/// <summary> /// Constructor /// </summary> /// <param name="polygonContainer">Polygon/line data</param> public PolygonEditorView(PolygonContainer polygonContainer) { InitializeComponent(); // Save off the polygon/line data _polygonContainer = polygonContainer; }
public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _farseerPoly = Framework.Content.Load <PolygonContainer>("Pipeline/FarseerPolygon"); }
public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _farseerPoly = Framework.Content.Load<PolygonContainer>("Pipeline/FarseerPolygon"); }
public void OnUse(PolygonContainer polygonContainer, Point point) { var i = 0; foreach (var polygon in polygonContainer.Polygons) { if (polygon.HasPoint(point)) { polygonContainer.Select(i); return; } i++; } }
public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; if (_farseerPoly == null) // flip once { _farseerPoly = Framework.Content.Load <PolygonContainer>("Pipeline/Polygon"); foreach (Polygon p in _farseerPoly.Values) { p.Vertices.Scale(new Vector2(1f, -1f)); // flip Vertices } } }
/// <summary> /// Display the polygon editor. /// </summary> /// <param name="propertyItem">Property from effect</param> /// <param name="value">Polygon container that is being edited</param> /// <param name="commandSource">?</param> /// <returns>Edited polygon container</returns> public override object ShowDialog(PropertyItem propertyItem, object value, IInputElement commandSource) { try { Debug.Assert(value != null); // Clone the polygon container PolygonContainer polygonContainer = ((PolygonContainer)value).Clone(); // Give the polygon container to the view PolygonEditorView newWindow = new PolygonEditorView(polygonContainer); // Display the modal polygon editor bool?okButton = newWindow.ShowDialog(); // If the OK button was pressed then... if (okButton.HasValue && okButton.Value) { // Create a new polygon container to the effect property change logic is triggered PolygonContainer polygonContainerUpdated = new PolygonContainer(); polygonContainerUpdated.Polygons.AddRange(newWindow.Polygons); polygonContainerUpdated.PolygonTimes.AddRange(newWindow.PolygonTimes); polygonContainerUpdated.Lines.AddRange(newWindow.Lines); polygonContainerUpdated.LineTimes.AddRange(newWindow.LineTimes); polygonContainerUpdated.Ellipses.AddRange(newWindow.Ellipses); polygonContainerUpdated.EllipseTimes.AddRange(newWindow.EllipseTimes); polygonContainerUpdated.Width = polygonContainer.Width; polygonContainerUpdated.Height = polygonContainer.Height; // Set the return value value = polygonContainerUpdated; } } catch (Exception e) { var messageBox = new MessageBoxForm("An error occurred loading the polygon editor.", "Polygon Error", MessageBoxButtons.OK, SystemIcons.Error); messageBox.ShowDialog(); } // Return the updated polygon container return(value); }
public override PolygonContainer Process(List <RawBodyTemplate> input, ContentProcessorContext context) { if (ScaleFactor < 1) { throw new Exception("Pixel to meter ratio must be greater than zero."); } if (BezierIterations < 1) { throw new Exception("Cubic bézier iterations must be greater than zero."); } Matrix matScale = Matrix.CreateScale(_scaleFactor, _scaleFactor, 1f); SVGPathParser parser = new SVGPathParser(BezierIterations); PolygonContainer polygons = new PolygonContainer(); foreach (RawBodyTemplate body in input) { foreach (RawFixtureTemplate fixture in body.Fixtures) { List <Polygon> paths = parser.ParseSVGPath(fixture.Path, fixture.Transformation * matScale); if (paths.Count == 1) { polygons.Add(fixture.Name, paths[0]); } else { for (int i = 0; i < paths.Count; i++) { polygons.Add(fixture.Name + i, paths[i]); } } } } if (DecomposePaths) { polygons.Decompose(); } return(polygons); }
public static void SpawnFigure(string name, GameManager.ObjectType objectType) { GameObject polyParent = new GameObject(name); Rigidbody parentRB = polyParent.AddComponent <Rigidbody>(); parentRB.useGravity = false; parentRB.isKinematic = true; PolygonContainer pc = polyParent.AddComponent <PolygonContainer>(); pc.lineMarker = GameManager.S.polygonHover; GameObject figure; PolygonGenerator pg; switch (objectType) { case GameManager.ObjectType.PENTAGON: figure = new GameObject("Pentagon"); pg = figure.AddComponent <PentagonGenerator>(); SetupObject(name, parentRB, figure, pg); break; case GameManager.ObjectType.SQUARE: figure = new GameObject("Square"); pg = figure.AddComponent <SquareGenerator>(); SetupObject(name, parentRB, figure, pg); break; case GameManager.ObjectType.TRIANGLE: figure = new GameObject("Triangle"); pg = figure.AddComponent <TriangleGenerator>(); SetupObject(name, parentRB, figure, pg); break; default: break; } }
public void Init(PolygonContainer polygonContainer) { _polygonContainer = polygonContainer; }
public void OnSelect(PolygonContainer polygonContainer) { polygonContainer.Selected.Rotate(new PointF(100, 100), 90); }
public void OnUse(PolygonContainer polygonContainer, Point point) { }
public void OnSelect(PolygonContainer polygonContainer) { polygonContainer.TriangulateSelected(); }
public void OnUse(PolygonContainer polygonContainer, Point point) { polygonContainer.AddPoint(point); }
public void OnSelect(PolygonContainer polygonContainer) { }
public void OnSelect(PolygonContainer polygonContainer) { polygonContainer.DeleteSelected(); }
public void OnSelect(PolygonContainer polygonContainer) { polygonContainer.AddPolygon(); }
public void OnUse(PolygonContainer polygonContainer, Point point) { Console.WriteLine("started"); bool flag = true; bool fin = true; Polygon polygon_A = new Polygon(); int ind_A = 0; Polygon polygon_B = new Polygon(); int ind_B = 0; List <Point> polygon_A_points = new List <Point>(); List <Point> polygon_B_points = new List <Point>(); //берём 2 полигона for (var i = 0; i < polygonContainer._polygons.Count; i++) { if (polygonContainer._polygons[i].HasPoint(point)) { if (flag) { foreach (Point p in polygonContainer._polygons[i]._points) { polygon_A_points.Add(p); } polygon_A = polygonContainer._polygons[i]; ind_A = i; flag = false; } else { foreach (Point p in polygonContainer._polygons[i]._points) { polygon_B_points.Add(p); } polygon_B = polygonContainer._polygons[i]; ind_B = i; fin = false; break; } } } if (!fin) { List <(Point, int)> polygon_A_points_marked = new List <(Point, int)>(); List <(Point, int)> polygon_B_points_marked = new List <(Point, int)>(); Console.WriteLine("pols finded"); //для каждого полигона помечаем точки, находящиеся внутри другого for (var j = 0; j < polygon_A_points.Count(); j++) { if (polygon_B.HasPoint(polygon_A_points[j])) { polygon_A_points_marked.Add((polygon_A_points[j], 1)); } else { polygon_A_points_marked.Add((polygon_A_points[j], 0)); } } for (var j = 0; j < polygon_B_points.Count(); j++) { if (polygon_A.HasPoint(polygon_B_points[j])) { polygon_B_points_marked.Add((polygon_B_points[j], 1)); } else { polygon_B_points_marked.Add((polygon_B_points[j], 0)); } } //получаем стороны полигонов List <Edge> polygon_A_edges = new List <Edge>(); List <Edge> polygon_B_edges = new List <Edge>(); (Point, int)t = polygon_A_points_marked[0]; for (var i = 1; i < polygon_A_points_marked.Count(); i++) { polygon_A_edges.Add(new Edge(t.Item1, polygon_A_points_marked[i].Item1)); t = polygon_A_points_marked[i]; } polygon_A_edges.Add(new Edge(t.Item1, polygon_A_points_marked[0].Item1)); Console.WriteLine("points found"); t = polygon_B_points_marked[0]; for (var i = 1; i < polygon_B_points_marked.Count(); i++) { polygon_B_edges.Add(new Edge(t.Item1, polygon_B_points_marked[i].Item1)); t = polygon_B_points_marked[i]; } polygon_B_edges.Add(new Edge(t.Item1, polygon_B_points_marked[0].Item1)); //для каждого полигона добавляем точки пересечений сторон int intersection_count = 0; int count; foreach (Edge e in polygon_A_edges) { count = 0; foreach (Edge q in polygon_B_edges) { PointF?pf = new PointF(); pf = e.Intersection(q); if (pf.HasValue) { Console.WriteLine("int pont"); if (count == 0) { intersection_count++; if (polygon_A_points_marked.Contains((e.SourceToPoint(), 0))) { int ind = polygon_A_points_marked.FindIndex(x => x == (e.SourceToPoint(), 0)); polygon_A_points_marked.Insert(ind + 1 + count, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } if (polygon_A_points_marked.Contains((e.SourceToPoint(), 1))) { int ind = polygon_A_points_marked.FindIndex(x => x == (e.SourceToPoint(), 1)); polygon_A_points_marked.Insert(ind + 1 + count, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } count++; } else { intersection_count++; if (polygon_A_points_marked.Contains((e.SourceToPoint(), 0))) { int ind = polygon_A_points_marked.FindIndex(x => x == (e.SourceToPoint(), 0)); if (Math.Pow(pf.Value.X - e.SourceToPoint().X, 2) + Math.Pow(pf.Value.Y - e.SourceToPoint().Y, 2) > Math.Pow(polygon_A_points_marked[ind + 1].Item1.X - e.SourceToPoint().X, 2) + Math.Pow(polygon_A_points_marked[ind + 1].Item1.Y - e.SourceToPoint().Y, 2)) { polygon_A_points_marked.Insert(ind + 1 + count, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } else { polygon_A_points_marked.Insert(ind + 1, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } } if (polygon_A_points_marked.Contains((e.SourceToPoint(), 1))) { int ind = polygon_A_points_marked.FindIndex(x => x == (e.SourceToPoint(), 1)); if (Math.Pow(pf.Value.X - e.SourceToPoint().X, 2) + Math.Pow(pf.Value.Y - e.SourceToPoint().Y, 2) > Math.Pow(polygon_A_points_marked[ind + 1].Item1.X - e.SourceToPoint().X, 2) + Math.Pow(polygon_A_points_marked[ind + 1].Item1.Y - e.SourceToPoint().Y, 2)) { polygon_A_points_marked.Insert(ind + 1 + count, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } else { polygon_A_points_marked.Insert(ind + 1, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } } count++; } } } } foreach (Edge e in polygon_B_edges) { count = 0; foreach (Edge q in polygon_A_edges) { PointF?pf = new PointF(); pf = e.Intersection(q); if (pf.HasValue) { Console.WriteLine("int pont"); if (count == 0) { intersection_count++; if (polygon_B_points_marked.Contains((e.SourceToPoint(), 0))) { int ind = polygon_B_points_marked.FindIndex(x => x == (e.SourceToPoint(), 0)); polygon_B_points_marked.Insert(ind + 1 + count, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } if (polygon_B_points_marked.Contains((e.SourceToPoint(), 1))) { int ind = polygon_B_points_marked.FindIndex(x => x == (e.SourceToPoint(), 1)); polygon_B_points_marked.Insert(ind + 1 + count, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } count++; } else { intersection_count++; if (polygon_B_points_marked.Contains((e.SourceToPoint(), 0))) { int ind = polygon_B_points_marked.FindIndex(x => x == (e.SourceToPoint(), 0)); if (Math.Pow(pf.Value.X - e.SourceToPoint().X, 2) + Math.Pow(pf.Value.Y - e.SourceToPoint().Y, 2) > Math.Pow(polygon_B_points_marked[ind + 1].Item1.X - e.SourceToPoint().X, 2) + Math.Pow(polygon_B_points_marked[ind + 1].Item1.Y - e.SourceToPoint().Y, 2)) { polygon_B_points_marked.Insert(ind + 1 + count, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } else { polygon_B_points_marked.Insert(ind + 1, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } } if (polygon_B_points_marked.Contains((e.SourceToPoint(), 1))) { int ind = polygon_B_points_marked.FindIndex(x => x == (e.SourceToPoint(), 1)); if (Math.Pow(pf.Value.X - e.SourceToPoint().X, 2) + Math.Pow(pf.Value.Y - e.SourceToPoint().Y, 2) > Math.Pow(polygon_B_points_marked[ind + 1].Item1.X - e.SourceToPoint().X, 2) + Math.Pow(polygon_B_points_marked[ind + 1].Item1.Y - e.SourceToPoint().Y, 2)) { polygon_B_points_marked.Insert(ind + 1 + count, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } else { polygon_B_points_marked.Insert(ind + 1, (new Point((int)pf.Value.X, (int)pf.Value.Y), 2)); } } count++; } } } } Console.WriteLine("edges found"); //строим полигон пересечения if (intersection_count == 0) { if (polygon_A.HasPoint(polygon_B_points[0])) { polygonContainer.Select(ind_B); } if (polygon_B.HasPoint(polygon_A_points[0])) { polygonContainer.Select(ind_A); } Console.WriteLine("no intersections"); } else { //находим точку полигона А int p_index = 0; for (int i = 0; i < polygon_A_points_marked.Count(); i++) { if (polygon_A_points_marked[i].Item2 == 2) { p_index = i; break; } } (Point, int)cur_p = polygon_A_points_marked[p_index]; (Point, int)prev_p = polygon_A_points_marked[p_index]; polygonContainer.AddPolygon(); polygonContainer.AddPoint(cur_p.Item1); char check = 'A'; if (p_index == (polygon_A_points_marked.Count() - 1)) { cur_p = polygon_A_points_marked[0]; } else { cur_p = polygon_A_points_marked[p_index + 1]; } if (cur_p.Item2 == 0) { int ind = polygon_B_points_marked.FindIndex(x => x == prev_p); if (ind == (polygon_B_points_marked.Count() - 1)) { cur_p = polygon_B_points_marked[0]; } else { cur_p = polygon_B_points_marked[ind + 1]; } check = 'B'; } (Point, int)temp_p = prev_p; Console.Write("final started "); Console.Write(polygon_A_points_marked.Count()); Console.Write(" "); Console.Write(polygon_B_points_marked.Count()); Console.WriteLine(); Console.Write(temp_p.Item1.X); Console.Write(" "); Console.Write(temp_p.Item1.Y); Console.WriteLine(); //делаем обход точек пересечения while (cur_p != temp_p) { int cX = cur_p.Item1.X; Console.Write(cX); Console.Write(" "); int cY = cur_p.Item1.Y; Console.Write(cY); Console.Write(" "); Console.WriteLine(" "); if (cur_p.Item2 == 1) { polygonContainer.AddPoint(cur_p.Item1); if (check == 'A') { int ind = polygon_A_points_marked.FindIndex(x => x == cur_p); Console.Write("point added "); Console.Write(ind); Console.Write(" A "); Console.Write(cur_p.Item1.X); Console.Write(" "); Console.Write(cur_p.Item1.Y); Console.WriteLine(); if (ind == (polygon_A_points_marked.Count() - 1)) { cur_p = polygon_A_points_marked[0]; } else { cur_p = polygon_A_points_marked[ind + 1]; } } else { int ind = polygon_B_points_marked.FindIndex(x => x == cur_p); Console.Write("point added "); Console.Write(ind); Console.Write(" B "); Console.Write(cur_p.Item1.X); Console.Write(" "); Console.Write(cur_p.Item1.Y); Console.WriteLine(); if (ind == (polygon_B_points_marked.Count() - 1)) { cur_p = polygon_B_points_marked[0]; } else { cur_p = polygon_B_points_marked[ind + 1]; } } } else if (cur_p.Item2 == 2) { polygonContainer.AddPoint(cur_p.Item1); if (check == 'A') { check = 'B'; int ind = polygon_B_points_marked.FindIndex(x => x == cur_p); Console.Write("point added "); Console.Write(ind); Console.Write(" pol switched from A to B "); Console.Write(cur_p.Item1.X); Console.Write(" "); Console.Write(cur_p.Item1.Y); Console.WriteLine(); if (ind == (polygon_B_points_marked.Count() - 1)) { cur_p = polygon_B_points_marked[0]; } else { cur_p = polygon_B_points_marked[ind + 1]; } } else if (check == 'B') { check = 'A'; int ind = polygon_A_points_marked.FindIndex(x => x == cur_p); Console.Write("point added "); Console.Write(ind); Console.Write(" pol switched from B to A "); Console.Write(cur_p.Item1.X); Console.Write(" "); Console.Write(cur_p.Item1.Y); Console.WriteLine(); if (ind == (polygon_A_points_marked.Count() - 1)) { cur_p = polygon_A_points_marked[0]; } else { cur_p = polygon_A_points_marked[ind + 1]; } } } } } } }
public void OnSelect(PolygonContainer polygonContainer) { polygonContainer.Clear(); }
public void OnSelect(PolygonContainer polygonContainer) { polygonContainer.Selected.Move(new PointF(2, 2)); }