/// <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); }
/// <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); }
/// <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 }); }
/// <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 }); }