/// <summary> /// Given an input of perimeters that describe a single tile group, returns a list of ConvexPolygonShape2Ds that /// represent the tile group but decomposed into rectangles. /// </summary> /// <param name="allPerims">Array of lists describing single tile group. Every list in the array represents a /// different perimeter.</param> /// <returns>A list of ConvexPolygonShape2Ds, with each one being a rectangle that the original irregular polygon /// was decomposed into.</returns> private static List <ConvexPolygonShape2D> _PartitionPolygonToRectangles( IReadOnlyList <List <Vector2> > allPerims) { var partitionedRectangles = new List <ConvexPolygonShape2D>(); var allIsoPerims = new List <Vector2> [allPerims.Count]; for (int i = 0; i < allPerims.Count; i++) { //convert to iso axis so all the shapes 'look' rectangular allIsoPerims[i] = AxisFuncs.CoordArrayToIsoAxis(allPerims[i]); } (List <Chord> chords, List <ChordlessPolygon> chordlessPolygons) = allIsoPerims.DecomposeComplexPolygonToRectangles(); List <List <Vector2> > allRectangles = chordlessPolygons.DecomposeChordlessPolygonToRectangles(chords); foreach (List <Vector2> rectangle in allRectangles) { List <Vector2> carteRectangle = AxisFuncs.CoordArrayToCarteAxis(rectangle); var cps2d = new ConvexPolygonShape2D() { Points = carteRectangle.ToArray() }; partitionedRectangles.Add(cps2d); } return(partitionedRectangles); }
/// <summary> /// Creates PolyEdges from all TileEdges in the isometric axis (instead of the cartesian axis) and maps them to /// each other. /// </summary> /// <param name="edgeColl"></param> /// <returns>Two Dictionaries that map TileEdges to their respective PolyEdges and vice versa.</returns> private static Dictionary <PolyEdge, TileEdge> _InitTilePolyBiDict(EdgeCollection <TileEdge> edgeColl) { var polyToTileMap = new Dictionary <PolyEdge, TileEdge>(); foreach (TileEdge tileEdge in edgeColl) { var polyEdge = new PolyEdge(AxisFuncs.CoordToIsoAxis(tileEdge.a), AxisFuncs.CoordToIsoAxis(tileEdge.b)); polyToTileMap[polyEdge] = tileEdge; } return(polyToTileMap); }