mirror of
https://github.com/love2d/love.git
synced 2026-08-12 00:20:52 +02:00
universal indexing rules in BezierCurve
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ LOVE 0.9.2 [Baby Inspector]
|
||||
* Added love.window.toPixels and love.window.fromPixels.
|
||||
* Added love.window.setPosition and love.window.getPosition, and 'x' and 'y' fields to love.window.setMode and t.window in love.conf.
|
||||
* Added love.filesystem.isSymlink, love.filesystem.setSymlinksEnabled, and love.filesystem.areSymlinksEnabled.
|
||||
* Added BezierCurve:renderSegment.
|
||||
* Added BezierCurve:renderSegment and BexierCurve:removePoint.
|
||||
|
||||
* Deprecated SpriteBatch:bind and SpriteBatch:unbind.
|
||||
* Deprecated all uses of the name 'FSAA' in favor of 'MSAA'.
|
||||
|
||||
@@ -124,15 +124,15 @@ void BezierCurve::setControlPoint(int i, const Vector &point)
|
||||
controlPoints[i] = point;
|
||||
}
|
||||
|
||||
void BezierCurve::insertControlPoint(const Vector &point, int pos)
|
||||
void BezierCurve::insertControlPoint(const Vector &point, int i)
|
||||
{
|
||||
if (pos < 0)
|
||||
pos += controlPoints.size() + 1;
|
||||
while (i < 0)
|
||||
i += controlPoints.size() + 1;
|
||||
|
||||
if (pos < 0 || (size_t) pos > controlPoints.size())
|
||||
while ((size_t) i > controlPoints.size())
|
||||
throw Exception("Invalid control point index");
|
||||
|
||||
controlPoints.insert(controlPoints.begin() + pos, point);
|
||||
controlPoints.insert(controlPoints.begin() + i, point);
|
||||
}
|
||||
|
||||
void BezierCurve::removeControlPoint(int i)
|
||||
|
||||
@@ -54,7 +54,8 @@ int w_BezierCurve_getControlPoint(lua_State *L)
|
||||
BezierCurve *curve = luax_checkbeziercurve(L, 1);
|
||||
int idx = luaL_checkinteger(L, 2);
|
||||
|
||||
idx--; // 1-indexing
|
||||
if (idx > 0) // 1-indexing
|
||||
idx--;
|
||||
|
||||
luax_catchexcept(L, [&]() {
|
||||
Vector v = curve->getControlPoint(idx);
|
||||
@@ -72,7 +73,8 @@ int w_BezierCurve_setControlPoint(lua_State *L)
|
||||
float vx = (float) luaL_checknumber(L, 3);
|
||||
float vy = (float) luaL_checknumber(L, 4);
|
||||
|
||||
idx--; // 1-indexing
|
||||
if (idx > 0) // 1-indexing
|
||||
idx--;
|
||||
|
||||
luax_catchexcept(L, [&](){ curve->setControlPoint(idx, Vector(vx,vy)); });
|
||||
return 0;
|
||||
@@ -97,7 +99,8 @@ int w_BezierCurve_removeControlPoint(lua_State *L)
|
||||
BezierCurve *curve = luax_checkbeziercurve(L, 1);
|
||||
int idx = luaL_checkint(L, 2);
|
||||
|
||||
idx--; // 1-indexing
|
||||
if (idx > 0) // 1-indexing
|
||||
idx--;
|
||||
|
||||
luax_catchexcept(L, [&](){ curve->removeControlPoint(idx); });
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user