Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit ae02b74

Browse files
committed
fix(zones): correct contains check
1 parent b97469e commit ae02b74

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

imports/zones/shared.lua

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local glm = require 'glm'
1313
---@field __type 'poly' | 'sphere' | 'box'
1414
---@field remove fun(self: self)
1515
---@field setDebug fun(self: CZone, enable?: boolean, colour?: vector)
16-
---@field contains fun(self: CZone, coords?: vector3): boolean
16+
---@field contains fun(self: CZone, coords?: vector3, updateDistance?: boolean): boolean
1717

1818
---@type table<number, CZone>
1919
local Zones = {}
@@ -132,7 +132,7 @@ CreateThread(function()
132132
local zone = nearbyZones[i]
133133

134134
if zone.insideZone then
135-
local contains = zone.thickness and glm_polygon_contains(zone.polygon, coords, zone.thickness / 4) or #(zone.coords - coords) < zone.radius
135+
local contains = zone:contains(coords, true)
136136

137137
if not contains then
138138
zone.insideZone = false
@@ -148,14 +148,7 @@ CreateThread(function()
148148

149149
for i = 1, #zones do
150150
local zone = zones[i]
151-
local radius, contains = zone.radius, nil
152-
zone.distance = #(zone.coords - coords)
153-
154-
if radius then
155-
contains = zone.distance < radius
156-
else
157-
contains = glm_polygon_contains(zone.polygon, coords, zone.thickness / 4)
158-
end
151+
local contains = zone:contains(coords, true)
159152

160153
if contains then
161154
if not zone.insideZone then
@@ -273,8 +266,12 @@ local function contains(self, coords)
273266
return glm_polygon_contains(self.polygon, coords, self.thickness / 4)
274267
end
275268

276-
local function insideSphere(self, coords)
277-
return #(self.coords - coords) < self.radius
269+
local function insideSphere(self, coords, updateDistance)
270+
local distance = #(self.coords - coords) < self.radius
271+
272+
if updateDistance then self.distance = distance end
273+
274+
return distance
278275
end
279276

280277
local function convertToVector(coords)

0 commit comments

Comments
 (0)