use dispatch_or_drop_output to replace Object

This commit is contained in:
Sébastien Loriot 2023-06-21 11:20:31 +02:00
parent 7d0dd109b3
commit f65aa68bd2
5 changed files with 24 additions and 69 deletions

View File

@ -3,6 +3,7 @@
*/
#include <CGAL/config.h>
#include <CGAL/iterator.h>
#ifndef CGAL_USE_CORE
#include <iostream>
@ -108,22 +109,13 @@ bool read_bezier(char const* aFileName, Bezier_polygon_set& rSet)
for (unsigned int k = 0; k < n_curves; ++k) {
// Read the current curve and subdivide it into x-monotone subcurves.
std::list<CGAL::Object> x_objs;
std::list<CGAL::Object>::const_iterator xoit;
Bezier_X_monotone_curve xcv;
Bezier_traits traits;
Bezier_traits::Make_x_monotone_2 make_x_monotone =
traits.make_x_monotone_2_object();
Bezier_curve B = read_bezier_curve(in_file, lDoubleFormat);
if (B.number_of_control_points() >= 2) {
make_x_monotone(B, std::back_inserter(x_objs));
for (xoit = x_objs.begin(); xoit != x_objs.end(); ++xoit) {
if (CGAL::assign(xcv, *xoit))
xcvs.push_back(xcv);
}
make_x_monotone(B, CGAL::dispatch_or_drop_output<Bezier_X_monotone_curve>(std::back_inserter(xcvs)));
}
}

View File

@ -6,6 +6,7 @@
#include <CGAL/Gps_circle_segment_traits_2.h>
#include <CGAL/General_polygon_set_2.h>
#include <CGAL/Lazy_exact_nt.h>
#include <CGAL/iterator.h>
#include <list>
#include <cassert>
@ -24,22 +25,15 @@ typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2;
// Construct a polygon from a circle.
Polygon_2 construct_polygon (const Circle_2& circle)
{
// Subdivide the circle into two x-monotone arcs.
// Subdivide the circle into two x-monotone arcs and construct the polygon.
Traits_2 traits;
Curve_2 curve (circle);
std::list<CGAL::Object> objects;
traits.make_x_monotone_2_object() (curve, std::back_inserter(objects));
assert(objects.size() == 2);
// Construct the polygon.
Polygon_2 pgn;
X_monotone_curve_2 arc;
std::list<CGAL::Object>::iterator iter;
for (iter = objects.begin(); iter != objects.end(); ++iter) {
CGAL::assign (arc, *iter);
pgn.push_back (arc);
}
traits.make_x_monotone_2_object() (curve,
CGAL::dispatch_or_drop_output<X_monotone_curve_2>(std::back_inserter(pgn)));
std::cout << "size: " << pgn.size() << "\n";
assert(pgn.size() == 2);
return pgn;
}

View File

@ -3,6 +3,7 @@
*/
#include <CGAL/config.h>
#include <CGAL/iterator.h>
#ifndef CGAL_USE_CORE
#include <iostream>
@ -42,14 +43,8 @@ typedef Traits_2::Point_2 Point_2;
// sub-arcs and append these sub-arcs as polygon edges.
void append_conic_arc(Polygon_2& polygon, const Curve_2& arc) {
Conic_traits_2 traits;
std::list<CGAL::Object> objects;
X_monotone_curve_2 xarc;
traits.make_x_monotone_2_object() (arc, std::back_inserter(objects));
for (auto it = objects.begin(); it != objects.end(); ++it) {
if (CGAL::assign (xarc, *it))
polygon.push_back (xarc);
}
traits.make_x_monotone_2_object() (arc,
CGAL::dispatch_or_drop_output<X_monotone_curve_2>(std::back_inserter(polygon)));
}
int main() {

View File

@ -25,22 +25,14 @@ typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2;
// Construct a polygon from a circle.
Polygon_2 construct_polygon (const Circle_2& circle)
{
// Subdivide the circle into two x-monotone arcs.
// Subdivide the circle into two x-monotone arcs and construct the polygon
Traits_2 traits;
Curve_2 curve (circle);
std::list<CGAL::Object> objects;
traits.make_x_monotone_2_object() (curve, std::back_inserter(objects));
assert(objects.size() == 2);
// Construct the polygon.
Polygon_2 pgn;
X_monotone_curve_2 arc;
std::list<CGAL::Object>::iterator iter;
for (iter = objects.begin(); iter != objects.end(); ++iter) {
CGAL::assign (arc, *iter);
pgn.push_back (arc);
}
traits.make_x_monotone_2_object() (curve,
CGAL::dispatch_or_drop_output<X_monotone_curve_2>(std::back_inserter(pgn)));
assert(pgn.size() == 2);
return pgn;
}

View File

@ -25,6 +25,7 @@
#include <CGAL/Gps_circle_segment_traits_2.h>
#include <CGAL/General_polygon_set_2.h>
#include <CGAL/squared_distance_2.h>
#include <CGAL/iterator.h>
namespace CGAL {
@ -97,29 +98,19 @@ public:
typename Traits_2::Make_x_monotone_2 make_x_monotone =
traits.make_x_monotone_2_object();
typename Dxf_circles_list::iterator circ_it;
CGAL::Object obj_vec[3];
CGAL::Object *obj_begin = (obj_vec + 0);
CGAL::Object *obj_end;
X_monotone_curve_2 cv1, cv2;
for (circ_it = circles.begin(); circ_it != circles.end(); ++circ_it)
{
// Break the circle into two x-monotone circular arcs.
const Dxf_circle_2& dxf_circ = *circ_it;
Curve_2 circ (dxf_circ.first, dxf_circ.second);
obj_end = make_x_monotone (circ, obj_begin);
CGAL_assertion(obj_end - obj_begin == 2);
CGAL::assign(cv1, obj_vec[0]);
CGAL::assign(cv2, obj_vec[1]);
// Generate the corresponding polygon.
Circ_polygon_2 pgn;
pgn.push_back (cv1);
pgn.push_back (cv2);
*pgns = pgn;
++pgns;
make_x_monotone (circ,
CGAL::dispatch_or_drop_output<X_monotone_curve_2>(std::back_inserter(pgn)));
CGAL_assertion(pgn.size() == 2);
*pgns++ = pgn;
}
circles.clear();
@ -131,8 +122,6 @@ public:
typename Dxf_polygon_2::iterator curr, next;
Point_2 ps, pt;
Circle_2 supp_circ;
std::size_t n_subarcs;
std::size_t i;
for (pgn_it = polygons.begin(); pgn_it != polygons.end(); ++pgn_it)
{
@ -184,15 +173,8 @@ public:
// Break the arc into x-monotone subarcs (there can be at most
// three subarcs) and add them to the polygon.
obj_end = make_x_monotone (circ_arc, obj_begin);
n_subarcs = (obj_end - obj_begin);
CGAL_assertion (n_subarcs <= 3);
for (i = 0; i < n_subarcs; i++)
{
if (CGAL::assign (cv1, obj_vec[i]))
pgn.push_back (cv1);
}
make_x_monotone (circ_arc,
CGAL::dispatch_or_drop_output<X_monotone_curve_2>(std::back_inserter(pgn)));
}
else
{