mirror of https://github.com/CGAL/cgal
Don't use bbox with segment/linear/polyline traits
This commit is contained in:
parent
b9a08d76d6
commit
17bcc9696c
|
|
@ -62,7 +62,7 @@ void ArrangementDemoTabBase::setupUi( )
|
||||||
double wh = MAX_WIDTH;
|
double wh = MAX_WIDTH;
|
||||||
scene->setSceneRect(xymin, xymin, wh, wh);
|
scene->setSceneRect(xymin, xymin, wh, wh);
|
||||||
|
|
||||||
this->getView()->installEventFilter(this->navigation.get());
|
this->getView()->viewport()->installEventFilter(this->navigation.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsView* ArrangementDemoTabBase::getView() const
|
QGraphicsView* ArrangementDemoTabBase::getView() const
|
||||||
|
|
|
||||||
|
|
@ -93,5 +93,5 @@ if (CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND)
|
||||||
cgal_add_compilation_test(arrangement_2)
|
cgal_add_compilation_test(arrangement_2)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
message(STATUS "NOTICE: This demo requires CGAL, CGAL-Core and Qt5, and will not be compiled.")
|
message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@ struct ConstructBoundingBox_impl
|
||||||
|
|
||||||
// We currently avoid using bbox function in Arr_sgegment_2 because it creates
|
// We currently avoid using bbox function in Arr_sgegment_2 because it creates
|
||||||
// its own kernel object
|
// its own kernel object
|
||||||
// TODO: remove this class once it's fixed
|
// TODO: remove this class and the polyline one once it's fixed
|
||||||
|
// and use bbox directly
|
||||||
template <typename Kernel_>
|
template <typename Kernel_>
|
||||||
struct ConstructBoundingBox_impl<CGAL::Arr_segment_traits_2<Kernel_>>
|
struct ConstructBoundingBox_impl<CGAL::Arr_segment_traits_2<Kernel_>>
|
||||||
{
|
{
|
||||||
|
|
@ -49,12 +50,17 @@ struct ConstructBoundingBox_impl<CGAL::Arr_segment_traits_2<Kernel_>>
|
||||||
|
|
||||||
CGAL::Bbox_2
|
CGAL::Bbox_2
|
||||||
operator()(const X_monotone_curve_2& curve)
|
operator()(const X_monotone_curve_2& curve)
|
||||||
|
{
|
||||||
|
return this->operator()(curve.source(), curve.target());
|
||||||
|
}
|
||||||
|
|
||||||
|
CGAL::Bbox_2 operator()(const Point_2& p1, const Point_2& p2)
|
||||||
{
|
{
|
||||||
CGAL::Bbox_2 bbox;
|
CGAL::Bbox_2 bbox;
|
||||||
double x1 = CGAL::to_double(curve.source().x());
|
double x1 = CGAL::to_double(p1.x());
|
||||||
double y1 = CGAL::to_double(curve.source().y());
|
double y1 = CGAL::to_double(p1.y());
|
||||||
double x2 = CGAL::to_double(curve.target().x());
|
double x2 = CGAL::to_double(p2.x());
|
||||||
double y2 = CGAL::to_double(curve.target().y());
|
double y2 = CGAL::to_double(p2.y());
|
||||||
|
|
||||||
double min_x, max_x, min_y, max_y;
|
double min_x, max_x, min_y, max_y;
|
||||||
if (x1 < x2)
|
if (x1 < x2)
|
||||||
|
|
@ -89,14 +95,11 @@ struct ConstructBoundingBox_impl<CGAL::Arr_segment_traits_2<Kernel_>>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <
|
template <typename SegmentTraits_2_>
|
||||||
typename RatKernel_, typename AlgKernel_, typename NtTraits_,
|
struct ConstructBoundingBox_impl<CGAL::Arr_polyline_traits_2<SegmentTraits_2_>>
|
||||||
typename BoundingTraits_>
|
|
||||||
struct ConstructBoundingBox_impl<CGAL::Arr_Bezier_curve_traits_2<
|
|
||||||
RatKernel_, AlgKernel_, NtTraits_, BoundingTraits_>>
|
|
||||||
{
|
{
|
||||||
using Traits = typename CGAL::Arr_Bezier_curve_traits_2<
|
using Traits = CGAL::Arr_polyline_traits_2<SegmentTraits_2_>;
|
||||||
RatKernel_, AlgKernel_, NtTraits_, BoundingTraits_>;
|
using SegmentTraits_2 = SegmentTraits_2_;
|
||||||
using X_monotone_curve_2 = typename Traits::X_monotone_curve_2;
|
using X_monotone_curve_2 = typename Traits::X_monotone_curve_2;
|
||||||
using Curve_2 = typename Traits::Curve_2;
|
using Curve_2 = typename Traits::Curve_2;
|
||||||
using Point_2 = typename Traits::Point_2;
|
using Point_2 = typename Traits::Point_2;
|
||||||
|
|
@ -104,16 +107,54 @@ struct ConstructBoundingBox_impl<CGAL::Arr_Bezier_curve_traits_2<
|
||||||
CGAL::Bbox_2
|
CGAL::Bbox_2
|
||||||
operator()(const X_monotone_curve_2& curve)
|
operator()(const X_monotone_curve_2& curve)
|
||||||
{
|
{
|
||||||
// TODO: find a way to find bounding box of a X_monotone_curve of bezier
|
ConstructBoundingBox_impl<SegmentTraits_2> construct_bounding_box;
|
||||||
// arrangements
|
|
||||||
return curve.supporting_curve().bbox();
|
auto n = curve.number_of_subcurves();
|
||||||
|
CGAL::Bbox_2 bbox;
|
||||||
|
for (std::size_t i = 0; i < n; ++i)
|
||||||
|
bbox += construct_bounding_box(curve[i]);
|
||||||
|
|
||||||
|
return bbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
CGAL::Bbox_2 operator()(const Point_2& p1, const Point_2& p2)
|
||||||
|
{
|
||||||
|
CGAL::Bbox_2 bbox;
|
||||||
|
double x1 = CGAL::to_double(p1.x());
|
||||||
|
double y1 = CGAL::to_double(p1.y());
|
||||||
|
double x2 = CGAL::to_double(p2.x());
|
||||||
|
double y2 = CGAL::to_double(p2.y());
|
||||||
|
|
||||||
|
double min_x, max_x, min_y, max_y;
|
||||||
|
if (x1 < x2)
|
||||||
|
{
|
||||||
|
min_x = x1;
|
||||||
|
max_x = x2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
min_x = x2;
|
||||||
|
max_x = x1;
|
||||||
|
}
|
||||||
|
if (y1 < y2)
|
||||||
|
{
|
||||||
|
min_y = y1;
|
||||||
|
max_y = y2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
min_y = y2;
|
||||||
|
max_y = y1;
|
||||||
|
}
|
||||||
|
return {min_x, min_y, max_x, max_y};
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL::Bbox_2
|
CGAL::Bbox_2
|
||||||
operator()(const Point_2& point)
|
operator()(const Point_2& point)
|
||||||
{
|
{
|
||||||
std::pair<double, double> p = point.approximate();
|
double x = CGAL::to_double(point.x());
|
||||||
return {p.first, p.second, p.first, p.second};
|
double y = CGAL::to_double(point.y());
|
||||||
|
return {x, y, x, y};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -130,7 +171,8 @@ struct ConstructBoundingBox_impl<CGAL::Arr_linear_traits_2<Kernel_>>
|
||||||
{
|
{
|
||||||
if (curve.is_segment())
|
if (curve.is_segment())
|
||||||
{
|
{
|
||||||
return curve.bbox();
|
return ConstructBoundingBox_impl<CGAL::Arr_segment_traits_2<Kernel_>>{}(
|
||||||
|
curve.source(), curve.target());
|
||||||
}
|
}
|
||||||
else if (curve.is_line())
|
else if (curve.is_line())
|
||||||
{
|
{
|
||||||
|
|
@ -166,6 +208,35 @@ struct ConstructBoundingBox_impl<CGAL::Arr_linear_traits_2<Kernel_>>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <
|
||||||
|
typename RatKernel_, typename AlgKernel_, typename NtTraits_,
|
||||||
|
typename BoundingTraits_>
|
||||||
|
struct ConstructBoundingBox_impl<CGAL::Arr_Bezier_curve_traits_2<
|
||||||
|
RatKernel_, AlgKernel_, NtTraits_, BoundingTraits_>>
|
||||||
|
{
|
||||||
|
using Traits = typename CGAL::Arr_Bezier_curve_traits_2<
|
||||||
|
RatKernel_, AlgKernel_, NtTraits_, BoundingTraits_>;
|
||||||
|
using X_monotone_curve_2 = typename Traits::X_monotone_curve_2;
|
||||||
|
using Curve_2 = typename Traits::Curve_2;
|
||||||
|
using Point_2 = typename Traits::Point_2;
|
||||||
|
|
||||||
|
CGAL::Bbox_2
|
||||||
|
operator()(const X_monotone_curve_2& curve)
|
||||||
|
{
|
||||||
|
// TODO: find a way to find bounding box of a X_monotone_curve of bezier
|
||||||
|
// arrangements
|
||||||
|
return curve.supporting_curve().bbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
CGAL::Bbox_2
|
||||||
|
operator()(const Point_2& point)
|
||||||
|
{
|
||||||
|
std::pair<double, double> p = point.approximate();
|
||||||
|
return {p.first, p.second, p.first, p.second};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <typename AlgebraicKernel_d_1>
|
template <typename AlgebraicKernel_d_1>
|
||||||
struct ConstructBoundingBox_impl<
|
struct ConstructBoundingBox_impl<
|
||||||
CGAL::Arr_rational_function_traits_2<AlgebraicKernel_d_1>>
|
CGAL::Arr_rational_function_traits_2<AlgebraicKernel_d_1>>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue