Narrow positions and bounding boxes at the boundary

Values read back from the game always use the named members, so they
are narrowed once where they enter a function rather than at each use.

`LuaControl.force` is a ForceID union, so reading a force only method
off it needs the cast the rest of the repo already uses.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-07 15:31:43 +00:00
co-authored by Claude Opus 5
parent 3f46055b70
commit a4213dadf5
3 changed files with 27 additions and 18 deletions
+6 -5
View File
@@ -15,11 +15,11 @@ local abs = math.abs
local commands = {}
--- @param player LuaPlayer
--- @param area BoundingBox
--- @param area ExpUtil_AABB.Box
--- @return boolean
local function location_break(player, area)
local surface = player.surface -- Allow remote view
local is_charted = player.force.is_chunk_charted
local is_charted = (player.force --[[@as LuaForce]]).is_chunk_charted
if is_charted(surface, { x = floor(area.left_top.x / 32), y = floor(area.left_top.y / 32) }) then
return true
elseif is_charted(surface, { x = floor(area.left_top.x / 32), y = floor(area.right_bottom.y / 32) }) then
@@ -63,13 +63,14 @@ SelectArea:on_selection(function(event)
}
local count = 0
local hits = {} --- @type MapPosition[]
local hits = {} --- @type MapPosition.struct[]
for _, entity in ipairs(entities) do
local skip = false
local entity_position = entity.position --[[@as MapPosition.struct]]
for _, pos in ipairs(hits) do
local x = abs(entity.position.x - pos.x)
local y = abs(entity.position.y - pos.y)
local x = abs(entity_position.x - pos.x)
local y = abs(entity_position.y - pos.y)
if x * x + y * y < 36 then
skip = true
break