Ejemplo n.º 1
0
 /// <summary>
 /// Assignment.
 /// </summary>
 /// <param name="Other">Other rectangle.</param>
 public void Set(C2DRect Other)
 {
     TopLeft.x     = Other.TopLeft.x;
     TopLeft.y     = Other.TopLeft.y;
     BottomRight.x = Other.BottomRight.x;
     BottomRight.y = Other.BottomRight.y;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// True if the entire other rectangle is within.
 /// </summary>
 /// <param name="Other">Other rectangle.</param>
 public bool Contains(C2DRect Other)
 {
     return(Other.GetLeft() > TopLeft.x &&
            Other.GetRight() < BottomRight.x &&
            Other.GetBottom() > BottomRight.y &&
            Other.GetTop() < TopLeft.y);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the distance from this to the other rect. 0 if there is an overlap.
        /// </summary>
        /// <param name="Other">Other rectangle.</param>
        public double Distance(C2DRect Other)
        {
            if (this.Overlaps(Other))
            {
                return(0);
            }

            if (Other.GetLeft() > this.BottomRight.x)
            {
                // Other is to the right
                if (Other.GetBottom() > this.TopLeft.y)
                {
                    // Other is to the top right
                    C2DPoint ptTopRight = new C2DPoint(BottomRight.x, TopLeft.y);
                    return(ptTopRight.Distance(new C2DPoint(Other.GetLeft(), Other.GetBottom())));
                }
                else if (Other.GetTop() < this.BottomRight.y)
                {
                    // Other to the bottom right
                    return(BottomRight.Distance(Other.TopLeft));
                }
                else
                {
                    // to the right
                    return(Other.GetLeft() - this.BottomRight.x);
                }
            }
            else if (Other.GetRight() < this.TopLeft.x)
            {
                // Other to the left
                if (Other.GetBottom() > this.TopLeft.y)
                {
                    // Other is to the top left
                    return(TopLeft.Distance(Other.BottomRight));
                }
                else if (Other.GetTop() < this.BottomRight.y)
                {
                    // Other to the bottom left
                    C2DPoint ptBottomLeft = new C2DPoint(TopLeft.x, BottomRight.y);
                    return(ptBottomLeft.Distance(new C2DPoint(Other.GetRight(), Other.GetTop())));
                }
                else
                {
                    //Just to the left
                    return(this.TopLeft.x - Other.GetRight());
                }
            }
            else
            {
                // There is horizontal overlap;
                if (Other.GetBottom() > TopLeft.y)
                {
                    return(Other.GetBottom() - TopLeft.y);
                }
                else
                {
                    return(BottomRight.y - Other.GetTop());
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draws an arc.
        /// </summary>
        public void Draw(C2DArc Arc, Graphics graphics, Pen pen)
        {
            C2DRect Rect        = new C2DRect();
            int     nStartAngle = 0;
            int     nSweepAngle = 0;

            GetArcParameters(Arc, Rect, ref nStartAngle, ref nSweepAngle);

            if (nSweepAngle == 0)
            {
                nSweepAngle = 1;
            }

            int Width = (int)Rect.Width();

            if (Width == 0)
            {
                Width = 1;
            }
            int Height = (int)Rect.Height();

            if (Height == 0)
            {
                Height = 1;
            }

            graphics.DrawArc(pen, (int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                             Width, Height, nStartAngle, nSweepAngle);
        }
Ejemplo n.º 5
0
        /// <summary>
	    /// Finds a recommended minimum grid size to avoid point equality problems.
        /// </summary>
        public static double GetMinGridSize(C2DRect cRect, bool bRoundToNearestDecimalFactor)
        {
            // Find the furthest possible linear distance from the origin.
            C2DPoint pt = cRect.GetPointFurthestFromOrigin();

            double dRes = Math.Abs(Math.Max(pt.x, pt.y));
            // Now multiply this by the eq tol. Now, 2 points which are this far apart from each other
            // (in x and y) and at the edge of the rect would be considered only just not equal.
            dRes *= Constants.conEqualityTolerance;
            // Now multiple this by an avoidance factor.
            dRes *= const_dEqualityAvoidanceFactor;

            if (dRes == 0)
                dRes = const_dEqualityAvoidanceFactor;

            if (bRoundToNearestDecimalFactor)
            {
                double dRound = 0.0001;

                while (dRound >= dRes)
                    dRound /= 10.0;

                while (dRound < dRes)
                    dRound *= 10.0;

                dRes = dRound;
            }
            return dRes;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Draws a rectangle filled.
        /// </summary>
        public void DrawFilled(C2DRect Rect, Graphics graphics, Brush brush)
        {
            C2DPoint pt1 = new C2DPoint(Rect.TopLeft);
            C2DPoint pt2 = new C2DPoint(Rect.BottomRight);

            this.ScaleAndOffSet(pt1);
            this.ScaleAndOffSet(pt2);

            int TLx = (int)pt1.x;

            if (Scale.x < 0)
            {
                TLx = (int)pt2.x;
            }

            int TLy = (int)pt2.y;

            if (Scale.x < 0)
            {
                TLy = (int)pt1.y;
            }

            graphics.FillRectangle(brush, TLx, TLy, (int)Math.Abs(pt1.x - pt2.x),
                                   (int)Math.Abs(pt1.y - pt2.y));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// True if it crosses the line. Provides the intersection points.
        /// </summary>
        /// <param name="Line">The other line.</param>
        /// <param name="IntersectionPts">Output. The intersection points.</param>
        public bool Crosses(C2DLineBase Line, List <C2DPoint> IntersectionPts)
        {
            var LineRect = new C2DRect();

            Line.GetBoundingRect(LineRect);

            if (!BoundingRect.Overlaps(LineRect))
            {
                return(false);
            }

            Debug.Assert(Lines.Count == LineRects.Count);

            if (Lines.Count != LineRects.Count)
            {
                return(false);
            }

            var IntersectionTemp = new C2DPointSet();

            var bResult = false;

            for (var i = 0; i < this.Lines.Count; i++)
            {
                if (LineRects[i].Overlaps(LineRect) &&
                    Lines[i].Crosses(Line, IntersectionTemp as List <C2DPoint>))
                {
                    bResult = true;
                }
            }

            IntersectionPts.InsertRange(0, IntersectionTemp);

            return(bResult);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns the bounding rectangle.
        /// </summary>
        /// <param name="Rect">Rectangle to recieve the result.</param>
        public void GetBoundingRect(C2DRect Rect)
        {
            Rect.Set(_Rim.BoundingRect);

            for (var i = 0; i < _Holes.Count; i++)
            {
                Rect.ExpandToInclude(_Holes[i].BoundingRect);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Draws a circle filled.
        /// </summary>
        public void DrawFilled(C2DCircle Circle, Graphics graphics, Brush brush)
        {
            C2DRect Rect = new C2DRect();

            Circle.GetBoundingRect(Rect);
            this.ScaleAndOffSet(Rect.BottomRight);
            this.ScaleAndOffSet(Rect.TopLeft);

            graphics.FillEllipse(brush, (int)Rect.TopLeft.x, (int)Rect.BottomRight.y, (int)Rect.Width(), (int)Rect.Height());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Draws a circle
        /// </summary>
        public void Draw(C2DCircle Circle, Graphics graphics, Pen pen)
        {
            C2DRect Rect = new  C2DRect();

            Circle.GetBoundingRect(Rect);
            this.ScaleAndOffSet(Rect.BottomRight);
            this.ScaleAndOffSet(Rect.TopLeft);

            graphics.DrawEllipse(pen, (int)Rect.TopLeft.x, (int)Rect.BottomRight.y, (int)Rect.Width(), (int)Rect.Height());
        }
Ejemplo n.º 11
0
        /// <summary>
        /// True if there is an overlap.
        /// </summary>
        /// <param name="Other">Other rectangle.</param>
        public bool Overlaps(C2DRect Other)
        {
            bool bOvX = !(Other.GetLeft() >= BottomRight.x ||
                          Other.GetRight() <= TopLeft.x);

            bool bOvY = !(Other.GetBottom() >= TopLeft.y ||
                          Other.GetTop() <= BottomRight.y);

            return(bOvX && bOvY);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Forms the bounding rectangles for all the lines.
        /// </summary>
        protected void MakeLineRects()
        {
            LineRects.Clear();

            for (var i = 0; i < Lines.Count; i++)
            {
                var pRect = new C2DRect();
                Lines[i].GetBoundingRect(pRect);
                LineRects.Add(pRect);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a path based on a polygon.
        /// </summary>
        private System.Drawing.Drawing2D.GraphicsPath CreatePath(C2DPolyBase Poly)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();


            if (Poly.Lines.Count == 0)
            {
                return(gp);
            }

            for (int i = 0; i < Poly.Lines.Count; i++)
            {
                if (Poly.Lines[i] is C2DLine)
                {
                    C2DPoint ptFrom = Poly.Lines[i].GetPointFrom();
                    C2DPoint ptTo   = Poly.Lines[i].GetPointTo();
                    ScaleAndOffSet(ptFrom);
                    ScaleAndOffSet(ptTo);
                    gp.AddLine((int)ptFrom.x, (int)ptFrom.y, (int)ptTo.x, (int)ptTo.y);
                }
                else if (Poly.Lines[i] is C2DArc)
                {
                    C2DRect Rect        = new C2DRect();
                    int     nStartAngle = 0;
                    int     nSweepAngle = 0;

                    GetArcParameters(Poly.Lines[i] as C2DArc, Rect, ref nStartAngle, ref nSweepAngle);

                    if (nSweepAngle == 0)
                    {
                        nSweepAngle = 1;
                    }

                    int Width = (int)Rect.Width();
                    if (Width == 0)
                    {
                        Width = 1;
                    }
                    int Height = (int)Rect.Height();
                    if (Height == 0)
                    {
                        Height = 1;
                    }

                    gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                              Width, Height, nStartAngle, nSweepAngle);
                }
            }

            gp.CloseFigure();

            return(gp);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// True if this is above the other.
 /// </summary>
 /// <param name="Other"></param>
 /// <returns></returns>
 public bool OverlapsAbove(C2DRect Other)
 {
     if (Other.GetLeft() >= BottomRight.x ||
         Other.GetRight() <= TopLeft.x)
     {
         return(false);
     }
     else
     {
         return(TopLeft.y > Other.GetBottom());
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// True if this is below the other.
 /// </summary>
 /// <param name="Other"></param>
 /// <returns></returns>
 public bool OverlapsBelow(C2DRect Other)
 {
     if (Other.GetLeft() >= BottomRight.x ||
         Other.GetRight() <= TopLeft.x)
     {
         return(false);
     }
     else
     {
         return(BottomRight.y < Other.GetTop());
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// True if there is an overlap, returns the overlap.
        /// </summary>
        /// <param name="Other">Rectangle.</param>
        /// <param name="Overlap">Output. The overlap.</param>
        public bool Overlaps(C2DRect Other, C2DRect Overlap)
        {
            C2DPoint ptOvTL = new C2DPoint();
            C2DPoint ptOvBR = new C2DPoint();

            ptOvTL.y = Math.Min(TopLeft.y, Other.TopLeft.y);
            ptOvBR.y = Math.Max(BottomRight.y, Other.BottomRight.y);

            ptOvTL.x = Math.Max(TopLeft.x, Other.TopLeft.x);
            ptOvBR.x = Math.Min(BottomRight.x, Other.BottomRight.x);

            Overlap.Set(ptOvTL, ptOvBR);

            return(Overlap.IsValid());
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets the parameters required to draw an arc.
        /// </summary>
        private void GetArcParameters(C2DArc Arc, C2DRect Rect, ref int nStartAngle, ref int nSweepAngle)
        {
            C2DPoint Centre = Arc.GetCircleCentre();

            Rect.Set(Centre.x - Arc.Radius, Centre.y + Arc.Radius,
                     Centre.x + Arc.Radius, Centre.y - Arc.Radius);

            ScaleAndOffSet(Rect.TopLeft);
            ScaleAndOffSet(Rect.BottomRight);
            ScaleAndOffSet(Centre);                                    // CR 19-1-09

            C2DPoint bottomRightTemp = new C2DPoint(Rect.BottomRight); // to make valid // CR 11-3-09

            Rect.BottomRight.Set(Rect.TopLeft);                        // to make valid // CR 11-3-09
            Rect.ExpandToInclude(bottomRightTemp);                     // to make valid // CR 11-3-09

            C2DPoint pt1 = Arc.Line.GetPointFrom();
            C2DPoint pt2 = Arc.Line.GetPointTo();

            this.ScaleAndOffSet(pt1);
            this.ScaleAndOffSet(pt2);

            C2DVector vec1 = new C2DVector(Centre, pt1);
            C2DVector vec2 = new C2DVector(Centre, pt2);

            C2DVector vecx = new C2DVector(100, 0); // x - axis

            double dStartAngle = vecx.AngleToLeft(vec1) * Constants.conDegreesPerRadian;
            double dSweepAngle = 0;

            bool bAlreadyFlipped = Scale.x * Scale.y < 0;

            if (Arc.ArcOnRight ^ bAlreadyFlipped)
            {
                dSweepAngle = vec1.AngleToLeft(vec2) * Constants.conDegreesPerRadian;
            }
            else
            {
                dSweepAngle = -vec1.AngleToRight(vec2) * Constants.conDegreesPerRadian;
            }

            nStartAngle = (int)dStartAngle;
            if (nStartAngle == 360)
            {
                nStartAngle = 0;
            }
            nSweepAngle = (int)dSweepAngle;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Intersection with a line base.
        /// </summary>
        /// <param name="Line">The other line.</param>
        public bool Crosses(C2DLineBase Line)
        {
            var LineRect = new C2DRect();

            Line.GetBoundingRect(LineRect);

            var Temp = new List <C2DPoint>();

            for (var i = 0; i < this.Lines.Count; i++)
            {
                if (LineRects[i].Overlaps(LineRect) && Lines[i].Crosses(Line, Temp))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Gets the bounding rectangle.
        /// </summary>
        /// <param name="Rect">Ouput. The Rect.</param>
        public void GetBoundingRect(C2DRect Rect)
        {
            if (Count == 0)
            {
                Rect.Clear();
                return;
            }
            else
            {
                Rect.Set(this[0]);

                for (int i = 1; i < Count; i++)
                {
                    Rect.ExpandToInclude(this[i]);
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Returns the projection of this onto the vector provided, given as the interval on
        /// (or off) the vector. Interval given as distance from the start of the vector.
        /// The vector is equivalent to a line from (0, 0).
        /// </summary>
        /// <param name="Vector">The projection vector.</param>
        /// <param name="Interval">The interval to recieve the result.</param>
        public override void Project(C2DVector Vector, CInterval Interval)
        {
            C2DArc    ThisCopy = new C2DArc(this);
            C2DVector VecCopy  = new C2DVector(Vector);

            double dAng = VecCopy.AngleFromNorth();

            VecCopy.TurnLeft(dAng);
            ThisCopy.RotateToRight(-dAng, new C2DPoint(0, 0));

            C2DRect rect = new C2DRect();

            ThisCopy.GetBoundingRect(rect);

            Interval.dMax = rect.GetTop() - VecCopy.j;
            Interval.dMin = Interval.dMax;

            Interval.ExpandToInclude(rect.GetBottom() - VecCopy.j);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Returns the projection of this onto the line provided, given as the interval on
        /// (or off) the line. Interval given as distance from the start of the line.
        /// </summary>
        /// <param name="TestLine">The projection line.</param>
        /// <param name="Interval">The interval to recieve the result.</param>
        public override void Project(C2DLine TestLine, CInterval Interval)
        {
            C2DArc  ThisCopy = new C2DArc(this);
            C2DLine LineCopy = new C2DLine(TestLine);

            double dAng = LineCopy.vector.AngleFromNorth();

            LineCopy.vector.TurnLeft(dAng);
            ThisCopy.RotateToRight(-dAng, LineCopy.point);

            C2DRect rect = new C2DRect();

            ThisCopy.GetBoundingRect(rect);

            Interval.dMax = rect.GetTop() - LineCopy.point.y;
            Interval.dMin = Interval.dMax;

            Interval.ExpandToInclude(rect.GetBottom() - LineCopy.point.y);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Draws an arc.
        /// </summary>
        public void Draw(C2DArc Arc, Graphics graphics, Pen pen)
        {
            C2DRect Rect = new C2DRect();
            int nStartAngle = 0;
            int nSweepAngle = 0;

            GetArcParameters(Arc, Rect, ref nStartAngle, ref nSweepAngle);

            if (nSweepAngle == 0)
                nSweepAngle = 1;

            int Width = (int)Rect.Width();
            if (Width == 0)
                Width = 1;
            int Height = (int)Rect.Height();
            if (Height == 0)
                Height = 1;

            graphics.DrawArc(pen, (int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                Width, Height, nStartAngle, nSweepAngle);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Draws a segment filled.
        /// </summary>
        public void DrawFilled(C2DSegment Segment, Graphics graphics, Brush brush)
        {
            C2DRect Rect        = new C2DRect();
            int     nStartAngle = 0;
            int     nSweepAngle = 0;

            GetArcParameters(Segment.Arc, Rect, ref nStartAngle, ref nSweepAngle);

            if (nSweepAngle == 0)
            {
                nSweepAngle = 1;
            }

            int Width = (int)Rect.Width();

            if (Width == 0)
            {
                Width = 1;
            }
            int Height = (int)Rect.Height();

            if (Height == 0)
            {
                Height = 1;
            }

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                      Width, Height, nStartAngle, nSweepAngle);

            C2DPoint ptFrom = Segment.Arc.Line.GetPointFrom();
            C2DPoint ptTo   = Segment.Arc.Line.GetPointTo();

            ScaleAndOffSet(ptFrom);
            ScaleAndOffSet(ptTo);
            gp.AddLine((int)ptTo.x, (int)ptTo.y, (int)ptFrom.x, (int)ptFrom.y);

            graphics.FillPath(brush, gp);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Creates a random shape.
        /// </summary>
        /// <param name="cBoundary">The boundary.</param>
        /// <param name="nMinPoints">The minimum points.</param>
        /// <param name="nMaxPoints">The maximum points.</param>
        public bool CreateRandom(C2DRect cBoundary, int nMinPoints, int nMaxPoints)
        {
            C2DPolygon Poly = new C2DPolygon();

            if (!Poly.CreateRandom(cBoundary, nMinPoints, nMaxPoints))
            {
                return(false);
            }

            CRandomNumber rCenOnRight = new CRandomNumber(0, 1);

            this.Set(Poly);

            for (int i = 0; i < Lines.Count; i++)
            {
                C2DLineBase pLine = Lines[i];

                bool          bCenOnRight = (rCenOnRight.GetInt() > 0);
                double        dLength     = pLine.GetLength();
                CRandomNumber Radius      = new CRandomNumber(dLength, dLength * 3);


                C2DArc pNew = new C2DArc(pLine.GetPointFrom(), pLine.GetPointTo(),
                                         Radius.Get(), bCenOnRight, !bCenOnRight);

                if (!this.Crosses(pNew))
                {
                    Lines[i] = pNew;
                    pNew.GetBoundingRect(LineRects[i]);
                    BoundingRect.ExpandToInclude(LineRects[i]);
                }
            }

            //     this.MakeLineRects();
            //      this.MakeBoundingRect();

            return(true);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// True if the point is with the range given to the shape or inside.
        /// </summary>
        /// <param name="pt">The point to test.</param>
        /// <param name="dRange">The range to test against.</param>
        public bool IsWithinDistance(C2DPoint pt, double dRange)
        {
            var RectTemp = new C2DRect(BoundingRect);

            RectTemp.Expand(dRange);

            if (!RectTemp.Contains(pt))
            {
                return(false);
            }

            if (Lines.Count == 0)
            {
                return(false);
            }

            if (Lines[0].GetPointFrom().Distance(pt) < dRange)
            {
                return(true);
            }

            if (this.Contains(pt))
            {
                return(true);
            }

            for (var i = 1; i < Lines.Count; i++)
            {
                if (Lines[i].Distance(pt) < dRange)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Finds a recommended minimum grid size to avoid point equality problems.
        /// </summary>
        public static double GetMinGridSize(C2DRect cRect, bool bRoundToNearestDecimalFactor)
        {
            // Find the furthest possible linear distance from the origin.
            C2DPoint pt = cRect.GetPointFurthestFromOrigin();

            double dRes = Math.Abs(Math.Max(pt.x, pt.y));

            // Now multiply this by the eq tol. Now, 2 points which are this far apart from each other
            // (in x and y) and at the edge of the rect would be considered only just not equal.
            dRes *= Constants.conEqualityTolerance;
            // Now multiple this by an avoidance factor.
            dRes *= const_dEqualityAvoidanceFactor;

            if (dRes == 0)
            {
                dRes = const_dEqualityAvoidanceFactor;
            }

            if (bRoundToNearestDecimalFactor)
            {
                double dRound = 0.0001;

                while (dRound >= dRes)
                {
                    dRound /= 10.0;
                }

                while (dRound < dRes)
                {
                    dRound *= 10.0;
                }

                dRes = dRound;
            }
            return(dRes);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Returns the intersections with this set and the other.
        /// Each intersection has an associated point and 2 indexes
        /// corresponding to the lines that created the intersection.
        /// </summary>
        /// <param name="Other">Input. The other line set.</param>
        /// <param name="pPoints">Output. The intersection points.</param>
        /// <param name="pIndexesThis">Output. The indexes for this.</param>
        /// <param name="pIndexesOther">Output. The indexes for the other set.</param>
        /// <param name="pBoundingRectThis">Input. The bounding rect for this.</param>
        /// <param name="pBoundingRectOther">Input. The bounding rect for the other.</param>
        public void GetIntersections(List <C2DLineBase> Other, List <C2DPoint> pPoints,
                                     List <int> pIndexesThis, List <int> pIndexesOther,
                                     C2DRect pBoundingRectThis, C2DRect pBoundingRectOther)
        {
            var Lines = new List <CLineBaseRect>();

            for (var i = 0; i < Count; i++)
            {
                var LineRect = new CLineBaseRect();
                LineRect.Line = this[i];
                LineRect.Line.GetBoundingRect(LineRect.Rect);
                LineRect.usIndex  = i;
                LineRect.bSetFlag = true;

                if (pBoundingRectOther.Overlaps(LineRect.Rect))
                {
                    Lines.Add(LineRect);
                }
            }

            for (var d = 0; d < Other.Count; d++)
            {
                var LineRect = new CLineBaseRect();
                LineRect.Line = Other[d];
                LineRect.Line.GetBoundingRect(LineRect.Rect);
                LineRect.usIndex  = d;
                LineRect.bSetFlag = false;

                if (pBoundingRectThis.Overlaps(LineRect.Rect))
                {
                    Lines.Add(LineRect);
                }
            }

            var Comparitor = new CLineBaseRectLeftToRight();

            Lines.Sort(Comparitor);

            var j     = 0;
            var IntPt = new List <C2DPoint>();

            while (j < Lines.Count)
            {
                var r = j + 1;

                var dXLimit = Lines[j].Rect.GetRight();

                while (r < Lines.Count &&
                       Lines[r].Rect.GetLeft() < dXLimit)
                {
                    if ((Lines[j].bSetFlag ^ Lines[r].bSetFlag) &&
                        Lines[j].Rect.Overlaps(Lines[r].Rect) &&
                        Lines[j].Line.Crosses(Lines[r].Line, IntPt))
                    {
                        while (IntPt.Count > 0)
                        {
                            pPoints.Add(IntPt[IntPt.Count - 1]);
                            IntPt.RemoveAt(IntPt.Count - 1);


                            if (Lines[j].bSetFlag)
                            {
                                pIndexesThis.Add(Lines[j].usIndex);
                            }
                            else
                            {
                                pIndexesThis.Add(Lines[r].usIndex);
                            }

                            if (Lines[j].bSetFlag)
                            {
                                pIndexesOther.Add(Lines[r].usIndex);
                            }
                            else
                            {
                                pIndexesOther.Add(Lines[j].usIndex);
                            }
                        }
                    }
                    r++;
                }
                j++;
            }
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Return the bounding rect
 /// </summary>
 public abstract  void GetBoundingRect( C2DRect Rect) ;
Ejemplo n.º 29
0
        /// <summary>
        /// Returns the bounding rect.
        /// </summary>
        /// <param name="Rect">Output. The bounding rectangle.</param>
        public override void GetBoundingRect(C2DRect Rect)
        {
	        Rect.Set(P1);
    	    Rect.ExpandToInclude(P2);
	        Rect.ExpandToInclude(P3);

        }
Ejemplo n.º 30
0
 /// <summary>
 /// Gets the bounding rectangle.
 /// </summary>
 /// <param name="Rect">The rectangle to recieve the result.</param>
 public override void GetBoundingRect(C2DRect Rect)
 {
     Rect.Set(_Centre.x - Radius, _Centre.y + Radius,
              _Centre.x + Radius, _Centre.y - Radius);
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Gets the bounding rectangle.
 /// </summary>
 /// <param name="Rect">The rectangle to recieve the result.</param> 
 public override void GetBoundingRect( C2DRect Rect)
 {
     Rect.Set(_Centre.x - Radius, _Centre.y + Radius,
               _Centre.x + Radius, _Centre.y - Radius);
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Returns the bounding rectangle. (Required for virtual base class).
 /// </summary>
 /// <param name="Rect">Ouput. Bounding rectangle.</param>
 public override void GetBoundingRect(C2DRect Rect)
 {
     Rect.Set(this);
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Expands to include the rectangle.
        /// </summary>
        /// <param name="Other">Rectangle.</param> 
	    public void ExpandToInclude(C2DRect Other)
        {
            ExpandToInclude(Other.TopLeft);
            ExpandToInclude(Other.BottomRight);
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Intersection with a line base.
        /// </summary>
        /// <param name="Line">The other line.</param>
        public bool Crosses(C2DLineBase Line)
        {
	        C2DRect LineRect = new C2DRect ();
	        Line.GetBoundingRect(LineRect);

            List<C2DPoint> Temp = new List<C2DPoint>();

	        for (int i = 0; i < this.Lines.Count; i++)
	        {
		        if (LineRects[i].Overlaps( LineRect ) &&  Lines[i].Crosses(Line, Temp))
			        return true;
	        }
	        return false;

        }
Ejemplo n.º 35
0
        /// <summary>
        /// True if the point is with the range given to the shape or inside.
        /// </summary> 
        /// <param name="pt">The point to test.</param> 
        /// <param name="dRange">The range to test against.</param> 
        public bool IsWithinDistance(C2DPoint pt, double dRange)
        {
	        C2DRect RectTemp = new C2DRect(BoundingRect);
	        RectTemp.Expand(dRange);

	        if (!RectTemp.Contains(pt))
		        return false;

	        if (Lines.Count == 0)
		        return false;

	        if (Lines[0].GetPointFrom().Distance(pt) < dRange)
		        return true;

	        if (this.Contains(pt))
		        return true;

	        for (int i = 1; i < Lines.Count; i++)
	        {
		        if(Lines[i].Distance(pt) < dRange)
			        return true;
	        }

	        return false;
        }
Ejemplo n.º 36
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="Other">The other rect.</param>   
 public C2DRect(C2DRect Other)
 {
     TopLeft.Set(Other.TopLeft);
     BottomRight.Set(Other.BottomRight);
 }
Ejemplo n.º 37
0
        /// <summary>
	    /// Assignment.
        /// </summary>
        /// <param name="Other">Other rectangle.</param> 
	    public void Set(C2DRect Other)
        {
            TopLeft.x = Other.TopLeft.x;
            TopLeft.y = Other.TopLeft.y;
            BottomRight.x = Other.BottomRight.x;
            BottomRight.y = Other.BottomRight.y;
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Returns the distance from this to the other rect. 0 if there is an overlap.
        /// </summary>
        /// <param name="Other">Other rectangle.</param> 
       public double Distance(C2DRect Other)
       {
	        if (this.Overlaps(Other))
		        return 0;

	        if (Other.GetLeft() > this.BottomRight.x)
	        {
		        // Other is to the right
		        if (Other.GetBottom() > this.TopLeft.y)
		        {
			        // Other is to the top right
			        C2DPoint ptTopRight = new C2DPoint(BottomRight.x,  TopLeft.y);
			        return ptTopRight.Distance(new C2DPoint(Other.GetLeft(), Other.GetBottom()));
		        }
		        else if (Other.GetTop() < this.BottomRight.y)
		        {
			        // Other to the bottom right
			        return BottomRight.Distance( Other.TopLeft );
		        }
		        else
		        {
			        // to the right
			        return Other.GetLeft() - this.BottomRight.x;
		        }
	        }
	        else if ( Other.GetRight() < this.TopLeft.x)
	        {
		        // Other to the left
		        if (Other.GetBottom() > this.TopLeft.y)
		        {
			        // Other is to the top left
			        return  TopLeft.Distance(Other.BottomRight);
		        }
		        else if (Other.GetTop() < this.BottomRight.y)
		        {
			        // Other to the bottom left
			        C2DPoint ptBottomLeft = new C2DPoint(TopLeft.x, BottomRight.y);
			        return ptBottomLeft.Distance ( new C2DPoint( Other.GetRight(), Other.GetTop()));
		        }
		        else
		        {
			        //Just to the left
			        return (this.TopLeft.x - Other.GetRight());
		        }
	        }
	        else
	        {
		        // There is horizontal overlap;
		        if (Other.GetBottom() >  TopLeft.y)
			        return Other.GetBottom() -  TopLeft.y;
		        else
			        return BottomRight.y - Other.GetTop();
	        }		

        }
Ejemplo n.º 39
0
        /// <summary>
        /// True if this is above or below the other
        /// </summary>
        /// <param name="Other"></param>
        /// <returns></returns>
        public bool OverlapsVertically( C2DRect Other)
        {
	        return !(Other.GetLeft() >= BottomRight.x ||
				          Other.GetRight() <=  TopLeft.x);
        }
Ejemplo n.º 40
0
        /// <summary>
        /// True if this is below the other.
        /// </summary>
        /// <param name="Other"></param>
        /// <returns></returns>
        public bool OverlapsBelow( C2DRect Other)
        {
	        if (Other.GetLeft() >= BottomRight.x ||
				          Other.GetRight() <=  TopLeft.x)
	        {
		        return false;
	        }
	        else 
	        {
		        return BottomRight.y < Other.GetTop();
	        }
        }
Ejemplo n.º 41
0
        /// <summary>
        /// True if there is an overlap, returns the overlap.
        /// </summary>
        /// <param name="Other">Rectangle.</param> 
        /// <param name="Overlap">Output. The overlap.</param> 
        public bool Overlaps(C2DRect Other, C2DRect Overlap)
        {
            C2DPoint ptOvTL = new C2DPoint();
            C2DPoint ptOvBR = new C2DPoint();

            ptOvTL.y = Math.Min(TopLeft.y, Other.TopLeft.y);
            ptOvBR.y = Math.Max(BottomRight.y, Other.BottomRight.y);

            ptOvTL.x = Math.Max(TopLeft.x, Other.TopLeft.x);
            ptOvBR.x = Math.Min(BottomRight.x, Other.BottomRight.x);

            Overlap.Set(ptOvTL, ptOvBR);

            return Overlap.IsValid();
        }
Ejemplo n.º 42
0
        /// <summary>
        ///  Gets the bounding rectangle.
        /// </summary>
        /// <param name="Rect">The bounding rectangle to recieve the result.</param>
        public override void GetBoundingRect(C2DRect Rect)
        {
            if (!IsValid())
            {
                return;
            }

            C2DPoint CentrePoint = new C2DPoint(GetCircleCentre());
            C2DPoint EndPoint    = new C2DPoint(Line.GetPointTo());

            // First set up the rect that bounds the 2 points then check for if the arc expands this.
            Line.GetBoundingRect(Rect);

            // If the arc crosses the y axis..
            if (((Line.point.x - CentrePoint.x) * (EndPoint.x - CentrePoint.x)) < 0)
            {
                // if the +ve y axis..
                if (Line.GetMidPoint().y > CentrePoint.y)
                {
                    if (CentreOnRight ^ ArcOnRight)
                    {
                        Rect.SetTop(CentrePoint.y + Radius);
                    }
                    else
                    {
                        // If the segment is the "Big" bit....
                        Rect.SetBottom(CentrePoint.y - Radius);
                    }
                }
                else         // if the -ve y axis...
                {
                    if (CentreOnRight ^ ArcOnRight)
                    {
                        Rect.SetBottom(CentrePoint.y - Radius);
                    }
                    else
                    {
                        // If the segment is th "Big" bit then...
                        Rect.SetTop(CentrePoint.y + Radius);
                    }
                }
            }
            else if (!(CentreOnRight ^ ArcOnRight))
            {
                Rect.SetBottom(CentrePoint.y - Radius);
                Rect.SetTop(CentrePoint.y + Radius);
            }

            // If the arc crosses the x axis..
            if (((Line.point.y - CentrePoint.y) * (EndPoint.y - CentrePoint.y)) < 0)
            {
                // if the +ve x axis..
                if (Line.GetMidPoint().x > CentrePoint.x)
                {
                    if (CentreOnRight ^ ArcOnRight)
                    {
                        Rect.SetRight(CentrePoint.x + Radius);
                    }
                    else
                    {
                        // If the segment is th "Big" bit then...
                        Rect.SetLeft(CentrePoint.x - Radius);
                    }
                }
                else         // if the -ve x axis...
                {
                    if (CentreOnRight ^ ArcOnRight)
                    {
                        Rect.SetLeft(CentrePoint.x - Radius);
                    }
                    else
                    {
                        // If the segment is th "Big" bit then...
                        Rect.SetRight(CentrePoint.x + Radius);
                    }
                }
            }
            else if (!(CentreOnRight ^ ArcOnRight))
            {
                Rect.SetLeft(CentrePoint.x - Radius);
                Rect.SetRight(CentrePoint.x + Radius);
            }
        }
Ejemplo n.º 43
0
        /// <summary>
        /// Creates a path based on a polygon.
        /// </summary>
        private System.Drawing.Drawing2D.GraphicsPath CreatePath( C2DPolyBase Poly)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            if (Poly.Lines.Count == 0)
                return gp;

            for (int i = 0; i < Poly.Lines.Count; i++)
            {
                if (Poly.Lines[i] is C2DLine)
                {
                    C2DPoint ptFrom = Poly.Lines[i].GetPointFrom();
                    C2DPoint ptTo = Poly.Lines[i].GetPointTo();
                    ScaleAndOffSet(ptFrom);
                    ScaleAndOffSet(ptTo);
                    gp.AddLine((int)ptFrom.x, (int)ptFrom.y, (int)ptTo.x, (int)ptTo.y);
                }
                else if (Poly.Lines[i] is C2DArc)
                {

                    C2DRect Rect = new C2DRect();
                    int nStartAngle = 0;
                    int nSweepAngle = 0;

                    GetArcParameters(Poly.Lines[i] as C2DArc, Rect, ref nStartAngle, ref nSweepAngle);

                    if (nSweepAngle == 0)
                        nSweepAngle = 1;

                    int Width = (int)Rect.Width();
                    if (Width == 0)
                        Width = 1;
                    int Height = (int)Rect.Height();
                    if (Height == 0)
                        Height = 1;

                    gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                        Width, Height, nStartAngle, nSweepAngle);

                }
            }

            gp.CloseFigure();

            return gp;
        }
Ejemplo n.º 44
0
        /// <summary>
        /// True if there is an overlap.
        /// </summary>
        /// <param name="Other">Other rectangle.</param> 
	    public bool Overlaps(C2DRect Other)
        {
            bool bOvX = !(Other.GetLeft() >= BottomRight.x ||
                          Other.GetRight() <= TopLeft.x);

            bool bOvY = !(Other.GetBottom() >= TopLeft.y ||
                          Other.GetTop() <= BottomRight.y);

            return bOvX && bOvY;
        }
Ejemplo n.º 45
0
 /// <summary>
 /// True if this is above or below the other
 /// </summary>
 /// <param name="Other"></param>
 /// <returns></returns>
 public bool OverlapsVertically(C2DRect Other)
 {
     return(!(Other.GetLeft() >= BottomRight.x ||
              Other.GetRight() <= TopLeft.x));
 }
Ejemplo n.º 46
0
 /// <summary>
 /// Returns the bounding rectangle.
 /// </summary>
 public override void GetBoundingRect( C2DRect Rect)
 {
     Arc.GetBoundingRect( Rect);
 }
Ejemplo n.º 47
0
        /// <summary>
        /// Returns the bounding rectangle.
        /// </summary>
        /// <param name="Rect">Rectangle to recieve the result.</param> 
        public void GetBoundingRect(C2DRect Rect) 
        {
            Rect.Set(_Rim.BoundingRect);

	        for (int i = 0; i < _Holes.Count; i++)
	        {
		        Rect.ExpandToInclude( _Holes[i].BoundingRect);
	        }
        }
Ejemplo n.º 48
0
        /// <summary>
        /// Returns the boolean result (e.g. union) of 2 shapes. Boolean Operation defined by 
        /// the inside / outside flags.
        /// </summary>
        /// <param name="Other">Other polygon.</param> 
        /// <param name="HoledPolys">Set of polygons to recieve the result.</param> 
        /// <param name="bThisInside">Does the operation require elements of this INSIDE the other.</param> 
        /// <param name="bOtherInside">Does the operation require elements of the other INSIDE this.</param> 
        /// <param name="grid">The grid with the degenerate settings.</param> 
        public void GetBoolean(C2DHoledPolyBase Other, List<C2DHoledPolyBase> HoledPolys,
                            bool bThisInside, bool bOtherInside,
                            CGrid grid)
        {
            if (_Rim.Lines.Count == 0 || Other.Rim.Lines.Count == 0)
		        return;

            if (_Rim.BoundingRect.Overlaps(Other.Rim.BoundingRect))
	        {
		        switch (grid.DegenerateHandling)
		        {
		        case CGrid.eDegenerateHandling.None:
			        {
				        List<C2DPolyBase> CompleteHoles1 = new List<C2DPolyBase>();
				        List<C2DPolyBase> CompleteHoles2 = new List<C2DPolyBase>();
				        C2DLineBaseSetSet Routes1 = new C2DLineBaseSetSet(); 
				        C2DLineBaseSetSet Routes2 = new C2DLineBaseSetSet(); 
				        GetRoutes( this, bThisInside, Other, bOtherInside, Routes1, Routes2,
								        CompleteHoles1, CompleteHoles2, grid);

				        Routes1.ExtractAllOf(Routes2);

				        if (Routes1.Count > 0)
				        {
					        Routes1.MergeJoining();

					        List<C2DPolyBase> Polygons = new List<C2DPolyBase>();

					        for (int i = Routes1.Count - 1; i >= 0; i--)
					        {
						        C2DLineBaseSet pRoute = Routes1[i];
						        if (pRoute.IsClosed(true) )
						        {
							        Polygons.Add(new C2DPolyBase());
							        Polygons[Polygons.Count - 1].CreateDirect(pRoute);
						        }
						        else
						        {
							     //   Debug.Assert(false);
							        grid.LogDegenerateError();
						        }	
					        }

                            C2DHoledPolyBaseSet NewComPolys = new C2DHoledPolyBaseSet();
        					
					        PolygonsToHoledPolygons(NewComPolys, Polygons);

					        NewComPolys.AddKnownHoles( CompleteHoles1 );

					        NewComPolys.AddKnownHoles( CompleteHoles2 );

					        if ( !bThisInside && !bOtherInside && NewComPolys.Count != 1)
					        {
							  //  Debug.Assert(false);
							    grid.LogDegenerateError();
					        }


					        HoledPolys.AddRange(NewComPolys);

                            NewComPolys.Clear();
				        }
			        }
			        break;
		        case CGrid.eDegenerateHandling.RandomPerturbation:
			        {
				        C2DHoledPolyBase OtherCopy = new C2DHoledPolyBase(Other);
				        OtherCopy.RandomPerturb();
                        grid.DegenerateHandling = CGrid.eDegenerateHandling.None;
				        GetBoolean( OtherCopy, HoledPolys, bThisInside, bOtherInside , grid );
                        grid.DegenerateHandling = CGrid.eDegenerateHandling.RandomPerturbation;
			        }
			        break;
		        case CGrid.eDegenerateHandling.DynamicGrid:
			        {
				        C2DRect Rect = new C2DRect();
                        if (_Rim.BoundingRect.Overlaps(Other.Rim.BoundingRect, Rect))
				        {
					        //double dOldGrid = CGrid::GetGridSize();
					        grid.SetToMinGridSize(Rect, false);
                            grid.DegenerateHandling = CGrid.eDegenerateHandling.PreDefinedGrid;
					        GetBoolean( Other, HoledPolys, bThisInside, bOtherInside , grid );
                            grid.DegenerateHandling = CGrid.eDegenerateHandling.DynamicGrid;
				        }
			        }
			        break;
		        case CGrid.eDegenerateHandling.PreDefinedGrid:
			        {
				        C2DHoledPolyBase P1 = new C2DHoledPolyBase(this);
                        C2DHoledPolyBase P2 = new C2DHoledPolyBase(Other);
				        P1.SnapToGrid(grid);
				        P2.SnapToGrid(grid);
				        C2DVector V1 = new C2DVector( P1.Rim.BoundingRect.TopLeft,  P2.Rim.BoundingRect.TopLeft);
				        double dPerturbation = grid.GridSize; // ensure it snaps back to original grid positions.
				        if (V1.i > 0)
                            V1.i = dPerturbation;
                        else
                            V1.i = -dPerturbation;	// move away slightly if possible
				        if (V1.j > 0)
                            V1.j = dPerturbation;
                        else 
                            V1.j = -dPerturbation; // move away slightly if possible
				        V1.i *= 0.411923;// ensure it snaps back to original grid positions.
				        V1.j *= 0.313131;// ensure it snaps back to original grid positions.
        				
				        P2.Move( V1 );
                        grid.DegenerateHandling = CGrid.eDegenerateHandling.None;
				        P1.GetBoolean( P2, HoledPolys, bThisInside, bOtherInside , grid );

                        for (int i = 0 ; i < HoledPolys.Count ; i++)
				            HoledPolys[i].SnapToGrid(grid);

                        grid.DegenerateHandling = CGrid.eDegenerateHandling.PreDefinedGrid;

			        }
			        break;
		        case CGrid.eDegenerateHandling.PreDefinedGridPreSnapped:
			        {
				        C2DHoledPolyBase P2 = new C2DHoledPolyBase(Other);
                        C2DVector V1 = new C2DVector(_Rim.BoundingRect.TopLeft, P2.Rim.BoundingRect.TopLeft);
				        double dPerturbation = grid.GridSize;
				        if (V1.i > 0) 
                            V1.i = dPerturbation; 
                        else
                            V1.i = -dPerturbation; // move away slightly if possible
				        if (V1.j > 0) 
                            V1.j = dPerturbation;
                        else
                            V1.j = -dPerturbation; // move away slightly if possible
				        V1.i *= 0.411923; // ensure it snaps back to original grid positions.
				        V1.j *= 0.313131;// ensure it snaps back to original grid positions.
				        P2.Move( V1 );

                        grid.DegenerateHandling = CGrid.eDegenerateHandling.None;
                        GetBoolean(P2, HoledPolys, bThisInside, bOtherInside, grid);

                        for (int i = 0; i < HoledPolys.Count; i++)
                            HoledPolys[i].SnapToGrid(grid);

                        grid.DegenerateHandling = CGrid.eDegenerateHandling.PreDefinedGridPreSnapped;
			        }
			        break;
		        }// switch
	        }
        }
Ejemplo n.º 49
0
 /// <summary>
 /// Returns the bounding rectangle.
 /// </summary>
 public override void GetBoundingRect(C2DRect Rect)
 {
     Arc.GetBoundingRect(Rect);
 }
Ejemplo n.º 50
0
 /// <summary>
 /// Returns the bounding rectangle which will be set to this point.
 /// </summary>
 /// <param name="Rect">The rectangle to recieve the result.</param>
 public override void GetBoundingRect( C2DRect Rect)
 {
     Rect.Set(this);
 }
Ejemplo n.º 51
0
        /// <summary>
        /// Creates a random shape.
        /// </summary>
        /// <param name="cBoundary">The boundary.</param> 
        /// <param name="nMinPoints">The minimum points.</param> 
        /// <param name="nMaxPoints">The maximum points.</param> 
        public bool CreateRandom(C2DRect cBoundary, int nMinPoints, int nMaxPoints)
        {
            C2DPolygon Poly = new C2DPolygon();
            if (!Poly.CreateRandom(cBoundary, nMinPoints, nMaxPoints))
                return false;

            CRandomNumber rCenOnRight = new CRandomNumber(0, 1);

            this.Set( Poly );

            for (int i = 0 ; i < Lines.Count; i ++)
            {
                C2DLineBase pLine = Lines[i];

                bool bCenOnRight = (rCenOnRight.GetInt() > 0 );
                double dLength = pLine.GetLength();
                CRandomNumber Radius = new CRandomNumber(dLength , dLength * 3);

                C2DArc pNew = new C2DArc( pLine.GetPointFrom(), pLine.GetPointTo(),
                                    Radius.Get(), bCenOnRight, !bCenOnRight);

                if (!this.Crosses( pNew ))
                {
                    Lines[i] = pNew;
                    pNew.GetBoundingRect(LineRects[i]);
                    BoundingRect.ExpandToInclude(LineRects[i]);
                }
            }

               //     this.MakeLineRects();
              //      this.MakeBoundingRect();

            return true;
        }
Ejemplo n.º 52
0
        /// <summary>
        /// True if the entire other rectangle is within.
        /// </summary>
        /// <param name="Other">Other rectangle.</param> 
	    public bool Contains(C2DRect Other)
        {
            return (Other.GetLeft() > TopLeft.x &&
                      Other.GetRight() < BottomRight.x &&
                      Other.GetBottom() > BottomRight.y &&
                      Other.GetTop() < TopLeft.y);
        }
Ejemplo n.º 53
0
        /// <summary>   
        /// Sets to the minimum recommended size for degenerate handling.
        /// </summary>
        public void SetToMinGridSize(C2DRect cRect, bool bRoundToNearestDecimalFactor)
        {
	        SetGridSize( GetMinGridSize(cRect, bRoundToNearestDecimalFactor));

        }
Ejemplo n.º 54
0
        /// <summary>
        /// Draws a rectangle filled.
        /// </summary>
        public void DrawFilled(C2DRect Rect, Graphics graphics, Brush brush)
        {
            C2DPoint pt1 = new C2DPoint(Rect.TopLeft);
            C2DPoint pt2 = new C2DPoint(Rect.BottomRight);
            this.ScaleAndOffSet(pt1);
            this.ScaleAndOffSet(pt2);

            int TLx = (int)pt1.x;
            if (Scale.x < 0)
                TLx = (int)pt2.x;

            int TLy = (int)pt2.y;
            if (Scale.x < 0)
                TLy = (int)pt1.y;

            graphics.FillRectangle(brush, TLx, TLy, (int)Math.Abs(pt1.x - pt2.x),
                                                    (int)Math.Abs(pt1.y - pt2.y));
        }
Ejemplo n.º 55
0
        /// <summary>
        /// True if it crosses the line. Provides the intersection points.
        /// </summary>
        /// <param name="Line">The other line.</param>
        /// <param name="IntersectionPts">Output. The intersection points.</param>
        public bool Crosses(C2DLineBase Line, List<C2DPoint> IntersectionPts)
        {
	        C2DRect LineRect = new C2DRect();
	        Line.GetBoundingRect( LineRect);

	        if (!BoundingRect.Overlaps(LineRect))
		        return false;

	        Debug.Assert(Lines.Count == LineRects.Count);

	        if(Lines.Count != LineRects.Count)
		        return false;

	        C2DPointSet IntersectionTemp = new C2DPointSet();

	        bool bResult = false;

            for (int i = 0; i < this.Lines.Count; i++)
	        {
		        if (LineRects[i].Overlaps(LineRect) &&
			        Lines[i].Crosses(Line, IntersectionTemp as List<C2DPoint>))
		        {
			        bResult = true;
		        }
	        }

	        IntersectionPts.InsertRange(0, IntersectionTemp);

	        return bResult;
        }
Ejemplo n.º 56
0
        /// <summary>
        /// True if this is above the other.
        /// </summary>
        /// <param name="Other"></param>
        /// <returns></returns>
        public bool OverlapsAbove( C2DRect Other)
        {
	        if (Other.GetLeft() >= BottomRight.x ||
				          Other.GetRight() <=  TopLeft.x)
	        {
		        return false;
	        }
	        else 
	        {
		        return TopLeft.y > Other.GetBottom();
	        }
        }
Ejemplo n.º 57
0
        /// <summary>
        /// Gets the boolean operation with the other. e.g. union / intersection.
        /// </summary>
        /// <param name="Other">The other polygon.</param>
        /// <param name="HoledPolys">The set to recieve the result.</param>
        /// <param name="bThisInside">The flag to indicate routes inside.</param>
        /// <param name="bOtherInside">The flag to indicate routes inside for the other.</param>
        /// <param name="grid">The degenerate settings.</param>
        public void GetBoolean(C2DPolyBase Other, List<C2DHoledPolyBase> HoledPolys,
                            bool bThisInside, bool bOtherInside,
                            CGrid grid)
        {
            
	        if (BoundingRect.Overlaps(Other.BoundingRect ))
	        {
		        switch (grid.DegenerateHandling)
		        {
		        case CGrid.eDegenerateHandling.None:
			        {
				        C2DLineBaseSetSet Routes1 = new C2DLineBaseSetSet();
                        C2DLineBaseSetSet Routes2 = new C2DLineBaseSetSet();
				        C2DPolyBase.GetRoutes( this, bThisInside, Other, bOtherInside, Routes1, Routes2);
				        Routes1.ExtractAllOf(Routes2);

				        if (Routes1.Count > 0)
				        {
					        // Add all the joining routes together to form closed routes
					        Routes1.MergeJoining();
					        // Set up some temporary polygons.
					        List<C2DPolyBase> Polygons = new List<C2DPolyBase>();
					        // Turn the routes into polygons.
					        for (int i = Routes1.Count - 1; i >= 0; i--)
					        {

						        if (Routes1[i].IsClosed(true) && Routes1[i].Count > 2)
						        {
							        Polygons.Add(new C2DPolyBase());
							        Polygons[Polygons.Count - 1].CreateDirect( Routes1[i]);
						        }
						        else
						        {
							     //   Debug.Assert(false);
							        grid.LogDegenerateError();
						        }	
					        }
                            

					        // Set up some temporary holed polygons
					        C2DHoledPolyBaseSet NewComPolys = new C2DHoledPolyBaseSet();
					        // Turn the set of polygons into holed polygons. Not needed for intersection.
					        if (!(bThisInside && bOtherInside))
					        {
						        C2DHoledPolyBase.PolygonsToHoledPolygons(NewComPolys, Polygons);
						        if (NewComPolys.Count != 1)
						        {
							     //   Debug.Assert(false);
							        grid.LogDegenerateError();
						        }
					        }
					        else
					        {
                                for (int i = 0; i < Polygons.Count; i++)
						            HoledPolys.Add(new C2DHoledPolyBase(Polygons[i]));
					        }

					        // Now add them all to the provided set.
                            for (int i = 0 ; i < NewComPolys.Count; i++)
					            HoledPolys.Add(NewComPolys[i]);
				        }
			        }
			        break;
		        case CGrid.eDegenerateHandling.RandomPerturbation:
			        {
				        C2DPolyBase OtherCopy = new C2DPolyBase(Other);
				        OtherCopy.RandomPerturb();
                        grid.DegenerateHandling = CGrid.eDegenerateHandling.None;
				        GetBoolean( OtherCopy, HoledPolys, bThisInside, bOtherInside, grid);
                        grid.DegenerateHandling = CGrid.eDegenerateHandling.RandomPerturbation;
			        }
			        break;
		        case CGrid.eDegenerateHandling.DynamicGrid:
			        {
				        C2DRect Rect = new C2DRect(); 
				        if (this.BoundingRect.Overlaps(Other.BoundingRect, Rect))
				        {
					        double dOldGrid = grid.GridSize;
					        grid.SetToMinGridSize(Rect, false);
                            grid.DegenerateHandling = CGrid.eDegenerateHandling.PreDefinedGrid;
					        GetBoolean( Other, HoledPolys, bThisInside, bOtherInside, grid);
                            grid.DegenerateHandling = CGrid.eDegenerateHandling.DynamicGrid;
				        }
			        }
			        break;
		        case CGrid.eDegenerateHandling.PreDefinedGrid:
			        {
				        C2DPolyBase P1 = new C2DPolyBase(this);
                        C2DPolyBase P2 = new C2DPolyBase(Other);
				        P1.SnapToGrid(grid);
                        P2.SnapToGrid(grid);
				        C2DVector V1 = new C2DVector( P1.BoundingRect.TopLeft,  P2.BoundingRect.TopLeft);
				        double dPerturbation = grid.GridSize; // ensure it snaps back to original grid positions.
				        if(V1.i > 0) 
                            V1.i = dPerturbation;
                        else
                           V1.i = -dPerturbation;	// move away slightly if possible
				        if(V1.j > 0) 
                            V1.j = dPerturbation;
                        else
                            V1.j = -dPerturbation; // move away slightly if possible
				        V1.i *= 0.411923;// ensure it snaps back to original grid positions.
				        V1.j *= 0.313131;// ensure it snaps back to original grid positions.

				        P2.Move( V1 );
                        grid.DegenerateHandling = CGrid.eDegenerateHandling.None;
				        P1.GetBoolean( P2, HoledPolys, bThisInside, bOtherInside, grid);

                        for (int i = 0; i < HoledPolys.Count; i++)
                            HoledPolys[i].SnapToGrid(grid);

	                    grid.DegenerateHandling = CGrid.eDegenerateHandling.PreDefinedGrid;
			        }
			        break;
		        case CGrid.eDegenerateHandling.PreDefinedGridPreSnapped:
			        {
				        C2DPolyBase P2 = new C2DPolyBase(Other);
				        C2DVector V1 = new C2DVector( this.BoundingRect.TopLeft,  P2.BoundingRect.TopLeft);
				        double dPerturbation = grid.GridSize; // ensure it snaps back to original grid positions.
				        if (V1.i > 0)
                            V1.i = dPerturbation;
                        else
                            V1.i = -dPerturbation; // move away slightly if possible
				        if (V1.j > 0)
                            V1.j = dPerturbation;
                        else
                            V1.j = -dPerturbation; // move away slightly if possible
				        V1.i *= 0.411923;// ensure it snaps back to original grid positions.
				        V1.j *= 0.313131;// ensure it snaps back to original grid positions.

				        P2.Move( V1 );
                        grid.DegenerateHandling = CGrid.eDegenerateHandling.None;
				        GetBoolean( P2, HoledPolys, bThisInside, bOtherInside, grid);

                        for (int i = 0; i < HoledPolys.Count; i++)
                            HoledPolys[i].SnapToGrid(grid);
                        grid.DegenerateHandling = CGrid.eDegenerateHandling.PreDefinedGridPreSnapped;
			        }
			        break;
		        }
                       
            }
        }
Ejemplo n.º 58
0
        /// <summary>
        /// Gets the parameters required to draw an arc.
        /// </summary>
        private void GetArcParameters(C2DArc Arc, C2DRect Rect, ref int nStartAngle, ref int nSweepAngle)
        {
            C2DPoint Centre = Arc.GetCircleCentre();

            Rect.Set(Centre.x - Arc.Radius, Centre.y + Arc.Radius,
                                        Centre.x + Arc.Radius, Centre.y - Arc.Radius);

            ScaleAndOffSet(Rect.TopLeft);
            ScaleAndOffSet(Rect.BottomRight);
            ScaleAndOffSet(Centre); // CR 19-1-09

            C2DPoint bottomRightTemp = new C2DPoint(Rect.BottomRight); // to make valid // CR 11-3-09
            Rect.BottomRight.Set(Rect.TopLeft); // to make valid // CR 11-3-09
            Rect.ExpandToInclude(bottomRightTemp); // to make valid // CR 11-3-09

            C2DPoint pt1 = Arc.Line.GetPointFrom();
            C2DPoint pt2 = Arc.Line.GetPointTo();
            this.ScaleAndOffSet(pt1);
            this.ScaleAndOffSet(pt2);

            C2DVector vec1 = new C2DVector(Centre, pt1);
            C2DVector vec2 = new C2DVector(Centre, pt2);

            C2DVector vecx = new C2DVector(100, 0); // x - axis

            double dStartAngle = vecx.AngleToLeft(vec1) * Constants.conDegreesPerRadian;
            double dSweepAngle = 0;

            bool bAlreadyFlipped = Scale.x * Scale.y < 0;

            if (Arc.ArcOnRight ^ bAlreadyFlipped)
                dSweepAngle = vec1.AngleToLeft(vec2) * Constants.conDegreesPerRadian;
            else
                dSweepAngle = -vec1.AngleToRight(vec2) * Constants.conDegreesPerRadian;

            nStartAngle = (int)dStartAngle;
            if (nStartAngle == 360)
                nStartAngle = 0;
            nSweepAngle = (int)dSweepAngle;
        }
Ejemplo n.º 59
0
        /// <summary>
        /// Returns the bounding rectangle.
        /// </summary>
        /// <param name="Rect">Output. The bounding rectangle.</param>
        public override void GetBoundingRect( C2DRect Rect) 
        {
	        Rect.Set(point);
	        Rect.ExpandToInclude(GetPointTo());
        }
Ejemplo n.º 60
0
        /// <summary>
        /// Forms the bounding rectangles for all the lines.
        /// </summary>
        protected void MakeLineRects()
        {
	        LineRects.Clear();

	        for (int i = 0 ; i  < Lines.Count; i++)
	        {
		        C2DRect pRect = new C2DRect();
		        Lines[i].GetBoundingRect( pRect);
		        LineRects.Add( pRect );
	        }

        }