difference() produces invalid (self-intersecting) result for valid polygon-with-hole input

Đang mở
#1,490 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

  • #1491 của @tinko92 — đã đóng, không merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
computer-graphics

Hướng nghiên cứu

Bắt đầu với testing.cpp đính kèm và tái hiện trường hợp này với Boost 1.91.0, tập trung vào bg::difference() khi lỗ của đa giác A chạm vào biên của đa giác B. Sử dụng bg::is_valid() và self-intersection được báo cáo tại (5, 15) để theo dõi kết quả; hoàn tất khi difference() trả về một hình học hợp lệ loại trừ B.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Version of Boost

1.91.0

Actual and Expected Behavior

Actual: boost::geometry::difference() on two valid multi_polygon operands (a polygon with a hole, minus another polygon) returns a result that fails boost::geometry::is_valid() — it contains a self-intersection introduced at the point where the hole's ring touches the subtracted polygon's boundary.

I discovered this by seeing that a point, that is in A \ B, is reported as also being within B, which violates the basic definition of set difference.

Expected: boost::geometry::difference() should return a valid geometry (satisfying is_valid()) for valid input operands.

Minimal complete program: attached testing.cpp

#include <boost/geometry.hpp>
#include <cassert>
#include <iostream>

namespace bg = boost::geometry;

using int_point_t = bg::model::point<int64_t, 2, bg::cs::cartesian>;
using int_poly_t = bg::model::polygon<int_point_t>;
using int_multi_poly_t = bg::model::multi_polygon<int_poly_t>;

int main()
{
   int_multi_poly_t poly_A;
   boost::geometry::read_wkt("MULTIPOLYGON(((0 0,20 0,20 20,0 20,0 0),(5 15,14 14,9 6,5 15)))", poly_A);

   int_multi_poly_t poly_B;
   boost::geometry::read_wkt("MULTIPOLYGON(((5 15,5 5,15 5,15 15,5 15)))", poly_B);

   bg::correct(poly_A);
   bg::correct(poly_B);

   assert(bg::is_valid(poly_A));
   assert(bg::is_valid(poly_B));

   int_multi_poly_t result;
   boost::geometry::difference(poly_A, poly_B, result);

   std::cout << boost::geometry::to_wkt(result) << std::endl;
   if (std::string message; !bg::is_valid(result, message))
      std::cerr << "Invalid geometry: " << message << std::endl;

}

Output when run:

MULTIPOLYGON(((0 0,0 20,20 20,20 0,0 0),(5 15,9 6,14 14,5 15),(5 15,5 5,15 5,15 15,5 15)))
Invalid geometry: Geometry has invalid self-intersections. A self-intersection point was found at (5, 15); method: t; operations: u/i; segment IDs {source, multi, ring, segment}: {0, 0, 0, 2}/{0, 0, 1, 3}

Pictures of input:
Image Image

Picture of output:
Image

Steps necessary to reproduce the problem
  1. Build the attached testing.cpp against Boost 1.91.0.
  2. Run it.
  3. Observe that bg::is_valid(result, message) reports false with a self-intersection at the point where polygon A's hole ring touches polygon B's boundary.

Both input polygons (poly_A, poly_B) are individually valid (confirmed via is_valid() before the difference() call in the program), so the invalidity is introduced by difference() itself.

All relevant compiler information
  • Compiler: GCC 14 (g++-14.3.0)
  • Standard: C++23 (-std=gnu++23)
  • OS: Linux
Ngôn ngữ chính
C++
Star
519
Fork
241
Merge trung bình
4 ngày 15 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của boostorg/geometry

Tất cả issue của boostorg/geometry

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.