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

Arrangement merge_edge assigns incorrect direction #8659

Open
Yvee1 opened this issue Dec 14, 2024 · 6 comments
Open

Arrangement merge_edge assigns incorrect direction #8659

Yvee1 opened this issue Dec 14, 2024 · 6 comments

Comments

@Yvee1
Copy link

Yvee1 commented Dec 14, 2024

Issue Details

The arrangement modification function merge_edge may invalidate the arrangement. In particular, the merged edge may have incorrect direction (that is, the direction returned by direction() does not match the actual edge direction).

Source Code

This is a minimal example with two straight edges that are merged into one with an incorrect direction.

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/Arr_segment_traits_2.h>

int main() {
    using K = CGAL::Epeck;
    using Traits = CGAL::Arr_segment_traits_2<K>;
    using Arrangement = CGAL::Arrangement_2<Traits>;
    Arrangement arr;
    K::Segment_2 seg1({0, 1}, {1, 0});
    K::Segment_2 seg2({0.1, -1}, {1, 0});
    CGAL::insert(arr, seg1);
    auto eh = CGAL::insert_non_intersecting_curve(arr, seg2);
    if (eh->source()->point() != seg2.source()) {
        eh = eh->twin();
    }

    std::cout << arr.is_valid() << std::endl;
    K::Segment_2 seg3(seg2.source(), seg1.source());
    auto ehn = eh->next();
    std::cout << eh->source()->point() << " -> " << eh->target()->point() << " " << eh->direction() << std::endl;
    std::cout << ehn->source()->point() << " -> " << ehn->target()->point() << " " << ehn->direction()<< std::endl;
    auto merged = arr.merge_edge(eh, eh->next(), seg3);
    std::cout << merged->source()->point() << " -> " << merged->target()->point() << " " << merged->direction() << std::endl;
    std::cout << arr.is_valid() << std::endl;
    return 0;
}

Environment

  • CGAL version: 5.6
@efifogel
Copy link
Member

efifogel commented Dec 14, 2024 via email

@Yvee1
Copy link
Author

Yvee1 commented Dec 14, 2024

Thanks for the quick reply. Is there a reason why merge_edge is not provided for halfedges with different direction? I don't immediately see an issue with such a function, but I presume there is some complication that prohibits such a more general function?

@efifogel
Copy link
Member

efifogel commented Dec 15, 2024 via email

@Yvee1
Copy link
Author

Yvee1 commented Dec 16, 2024

I think it would be useful to have a merge_edge() method that works on halfedges of different direction too. For example, when simplifying an arrangement, it's natural to want to merge edges to reduce the complexity of the arrangement, and then the x-direction of the halfedges that you merge will not necessarily be the same. It seems most natural to me to let merge_edge provide this functionality as well. I'm not familiar with all the bookkeeping that the arrangement does internally, but to me it seem the only addition needed to make this work for halfedges of different direction is to compare the x-coordinates of the endpoints of the new edge, and then set its direction accordingly. This relatively expensive geometric comparison need only be performed after the 'same-direction check' fails. If the problem is that the one 'same-direction' check may be superfluous in case it is already known that the edges have the same direction then passing it as an argument seems most sensible to me (more than creating a new function entirely to avoid this one operation).

@efifogel
Copy link
Member

efifogel commented Dec 16, 2024 via email

@Yvee1
Copy link
Author

Yvee1 commented Dec 16, 2024

Makes sense, thank you for the explanation!

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

2 participants