Skip to content

Commit 0679ff5

Browse files
committed
Made two Epsilons, one for Cubic-Roots (which needs to be super small) and one for Intersections (doesn't need to be as small)
Fixes intersections barely over 1 by > e-42 being in the range of practically the same number
1 parent 823c44d commit 0679ff5

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

Demo.rbxl

31 Bytes
Binary file not shown.

src/Path/Spline/SplineSegment.lua

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ local Utils = require(Root.Core.Utils)
1111
local Interface = {}
1212

1313
-- Math Functions
14-
local Epsilon = (2 ^ -42)
1514
do
15+
local Epsilon = (2 ^ -42)
16+
1617
function SumOfSquares(a: Vector3, b: Vector3): number
1718
return (
1819
((a.X - b.X) ^ 2)
@@ -159,22 +160,22 @@ local function CalculateAxisCoefficients(
159160
if ((knot1 - knot2) ~= 0) and ((knot1 - knot3) ~= 0) then
160161
u = (
161162
baseMultiplier
162-
* (
163-
((value1 - value2) / (knot1 - knot2))
164-
- ((value1 - value3) / (knot1 - knot3))
165-
+ ((value2 - value3) / (knot2 - knot3))
166-
)
163+
* (
164+
((value1 - value2) / (knot1 - knot2))
165+
- ((value1 - value3) / (knot1 - knot3))
166+
+ ((value2 - value3) / (knot2 - knot3))
167+
)
167168
)
168169
end
169170

170171
if ((knot2 - knot4) ~= 0) and ((knot3 - knot4) ~= 0) then
171172
v = (
172173
baseMultiplier
173-
* (
174-
((value2 - value3) / (knot2 - knot3))
175-
- ((value2 - value4) / (knot2 - knot4))
176-
+ ((value3 - value4) / (knot3 - knot4))
177-
)
174+
* (
175+
((value2 - value3) / (knot2 - knot3))
176+
- ((value2 - value4) / (knot2 - knot4))
177+
+ ((value3 - value4) / (knot3 - knot4))
178+
)
178179
)
179180
end
180181
end
@@ -195,8 +196,8 @@ local function CalculateCoefficientsPerAxis(
195196
-- Determine our sequence to calculate our coefficients
196197
local knotSequence = (
197198
(softness > 0)
198-
and CalculateKnotSequence(point1, point2, point3, point4, softness)
199-
or nil
199+
and CalculateKnotSequence(point1, point2, point3, point4, softness)
200+
or nil
200201
)
201202
return {
202203
X = CalculateAxisCoefficients(
@@ -231,11 +232,12 @@ end
231232
local function GetSecondDerivativeAtTime(time: number, coefficients: Coefficients): number
232233
return (
233234
(6 * coefficients[1] * time)
234-
+ (2 * coefficients[2])
235+
+ (2 * coefficients[2])
235236
)
236237
end
237238

238239
-- Solves the cubic spline for our intersection-value to get our progress-points (the roots of the spline)
240+
local IntersectionEpsilon = (2 ^ -20)
239241
local function FindSegmentTimeIntersectionsOnAxis(valueToIntersect: number, axisCoefficients: Coefficients): {number}
240242
-- Extract our coefficients
241243
local degree3, degree2 = axisCoefficients[1], axisCoefficients[2]
@@ -250,7 +252,7 @@ local function FindSegmentTimeIntersectionsOnAxis(valueToIntersect: number, axis
250252
-- Finally, return all the progress-values where we intersect our provided value
251253
local validRoots = {}
252254
for _, root in ipairs(GetCubicRoots(degree3, degree2, degree1, deltaConstant)) do
253-
if (root > -Epsilon) and (root <= (1 + Epsilon)) then
255+
if (root > -IntersectionEpsilon) and (root <= (1 + IntersectionEpsilon)) then
254256
table.insert(validRoots, math.clamp(root, 0, 1))
255257
end
256258
end

0 commit comments

Comments
 (0)