コード例 #1
0
ファイル: BoundsLine.cs プロジェクト: bangush/Core2D
        public bool Contains(IBaseShape shape, Point2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is ILineShape line))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            Point2 a;
            Point2 b;

            if (line.State.Flags.HasFlag(ShapeStateFlags.Size) && scale != 1.0)
            {
                a = new Point2(line.Start.X * scale, line.Start.Y * scale);
                b = new Point2(line.End.X * scale, line.End.Y * scale);
            }
            else
            {
                a = new Point2(line.Start.X, line.Start.Y);
                b = new Point2(line.End.X, line.End.Y);
            }

            var    nearest  = target.NearestOnLine(a, b);
            double distance = target.DistanceTo(nearest);

            return(distance < radius);
        }
コード例 #2
0
ファイル: ShapeBounds.cs プロジェクト: kamaloff/Core2D
        /// <summary>
        /// Checks if line contains point.
        /// </summary>
        /// <param name="line"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static bool Contains(XLine line, Vector2 v, double threshold, double dx, double dy)
        {
            var    a        = new Point2(line.Start.X + dx, line.Start.Y + dy);
            var    b        = new Point2(line.End.X + dx, line.End.Y + dy);
            var    target   = new Point2(v.X, v.Y);
            var    nearest  = target.NearestOnLine(a, b);
            double distance = target.DistanceTo(nearest);

            return(distance < threshold);
        }
コード例 #3
0
        void FillRelativeTo(ChangeTrackingTextBox txtBearing, ChangeTrackingTextBox txtDistance, Point2 relativePoint)
        {
            double angle = ManeuveringBoard.AngleBetween(relativePoint, posDataPoint.Value);

            txtBearing.Text = (angle * MathConst.RadiansToDegrees).ToString("0.##");
            txtBearing.Tag  = angle;
            double distance = relativePoint.DistanceTo(posDataPoint.Value);

            txtDistance.Text      = ManeuveringBoard.GetDistanceString(distance, unitSystem);
            txtDistance.Tag       = distance;
            txtBearing.WasChanged = txtDistance.WasChanged = false;
        }
コード例 #4
0
        public IBaseShape Contains(IBaseShape shape, Point2 target, double radius, IHitTest hitTest, Modifier modifier)
        {
            if (!(shape is LineShape line))
            {
                throw new ArgumentNullException("shape");
            }

            var    a        = new Point2(line.StartPoint.X, line.StartPoint.Y);
            var    b        = new Point2(line.Point.X, line.Point.Y);
            var    nearest  = target.NearestOnLine(a, b);
            double distance = target.DistanceTo(nearest);

            return(distance < radius ? shape : null);
        }
コード例 #5
0
ファイル: HitTestLine.cs プロジェクト: masums/Core2D
        public override bool Contains(IBaseShape shape, Point2 target, double radius, IDictionary <Type, HitTestBase> registered)
        {
            if (!(shape is ILineShape line))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var    a        = new Point2(line.Start.X, line.Start.Y);
            var    b        = new Point2(line.End.X, line.End.Y);
            var    nearest  = target.NearestOnLine(a, b);
            double distance = target.DistanceTo(nearest);

            return(distance < radius);
        }
コード例 #6
0
        public override BaseShape Contains(BaseShape shape, Point2 target, double radius, IHitTest hitTest)
        {
            var line = shape as LineShape;

            if (line == null)
            {
                throw new ArgumentNullException("shape");
            }

            var    a        = new Point2(line.StartPoint.X, line.StartPoint.Y);
            var    b        = new Point2(line.Point.X, line.Point.Y);
            var    nearest  = target.NearestOnLine(a, b);
            double distance = target.DistanceTo(nearest);

            return(distance < radius ? shape : null);
        }
コード例 #7
0
ファイル: WpfArc.cs プロジェクト: kamaloff/Core2D
        public WpfArc(Point2 p1, Point2 p2, Point2 p3, Point2 p4)
        {
            var    rect    = Rect2.FromPoints(p1, p2);
            var    center  = new Point2(rect.X + rect.Width / 2.0, rect.Y + rect.Height / 2.0);
            double offsetX = center.X - rect.X;
            double offsetY = center.Y - rect.Y;

            double minLenght = (double)Math.Max(offsetX, offsetY);

            double length1 = center.DistanceTo(p3);
            double p3x     = p3.X + (p3.X - center.X) / length1 * minLenght;
            double p3y     = p3.Y + (p3.Y - center.Y) / length1 * minLenght;

            double length2 = center.DistanceTo(p4);
            double p4x     = p4.X + (p4.X - center.X) / length2 * minLenght;
            double p4y     = p4.Y + (p4.Y - center.Y) / length2 * minLenght;

            IList <Point2> p3i;
            IList <Point2> p4i;

            Line2.LineIntersectsWithEllipse(center, new Point2(p3x, p3y), rect, true, out p3i);
            Line2.LineIntersectsWithEllipse(center, new Point2(p4x, p4y), rect, true, out p4i);
            Point2 start;
            Point2 end;

            if (p3i != null && p3i.Count == 1)
            {
                start = p3i.FirstOrDefault();
            }
            else
            {
                start = new Point2(p3x, p3y);
            }

            if (p4i != null && p4i.Count == 1)
            {
                end = p4i.FirstOrDefault();
            }
            else
            {
                end = new Point2(p4x, p4y);
            }

            double angle      = Line2.AngleBetween(center, start, center, end);
            bool   isLargeArc = angle > 180.0;

            double helperLenght = 60.0;

            double lengthStart = center.DistanceTo(start);
            double p3hx        = start.X + (start.X - center.X) / lengthStart * helperLenght;
            double p3hy        = start.Y + (start.Y - center.Y) / lengthStart * helperLenght;

            double lengthEnd = center.DistanceTo(end);
            double p4hx      = end.X + (end.X - center.X) / lengthEnd * helperLenght;
            double p4hy      = end.Y + (end.Y - center.Y) / lengthEnd * helperLenght;

            P1         = p1;
            P2         = p2;
            P3         = new Point2(p3hx, p3hy);
            P4         = new Point2(p4hx, p4hy);
            Rect       = rect;
            Center     = center;
            Start      = start;
            End        = end;
            Radius     = new Size2(offsetX, offsetY);
            IsLargeArc = isLargeArc;
            Angle      = angle;
        }
コード例 #8
0
            public bool Check( Point2 start, Point2 end, float startT, float endT, ref float collisionT, ref Vector2 collisionNormal )
            {
                Line2Intersection intersection = Intersections2.GetLinePlaneIntersection( start, end, m_Plane );
                if ( intersection == null )
                {
                    PlaneClassification edgeClass = m_Plane.ClassifyPoint( start, PlaneTolerance );
                    if ( edgeClass == PlaneClassification.On )
                    {
                        edgeClass = m_Plane.ClassifyPoint( end, PlaneTolerance );
                    }
                    if ( edgeClass == PlaneClassification.InFront )
                    {
                        return ( m_InFront != null ) && m_InFront.Check( start, end, startT, endT, ref collisionT, ref collisionNormal );
                    }
                    else if ( edgeClass == PlaneClassification.Behind )
                    {
                        return ( m_Behind == null ) || m_Behind.Check( start, end, startT, endT, ref collisionT, ref collisionNormal );
                    }

                    return false;
                }
                float intersectionT = startT + ( endT - startT ) * ( intersection.Distance / start.DistanceTo( end ) );
                collisionT = intersectionT;
                collisionNormal = m_Plane.Normal;
                if ( m_InFront != null )
                {
                    if ( m_InFront.Check( start, intersection.IntersectionPosition, startT, intersectionT, ref collisionT, ref collisionNormal ) )
                    {
                        return true;
                    }
                }
                if ( m_Behind != null )
                {
                    if ( m_Behind.Check( intersection.IntersectionPosition, end, intersectionT, endT, ref collisionT, ref collisionNormal ) )
                    {
                        return true;
                    }
                }
                else
                {
                    return true;
                }

                return false;
            }
コード例 #9
0
 /// <summary>
 /// Returns the distance from a point to a circle. If the point is within the
 /// circle, a negative distance is returned
 /// </summary>
 public static float DistancePointToCircle( Point2 pt, Point2 centre, float radius )
 {
     return pt.DistanceTo( centre ) - radius;
 }