JanetRossini.github.io

Lua, LSL, Blender, Python in Second Life


Project maintained by JanetRossini

Converging

Aug 28, 2025 • [designlinkagesluatesting]


Today I propose to remove the MainRod and GeneralMainRod classes, replacing them with the NewMainRod. Probably not interesting.

It would suffice to delete them and their tests, but I think it’ll be better to make the NewMainRod pass all the other classes’ tests, or know the reason why it shouldn’t do so. I guess at the end, I’ll wire it into my SVG code and make sure it looks right.

One thing I believe we’ll encounter is that some of the code is wired to assume that a zero-angle main rod should extend toward the rear of the locomotive. The NewMainRod treats a zero angle as forward, extending in the positive direction in X. We’ll just tweak as needed.

I believe that today’s exercise will not be very interesting. I hope I haven’t cursed myself by thinking that.

Huh. Cursed right out of the box. The MainRod tests are set not to run. When I turn them on, we get failures. The minimal right thing to do is to figure out why, although it is tempting to plug in the new thing and see what happens. But no, we want valid tests. Here’s the first failure:

Feature: original main rod
pos <7.041960108450192, 1, 0>
Actual: table[y]=1, Expected: 1.5. 
Test: '270'.
Actual: table[y]=2.7071067811865475, Expected: 2.5. 

The setup is:

local wheel
local main_rod
_:setup(function()
    wheel = DriveWheel{x=10, y=2}
    main_rod = MainRod{parent=wheel, length=6, radius=1}
end)

Seems clear to me that the y should be 1/2 below 2.

After some inspection, I see that the MainRod is left in a weird state, because I was trying to modify it to use my new scheme, before I decided to do the NewMainKRod from scratch. Let’s assume that the tests are good and just plug in the new main rod. I comment out the old MainRod class.

I have to implement drive_position, which the tests and other code want. The tests are failing badly.

_:test("initial position", function()
    _:expect(main_rod:position()).is(vector(8, 2))
    _:expect(main_rod:drive_point()).is(vector(5,2))
end)

That test says this:

Actual: table[y]=0, Expected: 2. Test: 'initial position'.
Actual: table[x]=0, Expected: 8. Test: 'initial position'.
Actual: table[y]=0, Expected: 2. Test: 'initial position'.
Actual: table[x]=0, Expected: 5. Test: 'initial position'.

I think we need a calculate in the init. Add that. New failure:

Actual: table[x]=14, Expected: 8. 
Test: 'initial position'.
Actual: table[x]=17, Expected: 5. 
Test: 'initial position'.

I suspect the program is right and the test wrong. Draw the picture. The drive position at zero is 17,2, the center position of the rod is 14,2. Test is wrong, old assumptions,, I think.

After more hand calculation than I’d like, the new main rod is passing the old main rod’s tests. They are actually very redundant with my original tests, except that they check the position of the main rod, not its end points. Made for a lot more number fiddling.

I’m bored with this, for now. Going to take a break, find something to read.

This is tedious. I think it needs to be done, as a double check on my math and code. But tedious.

Later …

OK, now I get to do the GeneralMainRod. I made a couple of tests run just for drill, but they duplicate others so removed them all. There is one ignored test, what was it?

_:ignore("story test", function()
    local wheel = DriveWheel{x=10, y=2}
    local main_rod = MainRod{parent=wheel, length=6, radius=1}
    local piston_rod = PistonRod{
        parent=main_rod, position=vector(6,2), length=4}
    wheel:move(0)
    main_rod:calculate()
    _:expect(main_rod:position(),"main").is(vector(8,2))
    _:expect(main_rod:drive_point(),"drive").is(vector(5,2))
    piston_rod:calculate()
    _:expect(piston_rod:position(),"piston").is(vector(3,2))
end)

Convert that to use NewMainRod, see what happens. Needs to accommodate the new convention.

Serious Mistake

I find, in the story test, that I have a serious mistake in the new object: it is not correctly setting the start position: it not getting properly rotated in the final answer.

I fix that and after adjusting hand calculations my story test works. I learn that I would like to have tables understand the error value in is in my tests. Will think on that.

I think we are good. Saving everything.

Safe paths!