Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
2fd14e1b
Commit
2fd14e1b
authored
10 years ago
by
SmallJoker
Committed by
Kahrl
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add Lua helper functions vector.apply(v) math.sign(x, tolerance)
parent
0e78aa29
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
builtin/common/misc_helpers.lua
+11
-0
11 additions, 0 deletions
builtin/common/misc_helpers.lua
builtin/common/vector.lua
+8
-0
8 additions, 0 deletions
builtin/common/vector.lua
doc/lua_api.txt
+4
-0
4 additions, 0 deletions
doc/lua_api.txt
with
23 additions
and
0 deletions
builtin/common/misc_helpers.lua
+
11
−
0
View file @
2fd14e1b
...
...
@@ -212,6 +212,17 @@ function math.hypot(x, y)
return
x
*
math.sqrt
(
1
+
t
*
t
)
end
--------------------------------------------------------------------------------
function
math
.
sign
(
x
,
tolerance
)
tolerance
=
tolerance
or
0
if
x
>
tolerance
then
return
1
elseif
x
<
-
tolerance
then
return
-
1
end
return
0
end
--------------------------------------------------------------------------------
function
get_last_folder
(
text
,
count
)
local
parts
=
text
:
split
(
DIR_DELIM
)
...
...
This diff is collapsed.
Click to expand it.
builtin/common/vector.lua
+
8
−
0
View file @
2fd14e1b
...
...
@@ -39,6 +39,14 @@ function vector.round(v)
}
end
function
vector
.
apply
(
v
,
func
)
return
{
x
=
func
(
v
.
x
),
y
=
func
(
v
.
y
),
z
=
func
(
v
.
z
)
}
end
function
vector
.
distance
(
a
,
b
)
local
x
=
a
.
x
-
b
.
x
local
y
=
a
.
y
-
b
.
y
...
...
This diff is collapsed.
Click to expand it.
doc/lua_api.txt
+
4
−
0
View file @
2fd14e1b
...
...
@@ -1280,6 +1280,7 @@ vector.distance(p1, p2) -> number
vector.length(v) -> number
vector.normalize(v) -> vector
vector.round(v) -> vector
vector.apply(v, func) -> vector
vector.equals(v1, v2) -> bool
For the following functions x can be either a vector or a number.
vector.add(v, x) -> vector
...
...
@@ -1296,6 +1297,9 @@ dump(obj, dumped={})
math.hypot(x, y)
^ Get the hypotenuse of a triangle with legs x and y.
Useful for distance calculation.
math.sign(x, tolerance)
^ Get the sign of a number
Optional: Also returns 0 when the absolute value is within the tolerance (default 0)
string:split(separator)
^ e.g. string:split("a,b", ",") == {"a","b"}
string:trim()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment