예제 #1
0
        /// <summary>
        /// the distance of the point from the outline of the shape, if the value is negative it is inside the polygon bounds
        /// </summary>
        /// <param name="point">The point.</param>
        /// <returns>
        /// Returns the distance from the shape to the point
        /// </returns>
        public float Distance(Vector2 point)
        {
            bool      insidePoly;
            PointInfo result = this.Distance(point, true, out insidePoly);

            // invert the distance from path when inside
            return(insidePoly ? -result.DistanceFromPath : result.DistanceFromPath);
        }
예제 #2
0
        /// <inheritdoc />
        public PointInfo Distance(PointF point)
        {
            PointInfo dist     = this.innerPath.DistanceFromPath(point);
            bool      isInside = this.innerPath.PointInPolygon(point);

            if (isInside)
            {
                dist.DistanceFromPath *= -1;
            }

            return(dist);
        }
예제 #3
0
        /// <inheritdoc/>
        public override PointInfo GetPointInfo(int x, int y)
        {
            Vector2 point = new Vector2(x, y);

            SixLabors.Shapes.PointInfo dist = this.Path.Distance(point);

            return(new PointInfo
            {
                DistanceAlongPath = dist.DistanceAlongPath,
                DistanceFromPath =
                    dist.DistanceFromPath < 0
                                   ? -dist.DistanceFromPath
                                   : dist.DistanceFromPath
            });
        }
예제 #4
0
        /// <inheritdoc/>
        public override PointInfo GetPointInfo(int x, int y)
        {
            Vector2 point             = new Vector2(x, y);
            float   distanceFromPath  = float.MaxValue;
            float   distanceAlongPath = 0;

            // ReSharper disable once ForCanBeConvertedToForeach
            for (int i = 0; i < this.Paths.Length; i++)
            {
                SixLabors.Shapes.PointInfo p = this.Paths[i].Distance(point);
                if (p.DistanceFromPath < distanceFromPath)
                {
                    distanceFromPath  = p.DistanceFromPath;
                    distanceAlongPath = p.DistanceAlongPath;
                }
            }

            return(new PointInfo
            {
                DistanceAlongPath = distanceAlongPath,
                DistanceFromPath = distanceFromPath
            });
        }