// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Drawing.Shapes.PolygonClipper { using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using Paths; /// /// Poly Node /// internal class PolyNode { #pragma warning disable SA1401 // Field must be private /// /// The polygon /// internal List Polygon = new List(); /// /// The index /// internal int Index; /// /// The childs /// protected List children = new List(); private PolyNode parent; #pragma warning restore SA1401 // Field must be private /// /// Gets the child count. /// /// /// The child count. /// public int ChildCount { get { return this.children.Count; } } /// /// Gets the contour. /// /// /// The contour. /// public List Contour { get { return this.Polygon; } } /// /// Gets the childs. /// /// /// The childs. /// public List Children { get { return this.children; } } /// /// Gets or sets the parent. /// /// /// The parent. /// public PolyNode Parent { get { return this.parent; } internal set { this.parent = value; } } /// /// Gets a value indicating whether this instance is hole. /// /// /// true if this instance is hole; otherwise, false. /// public bool IsHole { get { return this.IsHoleNode(); } } /// /// Gets or sets a value indicating whether this instance is open. /// /// /// true if this instance is open; otherwise, false. /// public bool IsOpen { get; set; } /// /// Gets or sets the source path. /// /// /// The source path. /// public IPath SourcePath { get; internal set; } /// /// Gets the next. /// /// The next node public PolyNode GetNext() { if (this.children.Count > 0) { return this.children[0]; } else { return this.GetNextSiblingUp(); } } /// /// Adds the child. /// /// The child. internal void AddChild(PolyNode child) { int cnt = this.children.Count; this.children.Add(child); child.parent = this; child.Index = cnt; } /// /// Gets the next sibling up. /// /// The next sibling up internal PolyNode GetNextSiblingUp() { if (this.parent == null) { return null; } else if (this.Index == this.parent.children.Count - 1) { return this.parent.GetNextSiblingUp(); } else { return this.parent.Children[this.Index + 1]; } } /// /// Determines whether [is hole node]. /// /// /// true if [is hole node]; otherwise, false. /// private bool IsHoleNode() { bool result = true; PolyNode node = this.parent; while (node != null) { result = !result; node = node.parent; } return result; } } }