Afforess / Factorio-Stdlib

Factorio Standard Library Project
ISC License
165 stars 49 forks source link

Area.to_xxx_area(entity) returns incorrect for rectangle bounding boxes in non N/S rotation #90

Closed Nexela closed 7 years ago

Nexela commented 7 years ago

image

Could also be in Position.add but don't have the time to look so making an issue as a reminder

This should return about -0.75

Nexela commented 7 years ago

Offset is only incorrect if width is > height

Nexela commented 7 years ago

Narrowed it down, Current solution, but not sure how much I like it.

--- Converts an entity and its selection_box to the area around it
-- @tparam LuaEntity entity to convert to an area
-- @treturn LuaBoundingBox
function Area.to_selection_area(entity)
    fail_if_missing(entity, "missing entity argument")

    local pos = entity.position
    local bb = entity.prototype.selection_box

    if entity.direction ~= defines.direction.north then
        return Area.rotate(Area.offset(bb, pos))
    end
    return Area.offset(bb, pos)
end
Afforess commented 7 years ago

Okay - I think I understand the issue here. The prototype definition is returning the generic bounding box, which apparently is defined for the N-S placement of the entity. Other directions result in the area being rotated 90 degrees, so that's what your check is doing. My only question is: Does the game ever return the direction as south (S-N orientation) and if so, then that should also be checked in your if statement, as N-S and S-N are isomorphic and should not result in rotation.

Nexela commented 7 years ago

Will be adjusting this some more tonight.

Nexela commented 7 years ago

Ok finally had to time check some 8 way rotations. will have the final fix pushed shortly :)