private static void SlicePolygonHelper(Polygon p, CircleNE c1, CircleNE c2, out List <Polygon> output) { output = new List <Polygon>(); // ZZZ - alter Clip method to work on Polygons and use that. // Slice it up. List <Polygon> sliced1, sliced2; Slicer.SlicePolygon(p, c1, out sliced1); Slicer.SlicePolygon(p, c2, out sliced2); // Keep the ones we want. foreach (Polygon newPoly in sliced1) { bool outside = !c1.IsPointInsideNE(newPoly.CentroidApprox); if (outside) { output.Add(newPoly); } } foreach (Polygon newPoly in sliced2) { bool inside = c2.IsPointInsideNE(newPoly.CentroidApprox); if (inside) { output.Add(newPoly); } } }
/// <summary> /// Slices a polygon by a circle with some thickness. /// Input circle may be a line. /// </summary> /// <remarks>The input polygon might get reversed</remarks> public static void SlicePolygon(Polygon p, CircleNE c, Geometry g, double thickness, out List <Polygon> output) { output = new List <Polygon>(); // Setup the two slicing circles. CircleNE c1 = c.Clone(), c2 = c.Clone(); Mobius m = new Mobius(); Vector3D pointOnCircle = c.IsLine ? c.P1 : c.Center + new Vector3D(c.Radius, 0); m.Hyperbolic2(g, c1.CenterNE, pointOnCircle, thickness / 2); c1.Transform(m); m.Hyperbolic2(g, c2.CenterNE, pointOnCircle, -thickness / 2); c2.Transform(m); // ZZZ - alter Clip method to work on Polygons and use that. // Slice it up. List <Polygon> sliced1, sliced2; Slicer.SlicePolygon(p, c1, out sliced1); Slicer.SlicePolygon(p, c2, out sliced2); // Keep the ones we want. foreach (Polygon newPoly in sliced1) { bool outside = !c1.IsPointInsideNE(newPoly.CentroidApprox); if (outside) { output.Add(newPoly); } } foreach (Polygon newPoly in sliced2) { bool inside = c2.IsPointInsideNE(newPoly.CentroidApprox); if (inside) { output.Add(newPoly); } } }
/// <summary> /// Clip the drawn polygons in a set of tiles, using a circle. /// </summary> public static void Clip(ref List <Tile> tiles, Circle c, bool keepInside) { List <Tile> newTiles = new List <Tile>(); foreach (Tile t in tiles) { List <Polygon> sliced; Slicer.SlicePolygon(t.Drawn, c, out sliced); foreach (Polygon p in sliced) { bool insideCircle = (p.CentroidApprox - c.Center).Abs() < c.Radius; if ((keepInside && insideCircle) || (!keepInside && !insideCircle)) { newTiles.Add(new Tile(t.Boundary, p, t.Geometry)); } } } tiles = newTiles; }
/// <summary> /// Clips the tiling to the interior of a circle. /// </summary> public void Clip(Circle c, bool interior = true) { Slicer.Clip(ref m_tiles, c, interior); }