Skip to content

Commit d18ac7d

Browse files
committed
Lots of optimizations, module collapsing, added missing Gauss and LUT Luau files
1 parent c970606 commit d18ac7d

File tree

11 files changed

+433
-501
lines changed

11 files changed

+433
-501
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

22
TweenDemo.rbxl.lock
33
TweenDemo.rbxl
4+
Demo.rbxl.lock

Demo.rbxl

-632 Bytes
Binary file not shown.

src/CurveInterpolator.luau

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ local Root = script
55
local InternalTypes = require(Root.Core.InternalTypes)
66

77
-- Core Modules
8-
local Math = require(Root.Core.Math)
98
local Utils = require(Root.Core.Utils)
109

1110
-- Spline Modules
@@ -111,7 +110,7 @@ do
111110
if time == 0 then
112111
return points[1]
113112
elseif time == 1 then
114-
return (self.Closed and points[1] or points[#points])
113+
return (self.Closed and points[1] or points[self.PointCount])
115114
end
116115

117116
-- Finally, find our point by solving our axis-values
@@ -164,8 +163,9 @@ do
164163
type CurvatureDetails = {
165164
Curvature: number;
166165
Radius: number;
166+
167+
Normal: InternalTypes.Point;
167168
Tangent: InternalTypes.Point;
168-
Direction: InternalTypes.Point;
169169
}
170170
function GetCurvatureAtTime(
171171
self: CurveInterpolatorInternal,
@@ -175,25 +175,21 @@ do
175175

176176
local derivative = self:ProcessAxisCoefficientsAtTime(SplineSegment.GetDerivativeAtTime, time)
177177
local secondDerivative = self:ProcessAxisCoefficientsAtTime(SplineSegment.GetSecondDerivativeAtTime, time)
178-
179-
local tangent = derivative.Unit
180-
local curvature = 0
181-
182178
local derivativeLength = derivative.Magnitude
183179
local derivativeCross = derivative:Cross(secondDerivative)
184-
local direction = derivativeCross:Cross(derivative).Unit
185-
186-
if derivativeLength > 0 then
187-
curvature = (derivativeCross.Magnitude / (derivativeLength ^ 3))
188-
end
189-
190-
local radius = ((curvature > 0) and (1 / curvature) or 0)
191180

181+
local curvature = (
182+
if derivativeLength > 0 then
183+
(derivativeCross.Magnitude / (derivativeLength ^ 3))
184+
else
185+
0
186+
)
192187
return {
193188
Curvature = curvature;
194-
Radius = radius;
195-
Tangent = tangent;
196-
Direction = direction;
189+
Radius = ((curvature > 0) and (1 / curvature) or 0);
190+
191+
Normal = derivativeCross:Cross(derivative).Unit;
192+
Tangent = derivative.Unit;
197193
}
198194
end
199195

@@ -222,10 +218,10 @@ do
222218
): ClosestDetails
223219
-- Default our threshold and samples
224220
local threshold = (threshold or DefaultSearchThreshold)
225-
local samples = (samples or ((#self.Points - 1) * 10))
221+
local samples = (samples or ((self.PointCount - 1) * 10))
226222

227223
-- Verify our threshold
228-
if (threshold <= 0) or (Math.IsFinite(threshold) == false) then
224+
if (threshold <= 0) then
229225
error(`Invalid Threshold ({threshold}) for GetClosestProgressToPoint`)
230226
end
231227

@@ -251,7 +247,7 @@ do
251247
-- Grab our closest time
252248
local closestTime = self:GetTimeFromProgress(closestProgress)
253249

254-
-- Handle bisecting our curve to narrow down our closest-progress
250+
-- Handle bisecting our curve to narrow down our closest-time
255251
local closestPoint = GetPointAtTime(self, closestTime)
256252
local function Bisect(time: number): boolean
257253
if (time >= 0) and (time <= 1) then
@@ -273,12 +269,9 @@ do
273269
end
274270
end
275271

276-
-- Now update our progress
277-
closestProgress = self:GetProgressFromTime(closestTime)
278-
279272
-- Finally, return everything we've gotten
280273
return {
281-
Progress = closestProgress;
274+
Progress = self:GetProgressFromTime(closestTime);
282275
Time = closestTime;
283276

284277
Point = closestPoint;
@@ -297,15 +290,16 @@ do
297290

298291
-- Go through and find all our time-intersections
299292
local timeIntersections = {}
300-
local pointCount = (self.Closed and (#self.Points + 1) or #self.Points)
293+
local pointCount = (self.Closed and (self.PointCount + 1) or self.PointCount)
301294
for segmentIndex = 1, (pointCount - 1) do
302295
-- Determine our main parameters for our segment
303-
local controlPoints = SplineCurve.GetControlPoints(segmentIndex, self.Points, self.Closed)
304-
local controlExtremeA, controlExtremeB = controlPoints[2][axis], controlPoints[3][axis]
305-
local coefficients = self:CalculateCoefficientsPerAxisForSegment(segmentIndex)[axis]
296+
local _, controlExtremeA, controlExtremeB = SplineCurve.GetControlPoints(segmentIndex, self.Points, self.Closed)
297+
local controlExtremeA, controlExtremeB = controlExtremeA[axis], controlExtremeB[axis]
298+
local coefficients = self.SegmentCoefficientsPerAxis[segmentIndex][axis]
306299

307300
-- Determine the minimum/maximum value for our axis
308-
local axisMinimum, axisMaximum = math.min(controlExtremeA, controlExtremeB), math.max(controlExtremeA, controlExtremeB)
301+
local axisMinimum = math.min(controlExtremeA, controlExtremeB)
302+
local axisMaximum = math.max(controlExtremeA, controlExtremeB)
309303

310304
-- Now see if our value we want to intersect falls into our segment range
311305
if ((valueToIntersect + margin) >= axisMinimum) and ((valueToIntersect - margin) <= axisMaximum) then
@@ -358,7 +352,7 @@ do
358352
end
359353

360354
-- State Management Functions
361-
function InvalidateCache(self: CurveInterpolatorInternal)
355+
function OnCacheUpdate(self: CurveInterpolatorInternal)
362356
self.CachedLookupTables = {}
363357
end
364358

@@ -440,9 +434,7 @@ function Interface.new(points: InternalTypes.Points, options: Options?): CurveIn
440434
Points = points;
441435
Closed = closed;
442436

443-
OnCacheInvalidation = function()
444-
InvalidateCache(curveInterpolator)
445-
end;
437+
OnCacheUpdate = OnCacheUpdate;
446438
}
447439
curveInterpolator = (
448440
if (options ~= nil) and (options.ArcDivisions ~= nil) then

src/CurveInterpolator/Core/Math.luau

Lines changed: 0 additions & 136 deletions
This file was deleted.

0 commit comments

Comments
 (0)