public static void test_tiling() { Vector2d origin = Vector2d.Zero; double radius = 22; Circle2d circ = new Circle2d(origin, radius); AxisAlignedBox2d elemBounds = circ.Bounds; //elemBounds.Max.x += radius / 2; AxisAlignedBox2d packBounds = new AxisAlignedBox2d(0, 0, 800, 400); double spacing = 5; Polygon2d boundsPoly = new Polygon2d(); for (int i = 0; i < 4; ++i) { boundsPoly.AppendVertex(packBounds.GetCorner(i)); } //List<Vector2d> packed = TilingUtil.BoundedRegularTiling2(elemBounds, packBounds, spacing); List <Vector2d> packed = TilingUtil.BoundedCircleTiling2(elemBounds, packBounds, spacing); System.Console.WriteLine("packed {0}", packed.Count); SVGWriter writer = new SVGWriter(); foreach (Vector2d t in packed) { writer.AddCircle(new Circle2d(origin + t, radius), SVGWriter.Style.Outline("black", 1.0f)); } writer.AddPolygon(boundsPoly, SVGWriter.Style.Outline("red", 2.0f)); writer.Write(TestUtil.GetTestOutputPath("test.svg")); }
public bool Compute() { AxisAlignedBox2d bounds = Polygon.Bounds; ScaleGridIndexer2 index = new ScaleGridIndexer2() { CellSize = TileSize }; Vector2i min = index.ToGrid(bounds.Min) - Vector2i.One; Vector2i max = index.ToGrid(bounds.Max); List <Tile> Tiles = new List <Tile>(); for (int y = min.y; y <= max.y; ++y) { for (int x = min.x; x <= max.x; ++x) { Tile t = new Tile(); t.index = new Vector2i(x, y); Vector2d tile_min = index.FromGrid(t.index); Vector2d tile_max = index.FromGrid(t.index + Vector2i.One); AxisAlignedBox2d tile_box = new AxisAlignedBox2d(tile_min, tile_max); tile_box.Expand(TileOverlap); t.poly = new Polygon2d(new Vector2d[] { tile_box.GetCorner(0), tile_box.GetCorner(1), tile_box.GetCorner(2), tile_box.GetCorner(3) }); Tiles.Add(t); } } gParallel.ForEach(Tiles, (tile) => { tile.regions = ClipperUtil.PolygonBoolean(Polygon, new GeneralPolygon2d(tile.poly), ClipperUtil.BooleanOp.Intersection); }); List <ICurvesFillPolygon> all_fills = new List <ICurvesFillPolygon>(); foreach (Tile t in Tiles) { if (t.regions.Count == 0) { continue; } t.fills = new ICurvesFillPolygon[t.regions.Count]; for (int k = 0; k < t.regions.Count; ++k) { t.fills[k] = TileFillGeneratorF(t.regions[k], t.index); if (t.fills[k] != null) { all_fills.Add(t.fills[k]); } } } gParallel.ForEach(all_fills, (fill) => { fill.Compute(); }); FillCurves = new List <FillCurveSet2d>(); foreach (ICurvesFillPolygon fill in all_fills) { List <FillCurveSet2d> result = fill.GetFillCurves(); if (result != null && result.Count > 0) { FillCurves.AddRange(result); } } return(true); }