Example #1
0
        internal static double GetPathFigureLength(PathFigure pathFigure)
        {
            if (pathFigure == null)
                return 0;

            var isAlreadyFlattened = pathFigure.Segments.All(pathSegment => (pathSegment is PolyLineSegment) || (pathSegment is LineSegment));

            var pathFigureFlattened = isAlreadyFlattened ? pathFigure : pathFigure.GetFlattenedPathFigure();
            double length = 0;
            var pt1 = pathFigureFlattened.StartPoint;

            foreach (var pathSegment in pathFigureFlattened.Segments)
            {
                if (pathSegment is LineSegment)
                {
                    var pt2 = ((LineSegment)pathSegment).Point;
                    length += (pt2 - pt1).Length;
                    pt1 = pt2;
                }
                else if (pathSegment is PolyLineSegment)
                {
                    var pointCollection = ((PolyLineSegment)pathSegment).Points;
                    foreach (var pt2 in pointCollection)
                    {
                        length += (pt2 - pt1).Length;
                        pt1 = pt2;
                    }
                }
            }
            return length;
        }
 private double CalculateLength(PathFigure path)
 {
     PathFigure p = path.GetFlattenedPathFigure(0.1, ToleranceType.Relative);
     double lenght = 0;
     Point start = p.StartPoint;
     for (int i = 0; i < p.Segments.Count; i++)
     {
         if (p.Segments[i] is LineSegment)
         {
             LineSegment seg = (p.Segments[i] as LineSegment);
             lenght += Point.Subtract(start, seg.Point).Length;
             start = seg.Point;
         }
         else if (p.Segments[i] is PolyLineSegment)
         {
             PolyLineSegment seg = (p.Segments[i] as PolyLineSegment);
             for (int j = 0; j < seg.Points.Count; j++)
             {
                 lenght += Point.Subtract(start, seg.Points[j]).Length;
                 start = seg.Points[j];
             }
         }
     }
     return lenght;
 }
		public static double GetPathFigureLength(PathFigure pathFigure)
		{
			double result;
			if (pathFigure == null)
			{
				result = 0.0;
			}
			else
			{
				bool flag = true;
				foreach (PathSegment current in pathFigure.Segments)
				{
					if (!(current is PolyLineSegment) && !(current is LineSegment))
					{
						flag = false;
						break;
					}
				}
				PathFigure pathFigure2 = flag ? pathFigure : pathFigure.GetFlattenedPathFigure();
				double num = 0.0;
				Point point = pathFigure2.StartPoint;
				foreach (PathSegment current in pathFigure2.Segments)
				{
					if (current is LineSegment)
					{
						Point point2 = (current as LineSegment).Point;
						num += (point2 - point).Length;
						point = point2;
					}
					else if (current is PolyLineSegment)
					{
						PointCollection points = (current as PolyLineSegment).Points;
						foreach (Point point2 in points)
						{
							num += (point2 - point).Length;
							point = point2;
						}
					}
				}
				result = num;
			}
			return result;
		}
Example #4
0
        //static void OnTextPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        //{
        //    (obj as TextOnPathBase).OnTextPropertyChanged(args);
        //}
        //protected abstract void OnTextPropertyChanged(DependencyPropertyChangedEventArgs args);
        //static void OnPathPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        //{
        //    (obj as TextOnPathBase).OnPathPropertyChanged(args);
        //}
        //protected abstract void OnPathPropertyChanged(DependencyPropertyChangedEventArgs args);
        // Utility method
        public static double GetPathFigureLength(PathFigure pathFigure)
        {
            if (pathFigure == null)
                return 0;

            bool isAlreadyFlattened = true;

            foreach (PathSegment pathSegment in pathFigure.Segments)
            {
                if (!(pathSegment is PolyLineSegment) && !(pathSegment is LineSegment))
                {
                    isAlreadyFlattened = false;
                    break;
                }
            }

            PathFigure pathFigureFlattened = isAlreadyFlattened ?
                pathFigure : pathFigure.GetFlattenedPathFigure();

            double length = 0;
            Point pt1     = pathFigureFlattened.StartPoint;

            foreach (PathSegment pathSegment in pathFigureFlattened.Segments)
            {
                if (pathSegment is LineSegment)
                {
                    Point pt2 = (pathSegment as LineSegment).Point;
                    length += (pt2 - pt1).Length;
                    pt1 = pt2;
                }
                else if (pathSegment is PolyLineSegment)
                {
                    PointCollection pointCollection = (pathSegment as PolyLineSegment).Points;
                    foreach (Point pt2 in pointCollection)
                    {
                        length += (pt2 - pt1).Length;
                        pt1 = pt2;
                    }
                }
            }

            return length;
        }
Example #5
0
		public static PolygonClosedD2D GetGlyphPolygon(PathFigure figure, bool reverseY, double deviationAngleInDegrees, double deviationAbsolute)
		{
			PolyBezierSegment polyBezierSegment;
			PolyLineSegment polyLineSegment;

			var flattenedFigure = figure.GetFlattenedPathFigure();

			if (flattenedFigure.Segments.Count != 1)
				throw new NotSupportedException();

			var points = (flattenedFigure.Segments[0] as PolyLineSegment).Points.Select(p => ToAltaxo(p, reverseY)).ToArray();

			var sharpPoints = new HashSet<PointD2D>();

			Point prevEndPoint;
			Vector prevEndVector;

			Vector startVector, endVector;
			Point endPoint;

			GetStartAndEndVector(figure.StartPoint, figure.Segments[0], out prevEndPoint, out startVector, out prevEndVector);
			for (int i = 1; i <= figure.Segments.Count; ++i)
			{
				if (i == figure.Segments.Count && prevEndPoint != figure.StartPoint) // if the end point of the very last segment is not the same than the start point of the figure
				{
					// Consider the straight line segment from the prevPoint to figure.StartPoint in the case that the startpoint and the endpoint of the figure are different
					startVector = endVector = figure.StartPoint - prevEndPoint;
					if (!IsSmoothJoint(startVector, prevEndVector))
						sharpPoints.Add(ToAltaxo(prevEndPoint, reverseY));
					prevEndVector = endVector;
					prevEndPoint = figure.StartPoint;
				}

				PathSegment seg = figure.Segments[i % figure.Segments.Count];
				GetStartAndEndVector(prevEndPoint, seg, out endPoint, out startVector, out endVector);

				if (!IsSmoothJoint(startVector, prevEndVector))
					sharpPoints.Add(ToAltaxo(prevEndPoint, reverseY));

				if (null != (polyLineSegment = (seg as PolyLineSegment)))
				{
					var preP = prevEndPoint;
					for (int j = 0; j < polyLineSegment.Points.Count - 1; ++j)
					{
						if (!IsSmoothJoint(polyLineSegment.Points[j] - preP, polyLineSegment.Points[j + 1] - polyLineSegment.Points[j]))
							sharpPoints.Add(ToAltaxo(polyLineSegment.Points[j], reverseY));
						preP = polyLineSegment.Points[j];
					}

					prevEndPoint = polyLineSegment.Points[polyLineSegment.Points.Count - 1];
				}
				if (null != (polyBezierSegment = (seg as PolyBezierSegment)))
				{
					for (int j = 2; j < polyBezierSegment.Points.Count - 1; j += 3)
						if (!IsSmoothJoint(polyBezierSegment.Points[j] - polyBezierSegment.Points[j - 1], polyBezierSegment.Points[j + 1] - polyBezierSegment.Points[j]))
							sharpPoints.Add(ToAltaxo(polyBezierSegment.Points[j], reverseY));
				}

				prevEndVector = endVector;
				prevEndPoint = endPoint;
			}

			return new PolygonClosedD2D(points, sharpPoints);
		}