/// <summary> /// Constructor. /// </summary> /// <param name="shape">The parent shape. If not null, it will automatically add the created loop /// to the shape. /// </param> /// <param name="initialInfo">Information on initial nodes to create.</param> public BLoop(BShape shape, params BNode.BezierInfo [] initialInfo) { if (shape != null) { shape.AddLoop(this); } foreach (BNode.BezierInfo bi in initialInfo) { BNode bn = new BNode(this, bi); bn.FlagDirty(); nodes.Add(bn); } if (initialInfo.Length == 0) { } // Do nothing else if (initialInfo.Length == 1) { } // Also do nothing if (initialInfo.Length == 2) { this.nodes[0].next = this.nodes[1]; this.nodes[1].prev = this.nodes[0]; } else { int lastIdx = this.nodes.Count - 1; for (int i = 0; i < lastIdx; ++i) { BNode bnprv = this.nodes[i]; BNode bnnxt = this.nodes[i + 1]; bnprv.next = bnnxt; bnnxt.prev = bnprv; } // Close the shape. if (this.nodes.Count > 0) { BNode bnfirst = this.nodes[0]; BNode bnlast = this.nodes[lastIdx]; bnfirst.prev = bnlast; bnlast.next = bnfirst; } } #if DEVELOPMENT_BUILD || UNITY_EDITOR this.debugCounter = Utils.RegisterCounter(); #endif }
/// <summary> /// Line loop constructor. /// /// Creates a shape constructed of straight lines, defined by an ordered array /// of 2D points. /// </summary> /// <param name="shape">The parent shape.</param> /// <param name="closed"> /// If true, the shape is created as a closed path.. /// Else if false, the shape is created as an open path</param> /// <param name="linePoints">The ordered list of points used to define the initial path.</param> public BLoop(BShape shape, bool closed, params Vector2 [] linePoints) { // Arguably, we could have made the style of creation between this and the // "params BNode.BezierInfo []" constructor the same style of either // storing in an array and connecting afterwards (the other) or making // connections as we go and storing the last (this one). if (shape != null) { shape.AddLoop(this); } if (linePoints.Length == 0) { } else if (linePoints.Length == 1) { BNode bn = new BNode(this, linePoints[0]); this.nodes.Add(bn); } else if (linePoints.Length == 2) { BNode bnA = new BNode(this, linePoints[0]); this.nodes.Add(bnA); BNode bnB = new BNode(this, linePoints[1]); this.nodes.Add(bnB); bnA.next = bnB; bnB.prev = bnA; } else { BNode first = null; BNode prev = null; foreach (Vector2 v2 in linePoints) { BNode bn = new BNode(this, v2); this.nodes.Add(bn); if (prev == null) { first = bn; } else { prev.next = bn; bn.prev = prev; } prev = bn; } if (closed == true) { // At this point, prev will point to the last item. first.prev = prev; prev.next = first; } } #if DEVELOPMENT_BUILD || UNITY_EDITOR this.debugCounter = Utils.RegisterCounter(); #endif }