public void ProfileThisFunction() { // This function exists primarily to allow me to run the VSTEST profiler on it, so that // I can determine where PolyBoolCS spends most of its time, and which areas can be // cleaned up if I ever decide to refactor it into a production-ready version. var clipper = new PolyBool(); var demo = DemoData.polyCases.Where(x => x.name == "Two Triangles With Common Edge").First(); for (int i = 0; i < 1000; i++) { var result = clipper.difference(demo.poly1, demo.poly2); Assert.IsNotNull(result); } }
private void button2_Click(object sender, EventArgs e) { List <PolygonHelper> phhs = new List <PolygonHelper>(); if (!checkBox1.Checked) { if (dataModel.SelectedItems.Length < 2) { dataModel.ParentForm.StatusMessage("there are no 2 polygon selected", StatusMessageType.Warning); return; } foreach (var item in dataModel.SelectedItems) { phhs.Add(item as PolygonHelper); } } else { phhs.Add((comboBox2.SelectedItem as ComboBoxItem).Tag as PolygonHelper); phhs.Add((comboBox3.SelectedItem as ComboBoxItem).Tag as PolygonHelper); } var ar1 = phhs.ToArray(); PolyBool pb = new PolyBool(); var poly1 = ar1[0].GetPolygon(); foreach (var item in ar1.Skip(1)) { poly1 = pb.difference(poly1, item.GetPolygon()); } if (poly1.regions.Count == 0) { dataModel.ParentForm.StatusMessage("no intersections", StatusMessageType.Warning); return; } var r = poly1; var nfps = r.regions.Select(z => new NFP() { Points = z.Select(y => new SvgPoint(y.x, y.y)).ToArray() }).ToArray(); for (int i = 0; i < nfps.Length; i++) { for (int j = 0; j < nfps.Length; j++) { if (i != j) { var d2 = nfps[i]; var d3 = nfps[j]; var f0 = d3.Points[0]; if (StaticHelpers.pnpoly(d2.Points.ToArray(), f0.X, f0.Y)) { d3.Parent = d2; if (!d2.Childrens.Contains(d3)) { d2.Childrens.Add(d3); } } } } } foreach (var item in nfps) { if (item.Parent != null) { continue; } PolygonHelper phh = new PolygonHelper(); dataModel.AddItem(phh); phh.Polygon = item; } }