public static void WriteTestOutputGraphs(List <DGraph2> graphs, string sFilename, SVGWriter.Style lineStyle, SVGWriter.Style vtxStyle, double vtxRadius = 2.5) { Vector2d a = Vector2d.Zero, b = Vector2d.Zero; SVGWriter svg = new SVGWriter(); foreach (DGraph2 graph in graphs) { foreach (int eid in graph.EdgeIndices()) { graph.GetEdgeV(eid, ref a, ref b); svg.AddLine(new Segment2d(a, b), lineStyle); } } if (vtxRadius > 0) { foreach (DGraph2 graph in graphs) { foreach (int vid in graph.VertexIndices()) { a = graph.GetVertex(vid); svg.AddCircle(new Circle2d(a, vtxRadius), vtxStyle); } } } svg.Write(Program.TEST_OUTPUT_PATH + sFilename); }
public void TestBasic() { var writer = new SVGWriter(); writer.AddLine(new Segment2d(Vector2d.Zero, Vector2d.AxisX)); writer.Write("basic.svg"); }
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 void TestLayers() { var writer = new SVGWriter(); writer.StartNewLayer("layer-0"); writer.AddLine(new Segment2d(Vector2d.Zero, Vector2d.AxisX)); writer.StartNewLayer("layer-1"); writer.AddLine(new Segment2d(Vector2d.Zero, Vector2d.AxisY)); writer.Write("layers.svg"); }
public static void test_svg() { Polygon2d poly = Polygon2d.MakeCircle(100.0f, 10); PolyLine2d pline = new PolyLine2d(); pline.AppendVertex(Vector2d.Zero); pline.AppendVertex(200 * Vector2d.AxisX); pline.AppendVertex(200 * Vector2d.One); Circle2d circ = new Circle2d(33 * Vector2d.One, 25); Segment2d seg = new Segment2d(Vector2d.Zero, -50 * Vector2d.AxisY); SVGWriter writer = new SVGWriter(); writer.AddPolygon(poly, SVGWriter.Style.Filled("lime", "black", 0.25f)); writer.AddPolyline(pline, SVGWriter.Style.Outline("orange", 2.0f)); writer.AddCircle(circ, SVGWriter.Style.Filled("yellow", "red", 5.0f)); writer.AddLine(seg, SVGWriter.Style.Outline("blue", 10.0f)); int astep = 29; Vector2d c = new Vector2d(-200, 100); for (int k = 1; k <= 12; ++k) { Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, 0, k * astep); writer.AddArc(arc); writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f)); } c.y += 50; for (int k = 1; k <= 12; ++k) { Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, k * astep, (k + 5) * astep); writer.AddArc(arc); writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f)); } c.y += 50; for (int k = 1; k <= 12; ++k) { Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, k * astep, (k + 10) * astep); writer.AddArc(arc); writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f)); } c.y += 50; for (int k = 1; k <= 12; ++k) { Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, k * astep, (k + 10) * astep); arc.Reverse(); writer.AddArc(arc); writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f)); } writer.Write(TestUtil.GetTestOutputPath("test.svg")); }
private static void ExportToSVG(DGraph2 input, DGraph2 minGraph, DGraph2 pathGraph) { SVGWriter writer = new SVGWriter(); writer.AddGraph(input, SVGWriter.Style.Outline("blue", 0.1f)); writer.AddGraph(minGraph, SVGWriter.Style.Outline("red", 0.1f)); foreach (int eid in minGraph.EdgeIndices()) { if (minGraph.GetEdgeGroup(eid) >= 0) { writer.AddLine(minGraph.GetEdgeSegment(eid), SVGWriter.Style.Outline("green", 0.07f)); } } writer.AddGraph(pathGraph, SVGWriter.Style.Outline("black", 0.03f)); foreach (int vid in pathGraph.VertexIndices()) { if (pathGraph.IsBoundaryVertex(vid)) { writer.AddCircle(new Circle2d(pathGraph.GetVertex(vid), 0.5f), SVGWriter.Style.Outline("blue", 0.03f)); } } writer.Write("MIN_GRAPH.svg"); }
public static void test_chamfer() { //Polygon2d poly = Polygon2d.MakeRectangle(Vector2d.Zero, 200, 200); //if (poly.IsClockwise) // poly.Reverse(); Polygon2d poly = Polygon2d.MakeCircle(100, 64); double max_offset = 50; for (int k = 0; k < poly.VertexCount; k++) { double t = (double)k / (double)poly.VertexCount; double offset = (k % 2 == 0) ? -t * max_offset : t * max_offset; poly[k] = poly[k] + offset * poly[k].Normalized; } poly.Chamfer(60, 30, 30); SVGWriter writer = new SVGWriter(); writer.AddPolygon(poly, SVGWriter.Style.Filled("lime", "black", 0.25f)); writer.Write(TestUtil.GetTestOutputPath("test.svg")); }
public void BuildPoster() { int qmax = 8; int width = 128; int skip = 2; List <Polygon> Lines = new List <Polygon>(qmax * 256 / skip); SVGWriter S = new SVGWriter(); int C = 0; int bR1 = 1; int bG1 = 58; int bB1 = 66; int R1 = 21; int G1 = 142; int B1 = 160; double h1, h2, s1, s2, v1, v2; int R2 = 255; int G2 = 234; int B2 = 0; ColorToHSV(Color.FromArgb(R1, G1, B1), out h1, out s1, out v1); ColorToHSV(Color.FromArgb(R2, G2, B2), out h2, out s2, out v2); for (int q = 0; q < qmax; q++) { Console.WriteLine("column {0}/{1}", q + 1, qmax); for (float i = 0; i < 256; i += skip) { float envelopeoffset = (float)(1 - Math.Abs(((float)i / 255 - 0.5)) * 2) * 14; if (envelopeoffset < 0) { envelopeoffset = 0; } int DecayValue = 40 + (q * 120) / (qmax - 1); float Ybase = i * 5; float H = 30; RebuildEnvInt(width * 30, DecayValue, DecayValue, DecayValue, DecayValue, (int)i); Polygon P = new Polygon(); Polygon P2 = new Polygon() { depth = 2 }; float targetmix = q / (float)(qmax - 1); float br = 1.0f;// (i / 512.0f) + 0.5f; double h, s, v; h = h1 + (h2 - h1) * targetmix; s = s1 + (s2 - s1) * targetmix; v = v1 + (v2 - v1) * targetmix; var Co = ColorFromHSV(h, s, v); P.r = (byte)((R1 + (R2 - R1) * targetmix) * br); P.g = (byte)((G1 + (G2 - G1) * targetmix) * br); P.b = (byte)((B1 + (B2 - B1) * targetmix) * br); // P.r = Co.R; // P.g = Co.G; // P.b = Co.B; for (int j = 0; j < width; j++) { double vv = linvalues2[(int)(j * 30)]; // if (vv != 0) { P.Vertices.Add(new GlmNet.vec2(j + q * width, Ybase + H - (float)vv * H)); } // P2.Vertices.Add(new GlmNet.vec2(j, Ybase + (float)linvalues2[j * 4] * H)); } Lines.Add(P); // Lines.Add(P2); C++; } } Console.WriteLine("writing svg.."); SVGWriter.Write("edgecutter_poster-" + DateTime.Now.ToLongDateString() + ".svg", 600 * 4, 256 * 10, Lines, 1, false, Color.FromArgb(0, 58, 66)); Console.WriteLine("done!"); }
void BuildPoster() { List <Polygon> Lines = new List <Polygon>(); SVGWriter S = new SVGWriter(); int C = 0; int bR1 = 1; int bG1 = 58; int bB1 = 66; int R1 = 21; int G1 = 142; int B1 = 160; double h1, h2, s1, s2, v1, v2; int R2 = 255; int G2 = 234; int B2 = 0; ColorToHSV(Color.FromArgb(R1, G1, B1), out h1, out s1, out v1); ColorToHSV(Color.FromArgb(R2, G2, B2), out h2, out s2, out v2); int qmax = 8; int width = 128; for (int q = 0; q < qmax; q++) { Console.WriteLine("column {0}/{1}", q + 1, qmax); for (float i = 0; i < 256; i += 2) { Shape.Value = (int)(i); Phase.Value = (int)((i / 5) % 256); Speed.Value = 255; float envelopeoffset = (float)(1 - Math.Abs(((float)i / 255 - 0.5)) * 2) * 14; if (envelopeoffset < 0) { envelopeoffset = 0; } Mod.Value = Math.Min((((q * 255) / (qmax - 1))) + (int)envelopeoffset, 255); float Ybase = i * 5; float H = 30; RebuildLFO(true, 2 * 4 * 6 * width); Polygon P = new Polygon(); Polygon P2 = new Polygon() { depth = 2 }; float targetmix = q / (float)(qmax - 1); float br = 1.0f;// (i / 512.0f) + 0.5f; double h, s, v; h = h1 + (h2 - h1) * targetmix; s = s1 + (s2 - s1) * targetmix; v = v1 + (v2 - v1) * targetmix; var Co = ColorFromHSV(h, s, v); P.r = (byte)((R1 + (R2 - R1) * targetmix) * br); P.g = (byte)((G1 + (G2 - G1) * targetmix) * br); P.b = (byte)((B1 + (B2 - B1) * targetmix) * br); // P.r = Co.R; // P.g = Co.G; // P.b = Co.B; for (int j = 0; j < width; j++) { P.Vertices.Add(new GlmNet.vec2(j + q * width, Ybase + (float)linvalues2[(int)(j * 4 * 8.5)] * H)); // P2.Vertices.Add(new GlmNet.vec2(j, Ybase + (float)linvalues2[j * 4] * H)); } Lines.Add(P); // Lines.Add(P2); C++; } } SVGWriter.Write("wobbler_poster-" + DateTime.Now.ToLongDateString() + ".svg", 600 * 4, 256 * 10, Lines, 1, false, Color.FromArgb(0, 58, 66)); }
public static void test_splitter() { Polygon2d poly = Polygon2d.MakeCircle(1000, 16); Polygon2d hole = Polygon2d.MakeCircle(500, 32); hole.Reverse(); GeneralPolygon2d gpoly = new GeneralPolygon2d(poly); gpoly.AddHole(hole); //Polygon2d poly = Polygon2d.MakeRectangle(Vector2d.Zero, 1000, 1000); DGraph2 graph = new DGraph2(); graph.AppendPolygon(gpoly); System.Console.WriteLine("Stats before: verts {0} edges {1} ", graph.VertexCount, graph.EdgeCount); GraphSplitter2d splitter = new GraphSplitter2d(graph); splitter.InsideTestF = gpoly.Contains; for (int k = 0; k < poly.VertexCount; ++k) { Line2d line = new Line2d(poly[k], Vector2d.AxisY); splitter.InsertLine(line); } System.Console.WriteLine("Stats after 1: verts {0} edges {1} ", graph.VertexCount, graph.EdgeCount); for (int k = 0; k < poly.VertexCount; ++k) { Line2d line = new Line2d(poly[k], Vector2d.AxisX); splitter.InsertLine(line); } for (int k = 0; k < poly.VertexCount; ++k) { Line2d line = new Line2d(poly[k], Vector2d.One.Normalized); splitter.InsertLine(line); } for (int k = 0; k < poly.VertexCount; ++k) { Line2d line = new Line2d(poly[k], new Vector2d(1, -1).Normalized); splitter.InsertLine(line); } System.Console.WriteLine("Stats after: verts {0} edges {1} ", graph.VertexCount, graph.EdgeCount); Random r = new Random(31337); foreach (int vid in graph.VertexIndices()) { Vector2d v = graph.GetVertex(vid); v += TestUtil.RandomPoints2(1, r, v, 25)[0]; graph.SetVertex(vid, v); } SVGWriter svg = new SVGWriter(); svg.AddGraph(graph); var vtx_style = SVGWriter.Style.Outline("red", 1.0f); foreach (int vid in graph.VertexIndices()) { Vector2d v = graph.GetVertex(vid); svg.AddCircle(new Circle2d(v, 10), vtx_style); } svg.Write(TestUtil.GetTestOutputPath("split_graph.svg")); }
public static void test_arrangement_demo() { DMesh3 mesh = TestUtil.LoadTestInputMesh("spheres_and_planes.obj"); MeshTransforms.Scale(mesh, 8); AxisAlignedBox3d meshBounds = mesh.CachedBounds; Vector3d origin = meshBounds.Center; double simplify_thresh = 5.0; Frame3f plane = new Frame3f(origin, Vector3d.AxisY); MeshPlaneCut cut = new MeshPlaneCut(mesh, plane.Origin, plane.Z); cut.Cut(); Arrangement2d builder = new Arrangement2d(new AxisAlignedBox2d(1024.0)); // insert all cut edges HashSet <Vector2d> srcpts = new HashSet <Vector2d>(); foreach (EdgeLoop loop in cut.CutLoops) { Polygon2d poly = new Polygon2d(); foreach (int vid in loop.Vertices) { poly.AppendVertex(mesh.GetVertex(vid).xz); } poly.Simplify(simplify_thresh, 0.01, true); foreach (Vector2d v in poly.Vertices) { srcpts.Add(v); } builder.Insert(poly); } foreach (EdgeSpan span in cut.CutSpans) { PolyLine2d pline = new PolyLine2d(); foreach (int vid in span.Vertices) { pline.AppendVertex(mesh.GetVertex(vid).xz); } pline.Simplify(simplify_thresh, 0.01, true); foreach (Vector2d v in pline) { srcpts.Add(v); } builder.Insert(pline); } SVGWriter svg = new SVGWriter(); svg.AddGraph(builder.Graph); var vtx_style = SVGWriter.Style.Outline("red", 1.0f); foreach (int vid in builder.Graph.VertexIndices()) { Vector2d v = builder.Graph.GetVertex(vid); if (srcpts.Contains(v) == false) { svg.AddCircle(new Circle2d(v, 2), vtx_style); } } svg.Write(TestUtil.GetTestOutputPath("arrangement.svg")); }
public static void test_cells() { Polygon2d outer = Polygon2d.MakeCircle(1000, 17); Polygon2d hole = Polygon2d.MakeCircle(100, 32); hole.Reverse(); GeneralPolygon2d gpoly = new GeneralPolygon2d(outer); gpoly.AddHole(hole); DGraph2 graph = new DGraph2(); graph.AppendPolygon(gpoly); GraphSplitter2d splitter = new GraphSplitter2d(graph); splitter.InsideTestF = gpoly.Contains; for (int k = 0; k < outer.VertexCount; ++k) { Line2d line = new Line2d(outer[k], Vector2d.AxisY); splitter.InsertLine(line); } for (int k = 0; k < outer.VertexCount; ++k) { Line2d line = new Line2d(outer[k], Vector2d.AxisX); splitter.InsertLine(line); } for (int k = 0; k < outer.VertexCount; ++k) { Line2d line = new Line2d(outer[k], Vector2d.One.Normalized); splitter.InsertLine(line); } for (int k = 0; k < outer.VertexCount; ++k) { Line2d line = new Line2d(outer[k], new Vector2d(1, -1).Normalized); splitter.InsertLine(line); } GraphCells2d cells = new GraphCells2d(graph); cells.FindCells(); List <Polygon2d> polys = cells.ContainedCells(gpoly); for (int k = 0; k < polys.Count; ++k) { double offset = polys[k].IsClockwise ? 4 : 20; polys[k].PolyOffset(offset); } PlanarComplex cp = new PlanarComplex(); for (int k = 0; k < polys.Count; ++k) { cp.Add(polys[k]); } // convert back to solids var options = PlanarComplex.FindSolidsOptions.Default; options.WantCurveSolids = false; options.SimplifyDeviationTolerance = 0; var solids = cp.FindSolidRegions(options); SVGWriter svg = new SVGWriter(); svg.AddGraph(graph, SVGWriter.Style.Outline("red", 5)); for (int k = 0; k < polys.Count; ++k) { svg.AddPolygon(polys[k], SVGWriter.Style.Outline("black", 1)); } svg.Write(TestUtil.GetTestOutputPath("cells_graph.svg")); }
private static void Window_KeyReleaseEvent(object sender, KeyReleaseEventArgs args) { if (args.Event.Key == Gdk.Key.Up) { if ((args.Event.State & Gdk.ModifierType.ShiftMask) != 0) { View.CurrentLayer = View.CurrentLayer + 10; } else { View.CurrentLayer = View.CurrentLayer + 1; } } else if (args.Event.Key == Gdk.Key.Down) { if ((args.Event.State & Gdk.ModifierType.ShiftMask) != 0) { View.CurrentLayer = View.CurrentLayer - 10; } else { View.CurrentLayer = View.CurrentLayer - 1; } } else if (args.Event.Key == Gdk.Key.n) { if (View.NumberMode == SliceViewCanvas.NumberModes.NoNumbers) { View.NumberMode = SliceViewCanvas.NumberModes.PathNumbers; } else { View.NumberMode = SliceViewCanvas.NumberModes.NoNumbers; } View.QueueDraw(); } else if (args.Event.Key == Gdk.Key.f) { View.ShowFillArea = !View.ShowFillArea; View.QueueDraw(); } else if (args.Event.Key == Gdk.Key.t) { View.ShowTravels = !View.ShowTravels; View.QueueDraw(); } else if (args.Event.Key == Gdk.Key.e) { View.ShowDepositMoves = !View.ShowDepositMoves; View.QueueDraw(); } else if (args.Event.Key == Gdk.Key.p) { View.ShowAllPathPoints = !View.ShowAllPathPoints; View.QueueDraw(); } else if (args.Event.Key == Gdk.Key.b) { View.ShowBelowLayer = !View.ShowBelowLayer; View.QueueDraw(); } else if (args.Event.Key == Gdk.Key.i) { View.ShowIssues = !View.ShowIssues; View.QueueDraw(); } else if (args.Event.Key == Gdk.Key.q) { //SliceViewerTests.TestDGraph2(); //SliceViewerTests.TestFill(); //SliceViewerTests.TestOffset(); if (SliceViewerTests.Active == null) { SliceViewerTests.TestOffsetAnimation(); } else { SliceViewerTests.UpdateOffsetAnimation(); } } else if (args.Event.Key == Gdk.Key.E) { List <PolyLine2d> paths = View.GetPolylinesForLayer(View.CurrentLayer); SVGWriter writer = new SVGWriter(); SVGWriter.Style lineStyle = SVGWriter.Style.Outline("black", 0.2f); foreach (var p in paths) { writer.AddPolyline(p, lineStyle); } writer.Write("c:\\scratch\\__LAST_PATHS.svg"); } }
static void Main(string[] args) { List <Polygon> Circles = new List <Polygon>(); List <Polygon> Circles2 = new List <Polygon>(); double CX = 25; double CY = 25; int pts = 1000; for (int i = 0; i < 6; i++) { Polygon P = new Polygon("circlegen"); double Radius = (18.4 - 4.2) * (i / 5.0f) + 4.2; for (int j = 0; j < pts; j++) { double phase = (j * Math.PI * 2) / (double)pts; vec2 pt = new vec2(CX, CY); float wob = (float)(Math.Sin(phase * 60) * .9); pt.x += (float)(Math.Sin(phase) * (Radius + wob)); pt.y += (float)(Math.Cos(phase) * (Radius + wob)); P.Vertices.Add(pt); } //P.MakeCircle(CX, CY, Radius, 300); P.Filled = false; P.Closed = true; P.r = (byte)(255 * (i / 5.0f)); P.g = (byte)(255 * (i / 5.0f)); P.b = (byte)(255 - (byte)(255 * (i / 5.0f))); Circles.Add(P); } CY += 50; for (int i = 0; i < 12; i++) { Polygon P2 = new Polygon("circlegen"); double Radius = (18.4 - 4.2) * (i / 11.0f) + 4.2; for (int j = 0; j < pts; j++) { double phase = (j * Math.PI * 2) / (double)pts; vec2 pt = new vec2(CX, CY); float wob = 1.0f + (float)(Math.Abs(Math.Sin(phase * 8)) * 0.10); pt.x += (float)(Math.Sin(phase) * (Radius * wob)); pt.y += (float)(Math.Cos(phase) * (Radius * wob)); P2.Vertices.Add(pt); } //P.MakeCircle(CX, CY, Radius, 300); P2.Filled = false; P2.Closed = true; P2.r = (byte)(255 * (i / 11.0f)); P2.g = (byte)(255 * (i / 11.0f)); P2.b = (byte)(255 - (byte)(255 * (i / 11.0f))); Circles.Add(P2); } CY += 50; for (int i = 0; i < 120; i++) { Polygon P2 = new Polygon("circlegen"); double Radius = ((18.4 - 4.2) * (i / 119.0f) + 4.2 + Math.Sin(i * 0.2) * 0.3) * 4.0; P2.MakeCircle(CX, CY, Radius, 400); P2.Filled = false; P2.r = (byte)(255 * (i / 119.0f)); P2.g = (byte)(255 * (i / 119.0f)); P2.b = (byte)(255 - (byte)(255 * (i / 119.0f))); Circles.Add(P2); } SVGWriter.Write("Wobbler2Circles.svg", 50, 150, Circles, 0.1, System.Drawing.Color.DarkBlue, null); List <string> Lines = new List <string>(); Lines.AddRange(CreateLines("tick.raw", "tick")); List <int> Speeds = new List <int>(); for (int i = 0; i < 128; i++) { double R = Math.Pow(2.0, (i - 69) / 12.0) * (double)(1 << 12); Speeds.Add((int)R); } Lines.AddRange(CreateIntTable(Speeds, "speedvals")); var CubicTable = interp(); Lines.AddRange(CreateIntTable(CubicTable, "CubicTable")); File.WriteAllLines("tick.h", Lines.ToArray()); }
// exports svg w/ different containments of point set (created by slicing mesh) public static void containment_demo_svg() { DMesh3 mesh = TestUtil.LoadTestInputMesh("bunny_solid.obj"); MeshTransforms.Scale(mesh, 4); AxisAlignedBox3d meshBounds = mesh.CachedBounds; Vector3d origin = meshBounds.Center; origin -= 0.2 * meshBounds.Height * Vector3d.AxisY; Frame3f plane = new Frame3f(origin, new Vector3d(1, 3, 0).Normalized); MeshPlaneCut cut = new MeshPlaneCut(mesh, plane.Origin, plane.Z); cut.Cut(); AxisAlignedBox2d polyBounds = AxisAlignedBox2d.Empty; List <Polygon2d> polys = new List <Polygon2d>(); foreach (EdgeLoop loop in cut.CutLoops) { Polygon2d poly = new Polygon2d(); foreach (int vid in loop.Vertices) { poly.AppendVertex(mesh.GetVertex(vid).xz); } poly.Rotate(new Matrix2d(90, true), Vector2d.Zero); polys.Add(poly); polyBounds.Contain(poly.Bounds); } SVGWriter svg = new SVGWriter(); var polyStyle = SVGWriter.Style.Outline("red", 1.0f); var contStyle = SVGWriter.Style.Outline("black", 1.0f); for (int k = 0; k < 3; ++k) { double shift = (k == 2) ? 1.4f : 1.1f; Vector2d tx = (k - 1) * (polyBounds.Width * shift) * Vector2d.AxisX; List <Vector2d> pts = new List <Vector2d>(); foreach (Polygon2d poly in polys) { var p2 = new Polygon2d(poly).Translate(tx); pts.AddRange(p2.Vertices); svg.AddPolygon(p2, polyStyle); } if (k == 0) { ConvexHull2 hull = new ConvexHull2(pts, 0.001, QueryNumberType.QT_DOUBLE); svg.AddPolygon(hull.GetHullPolygon(), contStyle); } else if (k == 1) { ContMinBox2 contbox = new ContMinBox2(pts, 0.001, QueryNumberType.QT_DOUBLE, false); svg.AddPolygon(new Polygon2d(contbox.MinBox.ComputeVertices()), contStyle); } else if (k == 2) { ContMinCircle2 contcirc = new ContMinCircle2(pts); svg.AddCircle(contcirc.Result, contStyle); } } svg.Write(TestUtil.GetTestOutputPath("contain_demos.svg")); }
public static void test_min_box_2() { Random r = new Random(31337); bool write_svg = false; int contained_circles_N = 100; int test_iters = 1000; //LocalProfiler p = new LocalProfiler(); //p.Start("Hulls"); QueryNumberType[] modes = new QueryNumberType[] { QueryNumberType.QT_DOUBLE, QueryNumberType.QT_INT64 }; //QueryNumberType[] modes = new QueryNumberType[] { QueryNumberType.QT_DOUBLE }; foreach (var queryMode in modes) { for (int k = 0; k < test_iters; ++k) { int N = contained_circles_N; double scale = (r.NextDouble() + 0.1) * 1024.0; Interval1d radRange = new Interval1d(10, 100); Vector2d[] pts = TestUtil.RandomPoints2(N, r, Vector2d.Zero, scale); double[] radius = TestUtil.RandomScalars(N, r, new Interval1d(radRange)); double eps = MathUtil.Epsilonf; SVGWriter svg = (write_svg) ? new SVGWriter() : null; List <Vector2d> accumPts = new List <Vector2d>(); for (int i = 0; i < pts.Length; ++i) { Polygon2d circ = Polygon2d.MakeCircle(radius[i], 16, radius[i]); circ.Translate(pts[i]); accumPts.AddRange(circ.Vertices); if (svg != null) { svg.AddPolygon(circ, SVGWriter.Style.Outline("black", 1.0f)); } } ContMinBox2 contbox = new ContMinBox2(accumPts, 0.001, queryMode, false); Box2d box = contbox.MinBox; if (svg != null) { svg.AddPolygon(new Polygon2d(box.ComputeVertices()), SVGWriter.Style.Outline("red", 2.0f)); svg.Write(TestUtil.GetTestOutputPath("contbox.svg")); } foreach (Vector2d v in accumPts) { if (box.Contains(v)) { continue; } double d = box.DistanceSquared(v); if (d < eps) { continue; } System.Console.WriteLine("test_min_box_2: Point {0} not contained!", v); } } } //p.StopAll(); //System.Console.WriteLine(p.AllTimes()); }