public ChordlessPolygon(Vector2[] outerPerim, List <Vector2>[] potentialHoles, Dictionary <Vector2, HashSet <Vector2> > bridges, bool isHole) { if (outerPerim is null) { throw new ArgumentNullException(nameof(outerPerim)); } if (potentialHoles is null) { throw new ArgumentNullException(nameof(potentialHoles)); } this.isHole = isHole; this._outerPerimUnsimplified = outerPerim; this._outerPerim = _SimplifyOuterPerim(outerPerim); this._holes = !this.isHole ? this._GetContainedHoles(potentialHoles) : System.Array.Empty <List <Vector2> >(); this._bridges = bridges; if (!GeometryFuncs.IsPolygonCCW(this._outerPerim)) { var reversePerim = this.outerPerim.ToList(); reversePerim.Reverse(); this._outerPerim = reversePerim.ToArray(); } foreach (List <Vector2> hole in this._holes) { if (!GeometryFuncs.IsPolygonCCW(hole.ToArray())) { hole.Reverse(); } } }
/// <summary> /// Decomposes a complex polygon described by the input <param>allIsoPerims</param> into the minimum number of /// rectangles (actually a lie, decomposes them into chordless polygons, which is decomposed into rectangles in /// another class). /// </summary> /// <param name="allIsoPerims">Array of lists of Vector2s. Each list describes a perimeter, whether it be /// the complex polygon's outer perimeters or holes (the 0'th index is always the outer perimeter).</param> /// <returns>A list of lists of Vector2s. Each list describes a rectangle in coordinates that follow the /// isometric axis (and need to be converted back to the cartesian axis elsewhere).</returns> // ReSharper disable once ReturnTypeCanBeEnumerable.Global public static (List <Chord>, List <ChordlessPolygon>) DecomposeComplexPolygonToRectangles(this List <Vector2>[] allIsoPerims) { if (allIsoPerims is null) { throw new ArgumentNullException(nameof(allIsoPerims)); } foreach (List <Vector2> perim in allIsoPerims) { if (!GeometryFuncs.IsPolygonCCW(perim.ToArray())) { perim.Reverse(); } } (List <Chord> chords, List <ChordlessPolygon> chordlessPolygons) = _ComplexToChordlessPolygons(allIsoPerims); return(chords, chordlessPolygons); }