Ejemplo n.º 1
0
        /**
         * Appends a straight line segment from the current point to the point <CODE>(x, y)</CODE>.
         */
        public virtual void LineTo(float x, float y) {
            if (currentPoint == null) {
                throw new Exception(START_PATH_ERR_MSG);
            }

            Point2D targetPoint = new Point2D.Float(x, y);
            this.LastSubpath.AddSegment(new Line(currentPoint, targetPoint));
            currentPoint = targetPoint;
        }
Ejemplo n.º 2
0
        /**
         * Begins a new subpath by moving the current point to coordinates <CODE>(x, y)</CODE>.
         */
        public virtual void MoveTo(float x, float y) {
            currentPoint = new Point2D.Float(x, y);
            Subpath lastSubpath = this.LastSubpath;

            if (lastSubpath != null && lastSubpath.IsSinglePointOpen()) {
                lastSubpath.SetStartPoint(currentPoint);
            } else {
                subpaths.Add(new Subpath(currentPoint));
            }
        }
Ejemplo n.º 3
0
        public override bool AllowText(TextRenderInfo renderInfo) {
            LineSegment ascent = renderInfo.GetAscentLine();
            LineSegment descent = renderInfo.GetDescentLine();

        Point2D[] glyphRect = new Point2D[] {
                new Point2D.Float(ascent.GetStartPoint()[0], ascent.GetStartPoint()[1]),
                new Point2D.Float(ascent.GetEndPoint()[0], ascent.GetEndPoint()[1]),
                new Point2D.Float(descent.GetEndPoint()[0], descent.GetEndPoint()[1]),
                new Point2D.Float(descent.GetStartPoint()[0], descent.GetStartPoint()[1]),
        };

            foreach (Rectangle rectangle in rectangles) {
                Point2D[] redactRect = GetVertices(rectangle);

                if (Intersect(glyphRect, redactRect)) {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 4
0
 virtual public void SetLocation(Point2D p) {
     SetLocation(p.GetX(), p.GetY());
 }
Ejemplo n.º 5
0
 /**
  * Constructs a new line based on the given coordinates.
  */
 public Line(Point2D p1, Point2D p2) : this((float) p1.GetX(), (float) p1.GetY(), 
                                            (float) p2.GetX(), (float) p2.GetY()) {
 }
Ejemplo n.º 6
0
 internal StandardLine(Point2D p1, Point2D p2) {
     A = (float) (p2.GetY() - p1.GetY());
     B = (float) (p1.GetX() - p2.GetX());
     C = (float) (p1.GetY() * (-B) - p1.GetX() * A);
 }
Ejemplo n.º 7
0
 private static bool LiesOnSegment(Point2D segStart, Point2D segEnd, Point2D point) {
     return point.GetX() >= Math.Min(segStart.GetX(), segEnd.GetX()) &&
            point.GetX() <= Math.Max(segStart.GetX(), segEnd.GetX()) &&
            point.GetY() >= Math.Min(segStart.GetY(), segEnd.GetY()) &&
            point.GetY() <= Math.Max(segStart.GetY(), segEnd.GetY());
 }
Ejemplo n.º 8
0
 private static double GetVectorEuclideanNorm(Point2D vector) {
     return vector.Distance(0, 0);
 }
 private void WriteMoveTo(Point2D destinationPoint, PdfContentByte canvas) {
     new PdfNumber(destinationPoint.GetX()).ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
     canvas.InternalBuffer.Append(' ');
     new PdfNumber(destinationPoint.GetY()).ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
     canvas.InternalBuffer.Append(m);
 }
Ejemplo n.º 10
0
 /**
  * Adds the subpaths to this path.
  *
  * @param subpaths {@link java.util.List} of subpaths to be added to this path.
  */
 public void AddSubpaths(IList<Subpath> subpaths) {
     if (subpaths.Count > 0) {
         Util.AddAll(this.subpaths, subpaths);
         currentPoint = this.subpaths[subpaths.Count - 1].GetLastPoint();
     }
 }
Ejemplo n.º 11
0
 /**
  * Adds the subpath to this path.
  *
  * @param subpath The subpath to be added to this path.
  */
 public void AddSubpath(Subpath subpath) {
     subpaths.Add(subpath);
     currentPoint = subpath.GetLastPoint();
 }
Ejemplo n.º 12
0
        /**
         * Appends a cubic Bezier curve to the current path. The curve shall extend from
         * the current point to the point <CODE>(x3, y3)</CODE>.
         */
        public virtual void CurveTo(float x1, float y1, float x2, float y2, float x3, float y3) {
            if (currentPoint == null) {
                throw new Exception(START_PATH_ERR_MSG);
            }
            // Numbered in natural order
            Point2D secondPoint = new Point2D.Float(x1, y1);
            Point2D thirdPoint = new Point2D.Float(x2, y2);
            Point2D fourthPoint = new Point2D.Float(x3, y3);

            IList<Point2D> controlPoints = new List<Point2D>(new Point2D[] {currentPoint, secondPoint, thirdPoint, fourthPoint});
            this.LastSubpath.AddSegment(new BezierCurve(controlPoints));

            currentPoint = fourthPoint;
        }
Ejemplo n.º 13
0
 public virtual bool Contains(Point2D point) {
     return Contains(point.GetX(), point.GetY());
 }
Ejemplo n.º 14
0
        virtual public Point2D InverseTransform(Point2D src, Point2D dst) {
            double det = GetDeterminant();
            if (Math.Abs(det) < ZERO) {
                // awt.204=Determinant is zero
                throw new InvalidOperationException("awt.204"); //$NON-NLS-1$
            }

            if (dst == null) {
                if (src is Point2D.Double) {
                    dst = new Point2D.Double();
                } else {
                    dst = new Point2D.Float();
                }
            }

            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.º 15
0
        virtual public Point2D DeltaTransform(Point2D src, Point2D dst) {
            if (dst == null) {
                if (src is Point2D.Double) {
                    dst = new Point2D.Double();
                } else {
                    dst = new Point2D.Float();
                }
            }

            double x = src.GetX();
            double y = src.GetY();

            dst.SetLocation(x * m00 + y * m01, x * m10 + y * m11);
            return dst;
        }
Ejemplo n.º 16
0
 private static Point2D ComponentwiseDiff(Point2D minuend, Point2D subtrahend) {
     return new Point2D.Float((float) (minuend.GetX() - subtrahend.GetX()),
                              (float) (minuend.GetY() - subtrahend.GetY()));
 }
Ejemplo n.º 17
0
 private static Point2D GetUnitVector(Point2D vector) {
     double vectorLength = GetVectorEuclideanNorm(vector);
     return new Point2D.Float((float) (vector.GetX() / vectorLength),
                              (float) (vector.GetY() / vectorLength));
 }
Ejemplo n.º 18
0
        private static Subpath ConstructSquare(Point2D squareCenter, double widthHalf, double rotationAngle) {
            // Orthogonal square is the square with sides parallel to one of the axes.
            Point2D[] ortogonalSquareVertices = {
                new Point2D.Double(-widthHalf, -widthHalf),
                new Point2D.Double(-widthHalf, widthHalf),
                new Point2D.Double(widthHalf, widthHalf),
                new Point2D.Double(widthHalf, -widthHalf)
        };

            Point2D[] rotatedSquareVertices = GetRotatedSquareVertices(ortogonalSquareVertices, rotationAngle, squareCenter);

            Subpath square = new Subpath();
            square.AddSegment(new Line(rotatedSquareVertices[0], rotatedSquareVertices[1]));
            square.AddSegment(new Line(rotatedSquareVertices[1], rotatedSquareVertices[2]));
            square.AddSegment(new Line(rotatedSquareVertices[2], rotatedSquareVertices[3]));
            square.AddSegment(new Line(rotatedSquareVertices[3], rotatedSquareVertices[0]));

            return square;
        }
Ejemplo n.º 19
0
        private static float ApplyDash(Path dashedPath, Point2D segStart, Point2D segEnd, Point2D dashTo, bool isGap) {
            float remainingDist = 0;

            if (!LiesOnSegment(segStart, segEnd, dashTo)) {
                remainingDist = (float) dashTo.Distance(segEnd);
                dashTo = segEnd;
            }

            if (isGap) {
                dashedPath.MoveTo((float) dashTo.GetX(), (float) dashTo.GetY());
            } else {
                dashedPath.LineTo((float) dashTo.GetX(), (float) dashTo.GetY());
            }

            return remainingDist;
        }
Ejemplo n.º 20
0
        private static Point2D[] GetRotatedSquareVertices(Point2D[] orthogonalSquareVertices, double angle, Point2D squareCenter) {
            Point2D[] rotatedSquareVertices = new Point2D[orthogonalSquareVertices.Length];

            AffineTransform.GetRotateInstance(angle).
                    Transform(orthogonalSquareVertices, 0, rotatedSquareVertices, 0, rotatedSquareVertices.Length);
            AffineTransform.GetTranslateInstance(squareCenter.GetX(), squareCenter.GetY()).
                    Transform(rotatedSquareVertices, 0, rotatedSquareVertices, 0, orthogonalSquareVertices.Length);

            return rotatedSquareVertices;
        }
Ejemplo n.º 21
0
        private Point2D[] TransformPoints(Matrix transormationMatrix, bool inverse, params Point2D[] points) {
            AffineTransform t = new AffineTransform(transormationMatrix[Matrix.I11], transormationMatrix[Matrix.I12],
                                                    transormationMatrix[Matrix.I21], transormationMatrix[Matrix.I22],
                                                    transormationMatrix[Matrix.I31], transormationMatrix[Matrix.I32]);
            Point2D[] transformed = new Point2D[points.Length];

            if (inverse) {
                t = t.CreateInverse();
            }

            t.Transform(points, 0, transformed, 0, points.Length);

            return transformed;
        }
Ejemplo n.º 22
0
        private static BezierCurve[] ApproximateCircle(Point2D 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(new List<Point2D>(new Point2D[] {
                new Point2D.Double(x, y + radius),
                new Point2D.Double(x + radius * circleApproximationConst, y + radius),
                new Point2D.Double(x + radius, y + radius * circleApproximationConst),
                new Point2D.Double(x + radius, y)
            }));

            approximation[1] = new BezierCurve(new List<Point2D>(new Point2D[] {
                new Point2D.Double(x + radius, y),
                new Point2D.Double(x + radius, y - radius * circleApproximationConst),
                new Point2D.Double(x + radius * circleApproximationConst, y - radius),
                new Point2D.Double(x, y - radius)
            }));

            approximation[2] = new BezierCurve(new List<Point2D>(new Point2D[] {
                new Point2D.Double(x, y - radius),
                new Point2D.Double(x - radius * circleApproximationConst, y - radius),
                new Point2D.Double(x - radius, y - radius * circleApproximationConst),
                new Point2D.Double(x - radius, y)
            }));

            approximation[3] = new BezierCurve(new List<Point2D>(new Point2D[] {
                new Point2D.Double(x - radius, y),
                new Point2D.Double(x - radius, y + radius * circleApproximationConst),
                new Point2D.Double(x - radius * circleApproximationConst, y + radius),
                new Point2D.Double(x, y + radius)
            }));

            return approximation;
        }
Ejemplo n.º 23
0
 internal bool Contains(Point2D point) {
     return Util.compare(Math.Abs(A * (float) point.GetX() + B * (float) point.GetY() + C), 0.1f) < 0;
 }
Ejemplo n.º 24
0
 private static void AddRect(Clipper clipper, Point2D[] rectVertices, PolyType polyType) {
     clipper.AddPath(ConvertToIntPoints(new List<Point2D>(rectVertices)), polyType, true);
 }
Ejemplo n.º 25
0
 /**
  * Constructs a new line based on the given coordinates.
  */
 public Line(float x1, float y1, float x2, float y2) {
     p1 = new Point2D.Float(x1, y1);
     p2 = new Point2D.Float(x2, y2);
 }
Ejemplo n.º 26
0
        private bool Intersect(Point2D[] rect1, Point2D[] rect2) {
            Clipper clipper = new Clipper();
            AddRect(clipper, rect1, PolyType.ptSubject);
            AddRect(clipper, rect2, PolyType.ptClip);

            List<List<IntPoint>> paths = new List<List<IntPoint>>();
            clipper.Execute(ClipType.ctIntersection, paths, PolyFillType.pftNonZero, PolyFillType.pftNonZero);

            return paths.Count != 0;
        }
Ejemplo n.º 27
0
 virtual public double Distance(Point2D p) {
     return Math.Sqrt(DistanceSq(p));
 }
Ejemplo n.º 28
0
        private Rectangle GetRectangle(Point2D p1, Point2D p2, Point2D p3, Point2D p4) {
            double[] xs = { p1.GetX(), p2.GetX(), p3.GetX(), p4.GetX() };
            double[] ys = { p1.GetY(), p2.GetY(), p3.GetY(), p4.GetY() };

            double left = Util.Min(xs);
            double bottom = Util.Min(ys);
            double right = Util.Max(xs);
            double top = Util.Max(ys);

            return new Rectangle((float)left, (float)bottom, (float)right, (float)top);
        }
Ejemplo n.º 29
0
 virtual public double DistanceSq(Point2D p) {
     return Point2D.DistanceSq(GetX(), GetY(), p.GetX(), p.GetY());
 }
Ejemplo n.º 30
0
        private static Point2D GetNextPoint(Point2D segStart, Point2D segEnd, float dist) {
            Point2D vector = ComponentwiseDiff(segEnd, segStart);
            Point2D unitVector = GetUnitVector(vector);

            return new Point2D.Float((float) (segStart.GetX() + dist * unitVector.GetX()),
                                     (float) (segStart.GetY() + dist * unitVector.GetY()));
        }