Ejemplo n.º 1
0
 internal StandardLine(Point p1, Point p2)
 {
     // Constants from the standard line representation: Ax+By+C
     A = (float)(p2.GetY() - p1.GetY());
     B = (float)(p1.GetX() - p2.GetX());
     C = (float)(p1.GetY() * (-B) - p1.GetX() * A);
 }
Ejemplo n.º 2
0
        public virtual void CopyConstructorTest()
        {
            Point second = new Point(new Point(0.13, 1.1));

            NUnit.Framework.Assert.AreEqual(0.13, second.GetX(), EPSILON_COMPARISON);
            NUnit.Framework.Assert.AreEqual(1.1, second.GetY(), EPSILON_COMPARISON);
        }
Ejemplo n.º 3
0
        public virtual void DoubleParamConstructorTest()
        {
            Point first = new Point(0.13, 1.1);

            NUnit.Framework.Assert.AreEqual(0.13, first.GetX(), EPSILON_COMPARISON);
            NUnit.Framework.Assert.AreEqual(1.1, first.GetY(), EPSILON_COMPARISON);
        }
Ejemplo n.º 4
0
 /// <summary>Appends a cubic Bezier curve to the current path.</summary>
 /// <remarks>
 /// Appends a cubic Bezier curve to the current path. The curve shall extend from
 /// the current point to the point <c>(x3, y3)</c> with the note that the current
 /// point represents two control points.
 /// </remarks>
 public virtual void CurveTo(float x2, float y2, float x3, float y3)
 {
     if (currentPoint == null)
     {
         throw new Exception(START_PATH_ERR_MSG);
     }
     CurveTo((float)currentPoint.GetX(), (float)currentPoint.GetY(), x2, y2, x3, y3);
 }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 6
0
 private static Point[] GetRotatedSquareVertices(Point[] orthogonalSquareVertices, double angle, Point squareCenter
                                                 )
 {
     Point[] rotatedSquareVertices = new Point[orthogonalSquareVertices.Length];
     AffineTransform.GetRotateInstance((float)angle).Transform(orthogonalSquareVertices, 0, rotatedSquareVertices
                                                               , 0, rotatedSquareVertices.Length);
     AffineTransform.GetTranslateInstance((float)squareCenter.GetX(), (float)squareCenter.GetY()).Transform(rotatedSquareVertices
                                                                                                            , 0, rotatedSquareVertices, 0, orthogonalSquareVertices.Length);
     return(rotatedSquareVertices);
 }
Ejemplo n.º 7
0
        /// <summary>Convert 4 Point objects into a Rectangle</summary>
        /// <param name="p1">first Point</param>
        /// <param name="p2">second Point</param>
        /// <param name="p3">third Point</param>
        /// <param name="p4">fourth Point</param>
        private Rectangle GetAsRectangle(Point p1, Point p2, Point p3, Point p4)
        {
            IList <double> xs     = JavaUtil.ArraysAsList(p1.GetX(), p2.GetX(), p3.GetX(), p4.GetX());
            IList <double> ys     = JavaUtil.ArraysAsList(p1.GetY(), p2.GetY(), p3.GetY(), p4.GetY());
            double         left   = Enumerable.Min(xs);
            double         bottom = Enumerable.Min(ys);
            double         right  = Enumerable.Max(xs);
            double         top    = Enumerable.Max(ys);

            return(new Rectangle((float)left, (float)bottom, (float)(right - left), (float)(top - bottom)));
        }
Ejemplo n.º 8
0
        public virtual Point DeltaTransform(Point src, Point dst)
        {
            if (dst == null)
            {
                dst = new Point();
            }
            double x = src.GetX();
            double y = src.GetY();

            dst.SetLocation(x * m00 + y * m01, x * m10 + y * m11);
            return(dst);
        }
Ejemplo n.º 9
0
 public virtual void Transform(Point[] src, int srcOff, Point[] dst, int dstOff, int length)
 {
     while (--length >= 0)
     {
         Point  srcPoint = src[srcOff++];
         double x        = srcPoint.GetX();
         double y        = srcPoint.GetY();
         Point  dstPoint = dst[dstOff];
         if (dstPoint == null)
         {
             dstPoint = new Point();
         }
         dstPoint.SetLocation(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12);
         dst[dstOff++] = dstPoint;
     }
 }
Ejemplo n.º 10
0
        /// <exception cref="iText.Kernel.Geom.NoninvertibleTransformException"/>
        public virtual Point InverseTransform(Point src, Point dst)
        {
            double det = GetDeterminant();

            if (Math.Abs(det) < ZERO)
            {
                // awt.204=Determinant is zero
                throw new NoninvertibleTransformException("Determinant is zero. Cannot invert transformation");
            }
            //$NON-NLS-1$
            if (dst == null)
            {
                dst = new Point();
            }
            double x = src.GetX() - m02;
            double y = src.GetY() - m12;

            dst.SetLocation((x * m11 - y * m01) / det, (y * m00 - x * m10) / det);
            return(dst);
        }
Ejemplo n.º 11
0
        public virtual Point InverseTransform(Point src, Point dst)
        {
            double det = GetDeterminant();

            if (Math.Abs(det) < ZERO)
            {
                // awt.204=Determinant is zero
                //$NON-NLS-1$
                throw new NoninvertibleTransformException(NoninvertibleTransformException.DETERMINANT_IS_ZERO_CANNOT_INVERT_TRANSFORMATION
                                                          );
            }
            if (dst == null)
            {
                dst = new Point();
            }
            double x = src.GetX() - m02;
            double y = src.GetY() - m12;

            dst.SetLocation((x * m11 - y * m01) / det, (y * m00 - x * m10) / det);
            return(dst);
        }
Ejemplo n.º 12
0
        /// <summary>Approximate a circle with 4 Bezier curves (one for each 90 degrees sector)</summary>
        /// <param name="center">center of the circle</param>
        /// <param name="radius">radius of the circle</param>
        private static BezierCurve[] ApproximateCircle(Point center, double radius)
        {
            // The circle is split into 4 sectors. Arc of each sector
            // is approximated  with bezier curve separately.
            BezierCurve[] approximation = new BezierCurve[4];
            double        x             = center.GetX();
            double        y             = center.GetY();

            approximation[0] = new BezierCurve(JavaUtil.ArraysAsList(new Point(x, y + radius), new Point(x + radius *
                                                                                                         CIRCLE_APPROXIMATION_CONST, y + radius), new Point(x + radius, y + radius * CIRCLE_APPROXIMATION_CONST
                                                                                                                                                            ), new Point(x + radius, y)));
            approximation[1] = new BezierCurve(JavaUtil.ArraysAsList(new Point(x + radius, y), new Point(x + radius, y
                                                                                                         - radius * CIRCLE_APPROXIMATION_CONST), new Point(x + radius * CIRCLE_APPROXIMATION_CONST, y - radius
                                                                                                                                                           ), new Point(x, y - radius)));
            approximation[2] = new BezierCurve(JavaUtil.ArraysAsList(new Point(x, y - radius), new Point(x - radius *
                                                                                                         CIRCLE_APPROXIMATION_CONST, y - radius), new Point(x - radius, y - radius * CIRCLE_APPROXIMATION_CONST
                                                                                                                                                            ), new Point(x - radius, y)));
            approximation[3] = new BezierCurve(JavaUtil.ArraysAsList(new Point(x - radius, y), new Point(x - radius, y
                                                                                                         + radius * CIRCLE_APPROXIMATION_CONST), new Point(x - radius * CIRCLE_APPROXIMATION_CONST, y + radius
                                                                                                                                                           ), new Point(x, y + radius)));
            return(approximation);
        }
Ejemplo n.º 13
0
 /// <summary>Sets the start point of the subpath.</summary>
 /// <param name="startPoint">the point this subpath starts at</param>
 public virtual void SetStartPoint(Point startPoint)
 {
     SetStartPoint((float)startPoint.GetX(), (float)startPoint.GetY());
 }
Ejemplo n.º 14
0
 /// <summary>Constructs a new subpath starting at the given point.</summary>
 /// <param name="startPoint">the point this subpath starts at</param>
 public Subpath(Point startPoint)
     : this((float)startPoint.GetX(), (float)startPoint.GetY())
 {
 }
Ejemplo n.º 15
0
 /// <summary>Constructs a new line based on the given coordinates.</summary>
 /// <param name="p1">start point of this Line</param>
 /// <param name="p2">end point of this Line</param>
 public Line(Point p1, Point p2)
     : this((float)p1.GetX(), (float)p1.GetY(), (float)p2.GetX(), (float)p2.GetY())
 {
 }
Ejemplo n.º 16
0
 internal virtual bool Contains(Point point)
 {
     return(JavaUtil.FloatCompare(Math.Abs(A * (float)point.GetX() + B * (float)point.GetY() + C), 0.1f) < 0);
 }