コード例 #1
0
        private void CurveEnd(PointFP control1, PointFP control2, PointFP curveEnd)
        {
            _drawingCurve = false;
            if (_needDrawStartCap)
            {
                _startCapP1       = new PointFP(_curveBegin);
                _startCapP2       = new PointFP(control1);
                _needDrawStartCap = false;
            }
            var head = new LineFP();
            var tail = new LineFP();

            CalcHeadTail(_curveBegin, control1, head, new LineFP());
            _outline.AddMoveTo(head.Pt1);
            _outline.AddPath(_curvePath1);
            CalcHeadTail(control2, curveEnd, new LineFP(), tail);
            _outline.AddLineTo(tail.Pt1);
            _outline.AddLineTo(tail.Pt2);
            _outline.ExtendIfNeeded(_curvePath1._cmdsSize, _curvePath1._pntsSize);
            int j = _curvePath2._pntsSize - 1;

            for (int i = _curvePath2._cmdsSize - 1; i >= 0; i--)
            {
                _outline.AddLineTo(_curvePath2._pnts[j--]);
            }
            _outline.AddLineTo(head.Pt2);
            _outline.AddClose();
            _curvePath1    = null;
            _curvePath2    = null;
            _lastCurveTail = null;
            _lastPoint     = new PointFP(control2);
            _drawingCurve  = false;
        }
コード例 #2
0
        private void AddLineJoin(PointFP lastPoint, PointFP currPoint,
                                 PointFP nextPoint)
        {
            if (lastPoint == null || currPoint == null || nextPoint == null ||
                nextPoint.Equals(currPoint) || lastPoint.Equals(currPoint))
            {
                return;
            }

            PointFP p1 = null, p2 = null;
            LineFP  head, tail, lastHead, lastTail;

            CalcHeadTail(currPoint, nextPoint,
                         head = new LineFP(), tail = new LineFP());
            CalcHeadTail(lastPoint, currPoint,
                         lastHead = new LineFP(), lastTail = new LineFP());
            var needLineJoin = false;
            var pi1          = new PointFP();
            var pi2          = new PointFP();

            var cross1 = LineFP.Intersects(new LineFP(head.Pt1, tail.Pt1),
                                           new LineFP(lastHead.Pt1, lastTail.Pt1), pi1);
            var cross2 = LineFP.Intersects(new LineFP(head.Pt2, tail.Pt2),
                                           new LineFP(lastHead.Pt2, lastTail.Pt2), pi2);

            if (cross1 && !cross2 && pi1.X != SingleFP.NOT_A_NUMBER)
            {
                p1           = lastTail.Pt2;
                p2           = head.Pt2;
                needLineJoin = true;
            }
            else if (!cross1 && cross2 && pi2.X != SingleFP.NOT_A_NUMBER)
            {
                p1           = lastTail.Pt1;
                p2           = head.Pt1;
                needLineJoin = true;
            }
            if (needLineJoin)
            {
                _outline.AddMoveTo(cross1 ? pi1 : pi2);
                _outline.AddLineTo(cross1 ? p2 : p1);
                if (_lineJoin == PenFP.LINEJOIN_MITER)
                {
                    _outline.AddLineTo(cross1 ? pi2 : pi1);
                }
                _outline.AddLineTo(cross1 ? p1 : p2);
                _outline.AddClose();
                if (_lineJoin == PenFP.LINEJOIN_ROUND)
                {
                    AddLineCap(cross2 ? pi2 : pi1, currPoint, PenFP.LINECAP_ROUND);
                }
            }
        }
コード例 #3
0
        private void CalcHeadTail(PointFP p1, PointFP p2, LineFP head,
                                  LineFP tail)
        {
            var curr = new LineFP(p1, p2);

            head.Reset(curr.GetHeadOutline(_ffRad));
            var dx = p2.X - p1.X;
            var dy = p2.Y - p1.Y;

            tail.Reset(head.Pt1.X + dx, head.Pt1.Y + dy,
                       head.Pt2.X + dx, head.Pt2.Y + dy);
        }
コード例 #4
0
        public override void LineTo(PointFP point)
        {
            if (point.Equals(_currPoint))
            {
                return;
            }

            LineFP head, tail;

            CalcHeadTail(_currPoint, point,
                         head = new LineFP(), tail = new LineFP());

            if (_drawingCurve)
            {
                if (_lastCurveTail != null)
                {
                    _curvePath1.AddLineTo(_lastCurveTail.Pt1);
                    _curvePath2.AddLineTo(_lastCurveTail.Pt2);
                }
                _lastCurveTail = new LineFP(tail);
            }
            else
            {
                if (_needDrawStartCap)
                {
                    _startCapP1       = new PointFP(_currPoint);
                    _startCapP2       = new PointFP(point);
                    _needDrawStartCap = false;
                }
                AddLineJoin(_lastPoint, _currPoint, point);

                _outline.AddMoveTo(head.Pt1);
                _outline.AddLineTo(tail.Pt1);
                _outline.AddLineTo(tail.Pt2);
                _outline.AddLineTo(head.Pt2);
                _outline.AddLineTo(head.Pt1);
                _outline.AddClose();
                _lastPoint = new PointFP(_currPoint);
            }
            base.LineTo(point);
        }
コード例 #5
0
 private void CurveEnd(PointFP control1, PointFP control2, PointFP curveEnd)
 {
     _drawingCurve = false;
     if (_needDrawStartCap)
     {
         _startCapP1 = new PointFP(_curveBegin);
         _startCapP2 = new PointFP(control1);
         _needDrawStartCap = false;
     }
     var head = new LineFP();
     var tail = new LineFP();
     CalcHeadTail(_curveBegin, control1, head, new LineFP());
     _outline.AddMoveTo(head.Pt1);
     _outline.AddPath(_curvePath1);
     CalcHeadTail(control2, curveEnd, new LineFP(), tail);
     _outline.AddLineTo(tail.Pt1);
     _outline.AddLineTo(tail.Pt2);
     _outline.ExtendIfNeeded(_curvePath1._cmdsSize, _curvePath1._pntsSize);
     int j = _curvePath2._pntsSize - 1;
     for (int i = _curvePath2._cmdsSize - 1; i >= 0; i--)
     {
         _outline.AddLineTo(_curvePath2._pnts[j--]);
     }
     _outline.AddLineTo(head.Pt2);
     _outline.AddClose();
     _curvePath1 = null;
     _curvePath2 = null;
     _lastCurveTail = null;
     _lastPoint = new PointFP(control2);
     _drawingCurve = false;
 }
コード例 #6
0
 private void CalcHeadTail(PointFP p1, PointFP p2, LineFP head,
         LineFP tail)
 {
     var curr = new LineFP(p1, p2);
     head.Reset(curr.GetHeadOutline(_ffRad));
     var dx = p2.X - p1.X;
     var dy = p2.Y - p1.Y;
     tail.Reset(head.Pt1.X + dx, head.Pt1.Y + dy,
             head.Pt2.X + dx, head.Pt2.Y + dy);
 }
コード例 #7
0
        private void AddLineJoin(PointFP lastPoint, PointFP currPoint,
                PointFP nextPoint)
        {
            if (lastPoint == null || currPoint == null || nextPoint == null
                    || nextPoint.Equals(currPoint) || lastPoint.Equals(currPoint))
            {
                return;
            }

            PointFP p1 = null, p2 = null;
            LineFP head, tail, lastHead, lastTail;
            CalcHeadTail(currPoint, nextPoint,
                    head = new LineFP(), tail = new LineFP());
            CalcHeadTail(lastPoint, currPoint,
                    lastHead = new LineFP(), lastTail = new LineFP());
            var needLineJoin = false;
            var pi1 = new PointFP();
            var pi2 = new PointFP();

            var cross1 = LineFP.Intersects(new LineFP(head.Pt1, tail.Pt1),
                                            new LineFP(lastHead.Pt1, lastTail.Pt1), pi1);
            var cross2 = LineFP.Intersects(new LineFP(head.Pt2, tail.Pt2),
                                            new LineFP(lastHead.Pt2, lastTail.Pt2), pi2);
            if (cross1 && !cross2 && pi1.X != SingleFP.NOT_A_NUMBER)
            {
                p1 = lastTail.Pt2;
                p2 = head.Pt2;
                needLineJoin = true;
            }
            else if (!cross1 && cross2 && pi2.X != SingleFP.NOT_A_NUMBER)
            {
                p1 = lastTail.Pt1;
                p2 = head.Pt1;
                needLineJoin = true;
            }
            if (needLineJoin)
            {
                _outline.AddMoveTo(cross1 ? pi1 : pi2);
                _outline.AddLineTo(cross1 ? p2 : p1);
                if (_lineJoin == PenFP.LINEJOIN_MITER)
                {
                    _outline.AddLineTo(cross1 ? pi2 : pi1);
                }
                _outline.AddLineTo(cross1 ? p1 : p2);
                _outline.AddClose();
                if (_lineJoin == PenFP.LINEJOIN_ROUND)
                {
                    AddLineCap(cross2 ? pi2 : pi1, currPoint, PenFP.LINECAP_ROUND);
                }
            }
        }
コード例 #8
0
        public override void LineTo(PointFP point)
        {
            if (point.Equals(_currPoint))
            {
                return;
            }

            LineFP head, tail;
            CalcHeadTail(_currPoint, point,
                    head = new LineFP(), tail = new LineFP());

            if (_drawingCurve)
            {
                if (_lastCurveTail != null)
                {
                    _curvePath1.AddLineTo(_lastCurveTail.Pt1);
                    _curvePath2.AddLineTo(_lastCurveTail.Pt2);
                }
                _lastCurveTail = new LineFP(tail);
            }
            else
            {
                if (_needDrawStartCap)
                {
                    _startCapP1 = new PointFP(_currPoint);
                    _startCapP2 = new PointFP(point);
                    _needDrawStartCap = false;
                }
                AddLineJoin(_lastPoint, _currPoint, point);

                _outline.AddMoveTo(head.Pt1);
                _outline.AddLineTo(tail.Pt1);
                _outline.AddLineTo(tail.Pt2);
                _outline.AddLineTo(head.Pt2);
                _outline.AddLineTo(head.Pt1);
                _outline.AddClose();
                _lastPoint = new PointFP(_currPoint);
            }
            base.LineTo(point);
        }
コード例 #9
0
ファイル: LineFP.cs プロジェクト: 237rxd/maptiledownloader
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Copy constructor.
  * @param l
  */
 public LineFP(LineFP l)
 {
     Reset(l.Pt1, l.Pt2);
 }
コード例 #10
0
ファイル: LineFP.cs プロジェクト: 237rxd/maptiledownloader
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * reset the line the same location as given line.
  * @param l
  */
 public void Reset(LineFP l)
 {
     Reset(l.Pt1, l.Pt2);
 }
コード例 #11
0
ファイル: LineFP.cs プロジェクト: 237rxd/maptiledownloader
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * check to see if two line intects and return the the intersction point.
         * @param l1
         * @param l2
         * @param intersection
         * @return
         */
        public static bool Intersects(LineFP l1, LineFP l2, PointFP intersection)
        {
            var x = SingleFP.NOT_A_NUMBER;
            var y = SingleFP.NOT_A_NUMBER;

            if (intersection != null)
            {
                intersection.Reset(x, y);
            }

            var ax0 = l1.Pt1.X;
            var ax1 = l1.Pt2.X;
            var ay0 = l1.Pt1.Y;
            var ay1 = l1.Pt2.Y;
            var bx0 = l2.Pt1.X;
            var bx1 = l2.Pt2.X;
            var by0 = l2.Pt1.Y;
            var by1 = l2.Pt2.Y;

            var adx = (ax1 - ax0);
            var ady = (ay1 - ay0);
            var bdx = (bx1 - bx0);
            var bdy = (by1 - by0);

            if (IsZero(adx) && IsZero(bdx))
            {
                return IsEqual(ax0, bx0);
            }
            if (IsZero(ady) && IsZero(bdy))
            {
                return IsEqual(ay0, by0);
            }
            if (IsZero(adx))
            {
                // A  vertical
                x = ax0;
                y = IsZero(bdy) ? by0 : MathFP.Mul(MathFP.Div(bdy, bdx), x - bx0) + by0;
            }
            else if (IsZero(bdx))
            {
                // B vertical
                x = bx0;
                y = IsZero(ady) ? ay0 : MathFP.Mul(MathFP.Div(ady, adx), x - ax0) + ay0;
            }
            else if (IsZero(ady))
            {
                y = ay0;
                x = MathFP.Mul(MathFP.Div(bdx, bdy), y - by0) + bx0;
            }
            else if (IsZero(bdy))
            {
                y = by0;
                x = MathFP.Mul(MathFP.Div(adx, ady), y - ay0) + ax0;
            }
            else
            {
                var xma = MathFP.Div(ady, adx); // slope segment A
                var xba = ay0 - (MathFP.Mul(ax0, xma)); // y intercept of segment A

                var xmb = MathFP.Div(bdy, bdx); // slope segment B
                var xbb = by0 - (MathFP.Mul(bx0, xmb)); // y intercept of segment B

                // parallel lines?
                if (xma == xmb)
                {
                    // Need trig functions
                    return xba == xbb;
                }
                // Calculate points of intersection
                // At the intersection of line segment A and B,
                //XA=XB=XINT and YA=YB=YINT
                x = MathFP.Div((xbb - xba), (xma - xmb));
                y = (MathFP.Mul(xma, x)) + xba;
            }

            // After the point or points of intersection are calculated, each
            // solution must be checked to ensure that the point of intersection lies
            // on line segment A and B.

            var minxa = MathFP.Min(ax0, ax1);
            var maxxa = MathFP.Max(ax0, ax1);

            var minya = MathFP.Min(ay0, ay1);
            var maxya = MathFP.Max(ay0, ay1);

            var minxb = MathFP.Min(bx0, bx1);
            var maxxb = MathFP.Max(bx0, bx1);

            var minyb = MathFP.Min(by0, by1);
            var maxyb = MathFP.Max(by0, by1);

            if (intersection != null)
            {
                intersection.Reset(x, y);
            }
            return ((x >= minxa) && (x <= maxxa) && (y >= minya) && (y <= maxya)
                    && (x >= minxb) && (x <= maxxb) && (y >= minyb) && (y <= maxyb));
        }
コード例 #12
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Copy constructor.
         * @param l
         */
        public LineFP(LineFP l)
        {
            Reset(l.Pt1, l.Pt2);
        }
コード例 #13
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * check to see if two line intects and return the the intersction point.
         * @param l1
         * @param l2
         * @param intersection
         * @return
         */
        public static bool Intersects(LineFP l1, LineFP l2, PointFP intersection)
        {
            var x = SingleFP.NOT_A_NUMBER;
            var y = SingleFP.NOT_A_NUMBER;

            if (intersection != null)
            {
                intersection.Reset(x, y);
            }

            var ax0 = l1.Pt1.X;
            var ax1 = l1.Pt2.X;
            var ay0 = l1.Pt1.Y;
            var ay1 = l1.Pt2.Y;
            var bx0 = l2.Pt1.X;
            var bx1 = l2.Pt2.X;
            var by0 = l2.Pt1.Y;
            var by1 = l2.Pt2.Y;

            var adx = (ax1 - ax0);
            var ady = (ay1 - ay0);
            var bdx = (bx1 - bx0);
            var bdy = (by1 - by0);

            if (IsZero(adx) && IsZero(bdx))
            {
                return(IsEqual(ax0, bx0));
            }
            if (IsZero(ady) && IsZero(bdy))
            {
                return(IsEqual(ay0, by0));
            }
            if (IsZero(adx))
            {
                // A  vertical
                x = ax0;
                y = IsZero(bdy) ? by0 : MathFP.Mul(MathFP.Div(bdy, bdx), x - bx0) + by0;
            }
            else if (IsZero(bdx))
            {
                // B vertical
                x = bx0;
                y = IsZero(ady) ? ay0 : MathFP.Mul(MathFP.Div(ady, adx), x - ax0) + ay0;
            }
            else if (IsZero(ady))
            {
                y = ay0;
                x = MathFP.Mul(MathFP.Div(bdx, bdy), y - by0) + bx0;
            }
            else if (IsZero(bdy))
            {
                y = by0;
                x = MathFP.Mul(MathFP.Div(adx, ady), y - ay0) + ax0;
            }
            else
            {
                var xma = MathFP.Div(ady, adx);         // slope segment A
                var xba = ay0 - (MathFP.Mul(ax0, xma)); // y intercept of segment A

                var xmb = MathFP.Div(bdy, bdx);         // slope segment B
                var xbb = by0 - (MathFP.Mul(bx0, xmb)); // y intercept of segment B

                // parallel lines?
                if (xma == xmb)
                {
                    // Need trig functions
                    return(xba == xbb);
                }
                // Calculate points of intersection
                // At the intersection of line segment A and B,
                //XA=XB=XINT and YA=YB=YINT
                x = MathFP.Div((xbb - xba), (xma - xmb));
                y = (MathFP.Mul(xma, x)) + xba;
            }

            // After the point or points of intersection are calculated, each
            // solution must be checked to ensure that the point of intersection lies
            // on line segment A and B.

            var minxa = MathFP.Min(ax0, ax1);
            var maxxa = MathFP.Max(ax0, ax1);

            var minya = MathFP.Min(ay0, ay1);
            var maxya = MathFP.Max(ay0, ay1);

            var minxb = MathFP.Min(bx0, bx1);
            var maxxb = MathFP.Max(bx0, bx1);

            var minyb = MathFP.Min(by0, by1);
            var maxyb = MathFP.Max(by0, by1);

            if (intersection != null)
            {
                intersection.Reset(x, y);
            }
            return((x >= minxa) && (x <= maxxa) && (y >= minya) && (y <= maxya) &&
                   (x >= minxb) && (x <= maxxb) && (y >= minyb) && (y <= maxyb));
        }
コード例 #14
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * reset the line the same location as given line.
         * @param l
         */
        public void Reset(LineFP l)
        {
            Reset(l.Pt1, l.Pt2);
        }