CultMath: site cells (power and multiplicative scores, fold, border), Gabriel margin and gate, out-free distance_to_segment
Not yet verified on Yggdrasil; this commit builds only if the next run says so. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f697e03f4e
commit
a3c3bd9695
6 changed files with 515 additions and 7 deletions
|
|
@ -317,18 +317,39 @@ public static partial class math
|
|||
}
|
||||
|
||||
public static float distance_to_segment(float2 point, float2 start, float2 end, out float2 closest)
|
||||
{
|
||||
closest = segment_closest(point, start, end);
|
||||
return distance(point, closest);
|
||||
}
|
||||
|
||||
/// <summary>The distance from <paramref name="point"/> to the segment <paramref name="start"/>-<paramref name="end"/>; a degenerate segment is its start.</summary>
|
||||
public static float distance_to_segment(float2 point, float2 start, float2 end) =>
|
||||
distance(point, segment_closest(point, start, end));
|
||||
|
||||
/// <summary>The distance from <paramref name="point"/> to the segment <paramref name="start"/>-<paramref name="end"/>; a degenerate segment is its start.</summary>
|
||||
public static float distance_to_segment(float3 point, float3 start, float3 end) =>
|
||||
distance(point, segment_closest(point, start, end));
|
||||
|
||||
private static float2 segment_closest(float2 point_value, float2 start, float2 end)
|
||||
{
|
||||
var segment = end - start;
|
||||
var segmentLengthSq = lengthsq(segment);
|
||||
if (segmentLengthSq <= 0.0f)
|
||||
{
|
||||
closest = start;
|
||||
return distance(point, start);
|
||||
}
|
||||
return start;
|
||||
|
||||
var t = saturate(dot(point - start, segment) / segmentLengthSq);
|
||||
closest = start + segment * t;
|
||||
return distance(point, closest);
|
||||
var t = saturate(dot(point_value - start, segment) / segmentLengthSq);
|
||||
return start + segment * t;
|
||||
}
|
||||
|
||||
private static float3 segment_closest(float3 point_value, float3 start, float3 end)
|
||||
{
|
||||
var segment = end - start;
|
||||
var segmentLengthSq = lengthsq(segment);
|
||||
if (segmentLengthSq <= 0.0f)
|
||||
return start;
|
||||
|
||||
var t = saturate(dot(point_value - start, segment) / segmentLengthSq);
|
||||
return start + segment * t;
|
||||
}
|
||||
|
||||
public static float catmullrom(float p0, float p1, float p2, float p3, float t)
|
||||
|
|
|
|||
Loading…
Reference in a new issue