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

Segment_2 has_on returns unexpected results #8346

Closed
barulicm opened this issue Jul 9, 2024 · 2 comments
Closed

Segment_2 has_on returns unexpected results #8346

barulicm opened this issue Jul 9, 2024 · 2 comments

Comments

@barulicm
Copy link

barulicm commented Jul 9, 2024

Issue Details

Segment_2::has_on can return the wrong answer given segments that are slightly off axis. In some cases, the order of the segment points changes the answer given.

We are getting the points passed to has_on from a projection to the segment's supporting line. The order of the segment points does not appear to change the projected point.

Source Code

#include <iostream>
#include <CGAL/Simple_cartesian.h>

using Kernel = CGAL::Simple_cartesian<double>;
using Point = Kernel::Point_2;
using Segment = Kernel::Segment_2;

int main() {
  Point p{-3.0, 1.0};

  Segment s{
    Point{0.0, 0.0},
    Point{-7.0, 1e-4}
  };
  // Expected true, actually returns true
  std::cout << s.has_on(s.supporting_line().projection(p)) << "\n";

  Segment s2{
    Point{-7.0, 1e-4},
    Point{0.0, 0.0}
  };
  // Expected true, actually returns false
  std::cout << s2.has_on(s2.supporting_line().projection(p)) << "\n";

  Point p2{-1.0, 1.0};

  Segment s3{
    Point{-2.0, 1e-4},
    Point{0.0, 0.0}
  };
  // Expected true, actually returns false
  std::cout << s3.has_on(s3.supporting_line().projection(p2)) << "\n";

  Segment s4{
    Point{0.0, 0.0},
    Point{-2.0, 1e-4}
  };
  // Expected true, actually returns false
  std::cout << s4.has_on(s4.supporting_line().projection(p2)) << "\n";

  return 0;
}

Environment

  • Operating system: Ubuntu 22.04
  • Compiler: g++
  • Release or debug mode: happens in both Debug and Release
  • Specific flags used (if any): n/a
  • CGAL version: 5.4 (git hash: c58ac97)
  • Boost version: 1.74
  • Other libraries versions if used (Eigen, TBB, etc.): n/a
@sloriot
Copy link
Member

sloriot commented Jul 9, 2024

Replacing using Kernel = CGAL::Simple_cartesian<double>; by using Kernel = CGAL::Exact_predicates_exact_constructions_kernel; should fix the wrong results.

See all this FAQ entry

@barulicm
Copy link
Author

Thanks for the info!

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

No branches or pull requests

4 participants