public static Profile2D GetSquareProfile(double centerX, double centerY, double width, double height) { var pp1 = new Point2D(centerX + width / 2, centerY + height / 2); var pp2 = new Point2D(centerX + width / 2, centerY - height / 2); var pp3 = new Point2D(centerX - width / 2, centerY - height / 2); var pp4 = new Point2D(centerX - width / 2, centerY + height / 2); var polygon = new Profile2D(); polygon.AddPnt(pp1); polygon.AddPnt(pp2); polygon.AddPnt(pp3); polygon.AddPnt(pp4); polygon.AddPnt(pp1); return(polygon); }
internal static IEnumerable <Profile2D> ElaboratePathData(PathGeometry p1, Point2D startPoint) { /* * La matrice di rotazione serve solamente a correggere il comportamento strano ( testo rovesciato) ottenuto dalla trasformazione in geometria del testo. */ var matrix = new Matrix3D(); matrix.RotateAt(new Quaternion(new Vector3D(1, 0, 0), 180), new System.Windows.Media.Media3D.Point3D(0, startPoint.Y, 0)); var profiles = new List <Profile2D>(); foreach (var figure in p1.Figures) { var profile = new Profile2D(); profiles.Add(profile); var d = figure.Segments; foreach (var l in d) { if (l is PolyLineSegment) { var pl = l as PolyLineSegment; var pts = pl.Points; foreach (var pnt in pts) { profile.AddPnt(new Point2D(pnt.X, pnt.Y), matrix); } if (pts.Count > 0) { profile.AddPnt(new Point2D(pts[0].X, pts[0].Y), matrix); } continue; } else if (l is PolyBezierSegment) { var pl = l as PolyBezierSegment; var pts = pl.Points; foreach (var pnt in pts) { profile.AddPnt(new Point2D(pnt.X, pnt.Y), matrix); } //if (pts.Count > 0) // profile.AddPnt(new Point2D(pts[0].X, pts[0].Y)); continue; } else if (l is LineSegment) { var pl = l as LineSegment; profile.AddPnt(new Point2D(pl.Point.X, pl.Point.Y), matrix); continue; } else if (l is BezierSegment) { var pl = l as BezierSegment; /* * todo , calcolare bezier da 3 point */ profile.AddPnt(new Point2D(pl.Point1.X, pl.Point1.Y), matrix); profile.AddPnt(new Point2D(pl.Point2.X, pl.Point3.Y), matrix); profile.AddPnt(new Point2D(pl.Point2.X, pl.Point3.Y), matrix); continue; } //if (!(l is PolyLineSegment)) //{ Debug.Fail("XamlDataManager.ElaboratePathData"); throw new Exception("XamlDataManager.ElaboratePathData"); //} } } return(profiles); }