Skip to content

Polygonal Puzzle - Wrong polygon intersection logic (but it works for the problem) #38

@ChrisVilches

Description

@ChrisVilches

I think the logic I implemented doesn't check for when a polygon is completely inside another polygon, and no edges are touching.

It seems the algorithm only works when edges or vertices are touching.

But it seems this works anyway, because the polygons are always touching in every check. It checks whether they are just touching, or one edge goes "inside" the other polygon, correctly. So it works.

What to do with this issue? Just close it? Or change method name? (that would require me changing the name in the Rust project as well, maybe).

UPDATE: This logic would be correct for this problem because this problem is trying to find the maximum perimeter overlapping (edges that match), so if the polygon is completely inside, the result would be zero anyway. For that reason, it's not necessary to check intersections when one polygon is completely contained inside the other.

However, there is another bug: When the polygons are the same (exact same sequence of points), the algorithm fails to detect an intersection. This seems like a worse issue than the above, since this actually could happen in the problem, but it seems it never happens anyway (in such a case, the answer will be the perimeter of the polygons, and the match would be complete)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions