예제 #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);
            }
        }
예제 #2
0
파일: Draw.cs 프로젝트: NerdDev/Hackmobile
 public static DrawAction <T> Inside <T>(Bounding bounds)
 {
     return((arr, x, y) =>
     {
         return bounds.Contains(x, y);
     });
 }
예제 #3
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);
            }
        }
예제 #4
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));
        }
예제 #5
0
        internal override bool Cross(Bounding selectBound, Entity entity)
        {
            Polyline polyline = entity as Polyline;

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

            Bounding polylineBound = polyline.Bounding;

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

            Rectangle2 selRect = new Rectangle2(
                new CADPoint(selectBound.left, selectBound.bottom),
                new CADPoint(selectBound.right, selectBound.top));

            Line2 rectLine1 = new Line2(selRect.leftBottom, selRect.leftTop);
            Line2 rectLine2 = new Line2(selRect.leftTop, selRect.rightTop);
            Line2 rectLine3 = new Line2(selRect.rightTop, selRect.rightBottom);
            Line2 rectLine4 = new Line2(selRect.rightBottom, selRect.leftBottom);

            for (int i = 1; i < polyline.NumberOfVertices; ++i)
            {
                CADPoint spnt         = polyline.GetPointAt(i - 1);
                CADPoint epnt         = polyline.GetPointAt(i);
                Line2    line2        = new Line2(spnt, epnt);
                CADPoint intersection = new CADPoint();
                if (Line2.Intersect(rectLine1, line2, ref intersection) ||
                    Line2.Intersect(rectLine2, line2, ref intersection) ||
                    Line2.Intersect(rectLine3, line2, ref intersection) ||
                    Line2.Intersect(rectLine4, line2, ref intersection))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #6
0
        internal override bool Cross(Bounding selectBound, Entity entity)
        {
            Line line = entity as Line;

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

            Bounding lineBound = line.Bounding;

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

            Rectangle2 selRect = new Rectangle2(
                new CADPoint(selectBound.left, selectBound.bottom),
                new CADPoint(selectBound.right, selectBound.top));

            Line2 rectLine1 = new Line2(selRect.leftBottom, selRect.leftTop);
            Line2 rectLine2 = new Line2(selRect.leftTop, selRect.rightTop);
            Line2 rectLine3 = new Line2(selRect.rightTop, selRect.rightBottom);
            Line2 rectLine4 = new Line2(selRect.rightBottom, selRect.leftBottom);
            Line2 line2     = new Line2(line.startPoint, line.endPoint);

            CADPoint intersection = new CADPoint();

            if (Line2.Intersect(rectLine1, line2, ref intersection) ||
                Line2.Intersect(rectLine2, line2, ref intersection) ||
                Line2.Intersect(rectLine3, line2, ref intersection) ||
                Line2.Intersect(rectLine4, line2, ref intersection))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #7
0
 internal virtual bool Window(Bounding bounding, Entity entity)
 {
     return(bounding.Contains(entity.bounding));
 }
예제 #8
0
파일: ArcRS.cs 프로젝트: zhudaijie/SharpCAD
        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);
            }
        }
예제 #9
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);
            }
        }