// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
namespace SixLabors.PolygonClipper {
///
/// Represents a stroke-processing vertex with a cached outgoing segment length.
///
///
/// This is an internal mutable value used by while
/// normalizing source contours and computing joins/caps.
///
internal struct StrokeVertexDistance
{
private const double VertexDistanceEpsilon = 1E-14D;
private const double Dd = 1D / VertexDistanceEpsilon;
///
/// The X-coordinate.
///
public double X;
///
/// The Y-coordinate.
///
public double Y;
///
/// Cached distance to another vertex measured by .
///
public double Distance;
///
/// Initializes a new instance of the struct.
///
/// The X-coordinate.
/// The Y-coordinate.
/// Initial cached distance value.
public StrokeVertexDistance(double x, double y, double distance)
{
this.X = x;
this.Y = y;
this.Distance = distance;
}
///
/// Measures the Euclidean distance from this vertex to and stores it in .
///
/// The vertex to measure to.
///
/// when the measured distance is greater than the internal epsilon;
/// otherwise .
///
///
/// When points are closer than epsilon, is set to a large sentinel value
/// to avoid divide-by-near-zero behavior in downstream stroker math.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Measure(in StrokeVertexDistance vd)
{
bool ret = (this.Distance = Vertex.Distance(new Vertex(this.X, this.Y), new Vertex(vd.X, vd.Y))) > VertexDistanceEpsilon;
if (!ret)
{
this.Distance = Dd;
}
return ret;
}
}
}