Test intersection vertices for whether they are inside a limited angle for field of vision #6255
Labels
lighting/fog
Issues related to dynamic lighting or fog of war
tech-debt
Issues focused on the reduction of technical debt
Milestone
Originally in GitLab by @caewok
Environment Details
Issue Description
I spotted a potential bug in
ClockwiseSweepPolygon.prototype._identifyIntersections
: This method adds vertices at overlapping wall intersections, but if the vertex is new,_identifyIntersections
does not check set a value for_inLimitedAngle
for that vertex. In the very next step after_inLimitedAngle
, the parent method_identifyVertices
deletes any vertices that do not have_inLimitedAngle
set to true. As a result, the newly added vertex will be immediately removed. (In the case of a limited angle field of vision.)This does not usually present as a bug, because in at least most instances,
_identifyIntersections
adds an intersection vertex that already exists in the set of vertices and thus will already have_inLimitedAngle
set previously. I would not assume this to always be the case, however, as intersections are a bit fickle and, due to floating point errors, can be slightly off their exact location. So it may be possible to have a new keyed vertex at an intersection point not previously seen.I found this potential bug because I am adding temporary walls to
ClockwiseSweepPolygon.
In this case, any overlapping intersection with the temporary wall will not have been previously processed, and so the vertex at the overlap is definitely new. I can confirm that this results inClockwiseSweepPolygon
removing the vertex at the overlap intersection, causing field-of-vision to display incorrectly. I would expect the same behavior if, as I said above, the overlapping intersection is not in the existing set of vertices.Proposed solution
A fairly simple check can avoid this potential issue in
_identifyIntersections
:For your reference, here is what the full method would look like:
The text was updated successfully, but these errors were encountered: