Fixed drawing with a bounding box

This commit is contained in:
Efi Fogel 2025-09-17 10:14:07 +03:00
parent 556e6b9993
commit 0879232f8e
1 changed files with 21 additions and 17 deletions

View File

@ -1582,24 +1582,25 @@ public:
{ {
using Approx_pnt = Approximate_point_2; using Approx_pnt = Approximate_point_2;
using Approx_seg = Approximate_kernel::Segment_2; using Approx_seg = Approximate_kernel::Segment_2;
using Approx_ray = Approximate_kernel::Ray_2;
using Approx_lin = Approximate_kernel::Line_2;
auto xmin = bbox.xmin(); auto xmin = bbox.xmin();
auto ymin = bbox.ymin(); auto ymin = bbox.ymin();
auto xmax = bbox.xmax(); auto xmax = bbox.xmax();
auto ymax = bbox.ymax(); auto ymax = bbox.ymax();
Approximate_kernel::Iso_rectangle_2 rect(xmin, ymin, xmax, ymax); Approximate_kernel::Iso_rectangle_2 rect(xmin, ymin, xmax, ymax);
auto xs = CGAL::to_double(xcv.source().x());
auto ys = CGAL::to_double(xcv.source().y());
auto xt = CGAL::to_double(xcv.target().x());
auto yt = CGAL::to_double(xcv.target().y());
if (xcv.is_ray()) { if (xcv.is_ray()) {
using Approx_ray = Approximate_kernel::Ray_2; auto ray = xcv.ray();
Approx_ray ray(Approx_pnt(xs, ys), Approx_pnt(xt, yt)); Kernel kernel;
const auto result = CGAL::intersection(rect, ray); auto construct_vertex = kernel.construct_point_on_2_object();
Approx_pnt s = this->operator()(construct_vertex(ray, 0));
Approx_pnt t = this->operator()(construct_vertex(ray, 1));
const auto result = CGAL::intersection(rect, Approx_ray(s, t));
if (! result) return oi; if (! result) return oi;
if (const auto* res_seg = std::get_if<Approx_seg>(&*result)) { if (const auto* res_seg = std::get_if<Approx_seg>(&*result)) {
*oi++ = res_seg->source(); *oi++ = l2r ? res_seg->min() : res_seg->max();
*oi++ = res_seg->target(); *oi++ = l2r ? res_seg->max() : res_seg->min();
return oi; return oi;
} }
const auto* res_pnt = std::get_if<Approx_pnt>(&*result); const auto* res_pnt = std::get_if<Approx_pnt>(&*result);
@ -1608,14 +1609,17 @@ public:
return oi; return oi;
} }
if (xcv.is_line()) { if (xcv.is_line()) {
using Approx_lin = Approximate_kernel::Line_2; const Line_2 & supp_line = xcv.supp_line();
Approx_lin line(Approx_pnt(xs, ys), Approx_pnt(xt, yt)); Approx_lin approx_supp_line(
const auto result = CGAL::intersection(rect, line); CGAL::to_double(supp_line.a()),
CGAL::to_double(supp_line.b()),
CGAL::to_double(supp_line.c()));
const auto result = CGAL::intersection(rect, approx_supp_line);
if (! result) return oi; if (! result) return oi;
if (const auto* res_seg = std::get_if<Approx_seg>(&*result)) { if (const auto* res_seg = std::get_if<Approx_seg>(&*result)) {
*oi++ = res_seg->source(); *oi++ = l2r ? res_seg->min() : res_seg->max();
*oi++ = res_seg->target(); *oi++ = l2r ? res_seg->max() : res_seg->min();
return oi; return oi;
} }
const auto* res_pnt = std::get_if<Approx_pnt>(&*result); const auto* res_pnt = std::get_if<Approx_pnt>(&*result);
@ -1623,13 +1627,13 @@ public:
*oi++ = *res_pnt; *oi++ = *res_pnt;
return oi; return oi;
} }
Approx_seg seg(Approx_pnt(xs, ys), Approx_pnt(xt, yt)); Approx_seg seg(this->operator()(xcv.source()), this->operator()(xcv.target()));
const auto result = CGAL::intersection(rect, seg); const auto result = CGAL::intersection(rect, seg);
if (! result) return oi; if (! result) return oi;
if (const auto* res_seg = std::get_if<Approx_seg>(&*result)) { if (const auto* res_seg = std::get_if<Approx_seg>(&*result)) {
*oi++ = res_seg->source(); *oi++ = l2r ? res_seg->min() : res_seg->max();
*oi++ = res_seg->target(); *oi++ = l2r ? res_seg->max() : res_seg->min();
return oi; return oi;
} }
const auto* res_pnt = std::get_if<Approx_pnt>(&*result); const auto* res_pnt = std::get_if<Approx_pnt>(&*result);