aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorBob Blackmon <bob.blackmon@ymail.com>2017-04-03 18:06:13 -0400
committerGitHub <noreply@github.com>2017-04-03 18:06:13 -0400
commitbab64d993b693ccb3c8766371a3ce18b92010b11 (patch)
treecad891a4f844c1e4f0829f8b3aa463dc579f79b2 /lua
parent8bea4a86946aed6c84d5e2639bcb4be3fbc77104 (diff)
downloadzones-bab64d993b693ccb3c8766371a3ce18b92010b11.tar.gz
zones-bab64d993b693ccb3c8766371a3ce18b92010b11.tar.bz2
zones-bab64d993b693ccb3c8766371a3ce18b92010b11.zip
Improve raycasting algorithm
Removed a loop.
Diffstat (limited to 'lua')
-rw-r--r--lua/zones.lua44
1 files changed, 18 insertions, 26 deletions
diff --git a/lua/zones.lua b/lua/zones.lua
index 19fe643..56fa575 100644
--- a/lua/zones.lua
+++ b/lua/zones.lua
@@ -1,5 +1,5 @@
-local version = 1.131 -- Older versions will not run if a newer version is used in another script.
+local version = 1.14 -- Older versions will not run if a newer version is used in another script.
--[[
ZONES - by Bobbleheadbob
WARNING: If you edit any of these files, make them use a different namespace. Multiple scripts may depend on this library so modifying it can break other scripts.
@@ -467,38 +467,30 @@ local function Intersect(line1, line2)
end
function zones.PointInPoly(point,poly) //True if point is within a polygon.
- //Check validity
- local lines = {}
- local pcount = #poly
- for k1=1, pcount do
-
- local k2 = k1+1
- if k2 > pcount then
- k2 = 1
- end
-
- lines[k1] = {
- x1 = poly[k1].x,
- y1 = poly[k1].y,
- x2 = poly[k2].x,
- y2 = poly[k2].y,
- valid = true
- }
-
- end
-
local ray = {
x1 = point.x,
y1 = point.y,
- x2 = point.x + 10000,
- y2 = point.y + 10000
+ x2 = 100000,
+ y2 = 100000
}
local inside = false
- //Do ray check.
- for k,v in pairs(lines)do
+ //Perform ray test
+ for k1, v in pairs(poly) do
+
+ local v2 = poly[k1+1]
+ if not v2 then
+ v2 = poly[1]
+ end
+
+ local line = {
+ x1 = v.x,
+ y1 = v.y,
+ x2 = v2.x,
+ y2 = v2.y
+ }
- if Intersect(ray,v) then
+ if Intersect(ray,line) then
inside = !inside
end