mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 20:35:17 +03:00
Fix setting x values < 0 for custom curves (fixes #6026)
Also accept bool for smooth parameter as the documentation suggest
This commit is contained in:
parent
e916c6dc9a
commit
c99dc375e8
1 changed files with 12 additions and 7 deletions
|
@ -860,9 +860,9 @@ Set Curve parameters
|
||||||
@param curve (unsigned number) curve number (use 0 for Curve1)
|
@param curve (unsigned number) curve number (use 0 for Curve1)
|
||||||
|
|
||||||
@param params see model.getCurve return format for table format. setCurve uses standard
|
@param params see model.getCurve return format for table format. setCurve uses standard
|
||||||
lua array indexing and array start at index 1
|
lua array indexing and arrays start at index 1
|
||||||
|
|
||||||
The first and last x value must 0 and 100 and x values must be monotonically increasing
|
The first and last x value must -100 and 100 and x values must be monotonically increasing
|
||||||
|
|
||||||
@retval 0 - Everything okay
|
@retval 0 - Everything okay
|
||||||
1 - Wrong number of points
|
1 - Wrong number of points
|
||||||
|
@ -879,15 +879,15 @@ The first and last x value must 0 and 100 and x values must be monotonically inc
|
||||||
Example setting a 4-point custom curve:
|
Example setting a 4-point custom curve:
|
||||||
```lua
|
```lua
|
||||||
params = {}
|
params = {}
|
||||||
params["x"] = {0, 34, 77, 100}
|
params["x"] = {-100, -34, 77, 100}
|
||||||
params["y"] = {-70, 20, -89, -100}
|
params["y"] = {-70, 20, -89, -100}
|
||||||
params["smooth"] = 1
|
params["smooth"] = true
|
||||||
params["type"] = 1
|
params["type"] = 1
|
||||||
val = model.setCurve(2, params)
|
val = model.setCurve(2, params)
|
||||||
```
|
```
|
||||||
setting a 6-point standard smoothed curve
|
setting a 6-point standard smoothed curve
|
||||||
```lua
|
```lua
|
||||||
val = model.setCurve(3, {smooth=1, y={-100, -50, 0, 50, 100, 80}})
|
val = model.setCurve(3, {smooth=true, y={-100, -50, 0, 50, 100, 80}})
|
||||||
```
|
```
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -923,6 +923,11 @@ static int luaModelSetCurve(lua_State *L)
|
||||||
newCurveData.type = luaL_checkinteger(L, -1);
|
newCurveData.type = luaL_checkinteger(L, -1);
|
||||||
}
|
}
|
||||||
else if (!strcmp(key, "smooth")) {
|
else if (!strcmp(key, "smooth")) {
|
||||||
|
// Earlier version of this api expected a 0/1 integer instead of a boolean
|
||||||
|
// Still accept a 0/1 here
|
||||||
|
if (lua_isboolean(L,-1))
|
||||||
|
newCurveData.smooth = lua_toboolean(L, -1);
|
||||||
|
else
|
||||||
newCurveData.smooth = luaL_checkinteger(L, -1);
|
newCurveData.smooth = luaL_checkinteger(L, -1);
|
||||||
}
|
}
|
||||||
else if (!strcmp(key, "x") || !strcmp(key, "y")) {
|
else if (!strcmp(key, "x") || !strcmp(key, "y")) {
|
||||||
|
@ -972,7 +977,7 @@ static int luaModelSetCurve(lua_State *L)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check first and last point
|
// Check first and last point
|
||||||
if (xPoints[0] != 0 || xPoints[newCurveData.points + 4] != 100) {
|
if (xPoints[0] != -100 || xPoints[newCurveData.points + 4] != 100) {
|
||||||
lua_pushinteger(L, 5);
|
lua_pushinteger(L, 5);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue