BezierCurve:insertControlPoint() indexing last doesn't work properly

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Krunklehorn
Prole
Posts: 8
Joined: Sat May 11, 2019 3:46 am

BezierCurve:insertControlPoint() indexing last doesn't work properly

Post by Krunklehorn »

From the wiki...
BezierCurve:insertControlPoint
Insert control point as the new i-th control point. Existing control points from i onwards are pushed back by 1. Indices start with 1. Negative indices wrap around: -1 is the last control point, -2 the one before the last, etc.
If I'm reading this correctly, the following code...

Code: Select all

-- a simple curve with four points in a counter-clockwise motion
-- default index is -1 (last), but was included for clarity
curve:insertControlPoint(0, 0, -1)	-- bottom left
curve:insertControlPoint(100, 0, -1)	-- bottom right
curve:insertControlPoint(100, -100, -1)	-- top right
curve:insertControlPoint(0, -100, -1)	-- top left

print(curve:getControlPoint(1))
print(curve:getControlPoint(2))
print(curve:getControlPoint(3))
print(curve:getControlPoint(4))
...should yield the following result.

Code: Select all

0	0
100	0
100	100
0	100
Since each point is supposed to be inserted at the last index, we expect the points to be in order as shown.
Here's what happens instead...

Code: Select all

100	0	-- (2nd)
100	100	-- (3rd)
0	100	-- (4th)
0	0	-- (1st)
Attempting to insert a point at the last index (-1) actually inserts it at the second last index.
Okay, so we think to try inserting at index 0 maybe?
Unfortunately that doesn't work....

Code: Select all

0	100	-- (4th)
100	100	-- (3rd)
100	0	-- (2nd)
0	0	-- (1st)
This gets treated as if you were inserting at index 1, which keeps your points in line but reverses their order since you're constantly pushing the whole list forward.

Additionally: the wiki's description, "points from i onwards are pushed back by 1" should actually say that the points are pushed forward, at least that's the intended result, right?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 143 guests