JanetRossini.github.io

Lua, LSL, Blender, Python in Second Life


Project maintained by JanetRossini

Remembering Where You Were

May 21, 2025 • [designluaobjectstesting]


I’d like to give my Bezier thing a bit of memory.

Given some confidence that we only need a few intervals to get a decent path, let’s remember the position and length of the curve at those points. We’ll use them for nefarious purposes later.

I’ll start by storing little tables and perhaps grow into something more expressive later.

Let’s try a test.

function Tests:test_check_memory()
    local p0 = vector(400, 400, 0)
    local p1 = vector(500, 500, 0)
    local p2 = vector(600, 500, 0)
    local p3 = vector(700, 400, 0)
    local b = Bezier(p0, p1, p2, p3)
    b:compute_way_points(8)
    for i = 0, 8 do
        j = i + 1
        frac = i/8
        pos = b:at(frac)
        self:assert_equals(b.way_points[j].pos, pos, `j={j}`)
    end
end

I think that compute_way_points is going to look a lot like compute-length. Mostly I picked a new name because I don’t want to put the way-point code into compute_length, even though I do think we’ll have some convergence to do soon. Here’s what I got:

function Bezier:compute_way_points(intervals)
    local wp0 = {len=0, pos=self:at(0)}
    local wps = {wp0}
    local v0 = self.p0
    local total = 0
    local v1
    local t
    local max = intervals
    for i = 1,max do
        t = i/max
        v1 = self:at(t)
        d = vector.magnitude(v1 - v0)
        total = total + d
        local wp = {len=total, pos=v1}
        table.insert(wps, wp)
        v0 = v1
    end
    self.way_points = wps
end

That passes the test. My mistakes included trying at{self.p0) instead of the correct at:0) and then some thrashing about when I didn’t recognize what the error was.

I do not have a test for the lengths and I’m not exactly sure how to do so, unless I were to write separate code to compute them. Anyway, I think it’s fine.

I don’t like that method, 18 lines long like that. I’ve logged out of Aditi now, but I think we’ll want something better, although I do think we’ll have no more than one occurrence of this loop in the final Bezier class.

Anyway, mission accomplished, the compute_way_points(n) method computes n+1 cells containing length so far and the point at that length, starting at t=0 and ending at t=1, as intended.

That’s all for now. Safe paths!