Beispiel #1
0
        internal static bool BoundingIntersectWithLine(Bounding bounding, LitMath.Line2 line)
        {
            Bounding lineBound = new Bounding(line.startPoint, line.endPoint);

            if (!bounding.IntersectWith(lineBound))
            {
                return(false);
            }

            if (bounding.Contains(line.startPoint) ||
                bounding.Contains(line.endPoint))
            {
                return(true);
            }

            LitMath.Vector2 pkPnt1 = new LitMath.Vector2(bounding.left, bounding.bottom);
            LitMath.Vector2 pkPnt2 = new LitMath.Vector2(bounding.left, bounding.top);
            LitMath.Vector2 pkPnt3 = new LitMath.Vector2(bounding.right, bounding.top);
            LitMath.Vector2 pkPnt4 = new LitMath.Vector2(bounding.right, bounding.bottom);

            double d1 = LitMath.Vector2.Cross(line.startPoint - pkPnt1, line.endPoint - pkPnt1);
            double d2 = LitMath.Vector2.Cross(line.startPoint - pkPnt2, line.endPoint - pkPnt2);
            double d3 = LitMath.Vector2.Cross(line.startPoint - pkPnt3, line.endPoint - pkPnt3);
            double d4 = LitMath.Vector2.Cross(line.startPoint - pkPnt4, line.endPoint - pkPnt4);

            if (d1 * d2 <= 0 || d1 * d3 <= 0 || d1 * d4 <= 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        internal override bool Cross(Bounding selectBound, Entity entity)
        {
            Text text = entity as Text;

            if (text == null)
            {
                return(false);
            }

            Bounding textBound = text.bounding;

            if (selectBound.Contains(textBound))
            {
                return(true);
            }

            if (textBound.IntersectWith(selectBound))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        internal override bool Cross(Bounding selectBound, Entity entity)
        {
            XPoint xPoint = entity as XPoint;

            if (xPoint == null)
            {
                return(false);
            }

            Bounding xPointBound = xPoint.bounding;

            return(selectBound.Contains(xPointBound) || xPointBound.IntersectWith(selectBound));
        }
Beispiel #4
0
        internal override bool Cross(Bounding selectBound, Entity entity)
        {
            Arc arc = entity as Arc;

            if (arc == null)
            {
                return(false);
            }

            Bounding arcBounding = arc.bounding;

            if (selectBound.Contains(arcBounding))
            {
                return(true);
            }

            if (!selectBound.IntersectWith(arcBounding))
            {
                return(false);
            }

            Circle circle = new Circle(arc.center, arc.radius);

            LitMath.Vector2 nearestPntOnBound = new LitMath.Vector2(
                Math.Max(selectBound.left, Math.Min(circle.center.x, selectBound.right)),
                Math.Max(selectBound.bottom, Math.Min(circle.center.y, selectBound.top)));

            if (LitMath.Vector2.Distance(nearestPntOnBound, circle.center) <= circle.radius)
            {
                double bdLeft   = selectBound.left;
                double bdRight  = selectBound.right;
                double bdTop    = selectBound.top;
                double bdBottom = selectBound.bottom;

                List <LitMath.Vector2> pnts = new List <LitMath.Vector2>();
                pnts.Add(new LitMath.Vector2(bdLeft, bdTop));
                pnts.Add(new LitMath.Vector2(bdLeft, bdBottom));
                pnts.Add(new LitMath.Vector2(bdRight, bdTop));
                pnts.Add(new LitMath.Vector2(bdRight, bdBottom));
                LitMath.Vector2 xp = new LitMath.Vector2(1, 0);
                foreach (LitMath.Vector2 pnt in pnts)
                {
                    if (LitMath.Vector2.Distance(pnt, circle.center) >= circle.radius)
                    {
                        LitMath.Vector2 v   = pnt - circle.center;
                        double          rad = LitMath.Vector2.AngleInRadian(xp, v);
                        if (LitMath.Vector2.Cross(xp, v) < 0)
                        {
                            rad = Math.PI * 2 - rad;
                        }

                        if (AngleInRange(rad, arc.startAngle, arc.endAngle))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            else
            {
                return(false);
            }
        }
Beispiel #5
0
        internal override bool Cross(Bounding selectBound, Entity entity)
        {
            Arc arc = entity as Arc;

            if (arc == null)
            {
                return(false);
            }

            Bounding arcBounding = arc.Bounding;

            if (selectBound.Contains(arcBounding))
            {
                return(true);
            }

            if (!selectBound.IntersectWith(arcBounding))
            {
                return(false);
            }

            Circle   circle            = new Circle(arc.center, arc.radius);
            CADPoint nearestPntOnBound = new CADPoint(
                System.Math.Max(selectBound.left, System.Math.Min(circle.center.X, selectBound.right)),
                System.Math.Max(selectBound.bottom, System.Math.Min(circle.center.Y, selectBound.top)));

            if (CADPoint.Distance(nearestPntOnBound, circle.center) <= circle.radius)
            {
                double bdLeft   = selectBound.left;
                double bdRight  = selectBound.right;
                double bdTop    = selectBound.top;
                double bdBottom = selectBound.bottom;

                List <CADPoint> pnts = new List <CADPoint>();
                pnts.Add(new CADPoint(bdLeft, bdTop));
                pnts.Add(new CADPoint(bdLeft, bdBottom));
                pnts.Add(new CADPoint(bdRight, bdTop));
                pnts.Add(new CADPoint(bdRight, bdBottom));
                CADVector xp = new CADVector(1, 0);
                foreach (CADPoint pnt in pnts)
                {
                    if (CADPoint.Distance(pnt, circle.center) >= circle.radius)
                    {
                        CADVector v   = pnt - circle.center;
                        double    rad = CADVector.AngleInRadian(xp, v);
                        if (CADVector.Cross(xp, v) < 0)
                        {
                            rad = System.Math.PI * 2 - rad;
                        }

                        if (AngleInRange(rad, arc.startAngle, arc.endAngle))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            else
            {
                return(false);
            }
        }