Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disappearing region #26

Open
LiorKovalio opened this issue Feb 7, 2023 · 0 comments
Open

Disappearing region #26

LiorKovalio opened this issue Feb 7, 2023 · 0 comments

Comments

@LiorKovalio
Copy link

I think there is an issue with the finishing step, namely the finish_edges function.
The following code shows a missing edge (P3/P1) which is removed in finish_edges. Diving in, it seems like an issue with _get_intersection_point.

from foronoi import Voronoi, Polygon

good = [(262, 90), (188, 204), (521, 360), (541, 329), (501, 154)]
bad =   [(262, 90), (188, 204), (521, 360), (541, 329), (500, 154)]  # last site differs by (1, 0) from the above
polygon = Polygon([(0, 720), (1280, 720), (1280, 0), (0, 0)])
v_good = Voronoi(polygon)
v_good.create_diagram(points=good)
v_bad = Voronoi(polygon)
v_bad.create_diagram(points=bad)

Here are the diagrams (bad to the left, good to the right)
image

I've tried and changed the _get_intersection_point into:

    def _get_intersection_point(self, orig, end):
        p = self.points + [self.points[0]]
        points = []

        point = None

        for i in range(0, len(p) - 1):
            intersection_point = Algebra.get_intersection(orig, end, p[i], p[i + 1])
            if intersection_point:
                points.append(intersection_point)

        if len(points) == 0:
            point = None
        elif len(points) == 1:  # this is the actual change
            point = points[0]
        else:
            max_distance = Algebra.distance(orig, end)

            # Find the intersection point that is furthest away from the start
            if points:
                distances = [Algebra.distance(orig, p) for p in points]
                distances = [i for i in distances if i <= max_distance]
                if distances:
                    point = points[np.argmax(distances)]

        return point

This change solves the above case, without breaking any tests.
@Yatoom Could you please take a look? Thanks for the lib btw!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant