Ejemplo n.º 1
0
        public virtual void TransformPathTest()
        {
            Line        inLine        = new Line(new Point(0, 0), new Point(10, 10));
            BezierCurve inBezierCurve = new BezierCurve(JavaUtil.ArraysAsList(new Point(0, 0), new Point(0, 5), new Point
                                                                                  (5, 5), new Point(5, 0)));
            Subpath inSubpath = new Subpath();

            inSubpath.AddSegment(inLine);
            inSubpath.AddSegment(inBezierCurve);
            Path        inPath         = new Path(JavaUtil.ArraysAsList(inSubpath));
            Matrix      ctm            = new Matrix(1, 0, 0, 1, 5, 5);
            Path        outPath        = ShapeTransformUtil.TransformPath(inPath, ctm);
            Line        cmpLine        = new Line(new Point(-5, -5), new Point(5, 5));
            BezierCurve cmpBezierCurve = new BezierCurve(JavaUtil.ArraysAsList(new Point(-5, -5), new Point(-5, 0), new
                                                                               Point(0, 0), new Point(0, -5)));
            Subpath cmpSubpath = new Subpath();

            inSubpath.AddSegment(cmpLine);
            inSubpath.AddSegment(cmpBezierCurve);
            Path cmpPath = new Path(JavaUtil.ArraysAsList(cmpSubpath));

            for (int i = 0; i < cmpPath.GetSubpaths().Count; i++)
            {
                Subpath subpath = cmpPath.GetSubpaths()[i];
                for (int j = 0; j < subpath.GetSegments().Count; j++)
                {
                    IShape cmpShape = subpath.GetSegments()[j];
                    IShape outShape = outPath.GetSubpaths()[i].GetSegments()[j];
                    NUnit.Framework.Assert.AreEqual(cmpShape.GetBasePoints().ToArray(), outShape.GetBasePoints().ToArray());
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>Closes the current subpath.</summary>
        public virtual void CloseSubpath()
        {
            Subpath lastSubpath = GetLastSubpath();

            lastSubpath.SetClosed(true);
            Point startPoint = lastSubpath.GetStartPoint();

            MoveTo((float)startPoint.GetX(), (float)startPoint.GetY());
        }
        /// <summary>Method for transforming a path.</summary>
        /// <remarks>
        /// Method for transforming a path.
        /// The method creates a new transformed path without changing the original path.
        /// </remarks>
        /// <param name="path">the source path for transformation</param>
        /// <param name="ctm">the transformation matrix</param>
        /// <returns>the new transformed path</returns>
        public static Path TransformPath(Path path, Matrix ctm)
        {
            Path newPath = new Path();

            foreach (Subpath subpath in path.GetSubpaths())
            {
                Subpath transformedSubpath = TransformSubpath(subpath, ctm);
                newPath.AddSubpath(transformedSubpath);
            }
            return(newPath);
        }
        private static Subpath TransformSubpath(Subpath subpath, Matrix ctm)
        {
            Subpath newSubpath = new Subpath();

            newSubpath.SetClosed(subpath.IsClosed());
            foreach (IShape segment in subpath.GetSegments())
            {
                IShape transformedSegment = TransformSegment(segment, ctm);
                newSubpath.AddSegment(transformedSegment);
            }
            return(newSubpath);
        }
Ejemplo n.º 5
0
        /// <summary>Begins a new subpath by moving the current point to coordinates <c>(x, y)</c>.</summary>
        /// <param name="x">x-coordinate of the new point</param>
        /// <param name="y">y-coordinate of the new point</param>
        public virtual void MoveTo(float x, float y)
        {
            currentPoint = new Point(x, y);
            Subpath lastSubpath = subpaths.Count > 0 ? subpaths[subpaths.Count - 1] : null;

            if (lastSubpath != null && lastSubpath.IsSinglePointOpen())
            {
                lastSubpath.SetStartPoint(currentPoint);
            }
            else
            {
                subpaths.Add(new Subpath(currentPoint));
            }
        }
Ejemplo n.º 6
0
 /// <summary>Adds the subpath to this path.</summary>
 /// <param name="subpath">The subpath to be added to this path.</param>
 public virtual void AddSubpath(Subpath subpath)
 {
     subpaths.Add(subpath);
     currentPoint = subpath.GetLastPoint();
 }