mirror of https://github.com/CGAL/cgal
Add free functions join() and intersection() for any combination of P, MP, MPwH
This commit is contained in:
parent
b24f19cecb
commit
78c8b4480e
|
|
@ -30,7 +30,7 @@ namespace CGAL {
|
|||
The class `Polygon_with_holes_2` models the concept `GeneralPolygonWithHoles_2`.
|
||||
It represents a linear polygon with holes. It is parameterized with two
|
||||
types (`Kernel` and `Container`) that are used to instantiate
|
||||
the type `Polygon_2<Kernel,Container>`. This poygon type is used to
|
||||
the type `Polygon_2<Kernel,Container>`. This polygon type is used to
|
||||
represent the outer boundary and the boundary of the holes (if any exist).
|
||||
|
||||
\cgalModels{GeneralPolygonWithHoles_2}
|
||||
|
|
@ -42,7 +42,7 @@ class Polygon_with_holes_2 :
|
|||
public General_polygon_with_holes_2<CGAL::Polygon_2<Kernel, Containter> >
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Kernel Traits;
|
||||
typedef CGAL::Polygon_2<Kernel, Containter> Polygon_2;
|
||||
typedef General_polygon_with_holes_2<Polygon_2> Base;
|
||||
typedef typename Base::Hole_const_iterator Hole_const_iterator;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
using K = CGAL::Exact_predicates_inexact_constructions_kernel;
|
||||
|
||||
using Point_2 = K::Point_2;
|
||||
using Polygon_2 = CGAL::Polygon_2<K>;
|
||||
using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2<K>;
|
||||
using Multipolygon_with_holes_2 = CGAL::Multipolygon_with_holes_2<K>;
|
||||
|
||||
|
|
@ -45,6 +47,14 @@ main(int argc, char* argv[])
|
|||
CGAL::draw(mpwh);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
Polygon_2 pB;
|
||||
pB.push_back(Point_2(-1,-1));
|
||||
pB.push_back(Point_2(1,-1));
|
||||
pB.push_back(Point_2(1,1));
|
||||
pB.push_back(Point_2(-1,1));
|
||||
mpwh = CGAL::Polygon_repair::join(pA,pB);
|
||||
CGAL::draw(mpwh);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,6 +135,22 @@ default constructor.
|
|||
/*!
|
||||
sets the polygons as input of the %Boolean operation.
|
||||
*/
|
||||
void
|
||||
insert(const Polygon_2& pA)
|
||||
{
|
||||
cdt.insert_constraint(pA.vertices_begin(), pA.vertices_end(), true);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
insert(const Polygon_with_holes_2& pwh)
|
||||
{
|
||||
cdt.insert_constraint(pwh.outer_boundary().vertices_begin(), pwh.outer_boundary().vertices_end(), true);
|
||||
for(auto const& hole : pwh.holes()){
|
||||
cdt.insert_constraint(hole.vertices_begin(), hole.vertices_end(), true);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
insert(const Multipolygon_with_holes_2& pA)
|
||||
{
|
||||
|
|
@ -144,10 +160,7 @@ sets the polygons as input of the %Boolean operation.
|
|||
cdt.insert_constraint(hole.vertices_begin(), hole.vertices_end(), true);
|
||||
}
|
||||
}
|
||||
|
||||
mark_domains();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void
|
||||
|
|
@ -181,7 +194,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
// this marks how many multipolygon interiors overlap a cell of the arrangement of mutipolygons
|
||||
void
|
||||
mark_domains()
|
||||
|
|
@ -217,7 +230,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
template <typename Fct>
|
||||
void
|
||||
label_domain(Face_handle start, int label, const Fct& fct)
|
||||
|
|
@ -378,26 +391,45 @@ template <typename K>
|
|||
Multipolygon_with_holes_2<K>
|
||||
join(const Multipolygon_with_holes_2<K>& pA)
|
||||
{
|
||||
CGAL::Polygon_repair::Boolean<K> bops;
|
||||
bops.insert(pA);
|
||||
struct Larger_than_zero {
|
||||
bool operator()(int i) const
|
||||
{
|
||||
return i > 0;
|
||||
}
|
||||
};
|
||||
|
||||
CGAL::Polygon_repair::Boolean<K> bops;
|
||||
bops.insert(pA);
|
||||
bops.mark_domains();
|
||||
Larger_than_zero ltz;
|
||||
return bops(ltz);
|
||||
}
|
||||
|
||||
template <typename PA, typename PB, typename K = Default>
|
||||
decltype(auto) // Multipolygon_with_holes_2<K>
|
||||
join(const PA& pA, const PB& pB, const K& k = Default())
|
||||
{
|
||||
typedef typename Default::Get<K, typename PA::Traits>::type Traits;
|
||||
|
||||
struct Larger_than_zero {
|
||||
bool operator()(int i) const
|
||||
{
|
||||
return i > 0;
|
||||
}
|
||||
};
|
||||
|
||||
CGAL::Polygon_repair::Boolean<Traits> bops;
|
||||
bops.insert(pA);
|
||||
bops.insert(pB);
|
||||
bops.mark_domains();
|
||||
Larger_than_zero ltz;
|
||||
return bops(ltz);
|
||||
}
|
||||
|
||||
template <typename K>
|
||||
Multipolygon_with_holes_2<K>
|
||||
intersection(const Multipolygon_with_holes_2<K>& pA)
|
||||
{
|
||||
CGAL::Polygon_repair::Boolean<K> bops;
|
||||
bops.insert(pA);
|
||||
struct Equal {
|
||||
int val;
|
||||
Equal(int val)
|
||||
|
|
@ -409,10 +441,35 @@ intersection(const Multipolygon_with_holes_2<K>& pA)
|
|||
return i == val;
|
||||
}
|
||||
};
|
||||
|
||||
CGAL::Polygon_repair::Boolean<K> bops;
|
||||
bops.insert(pA);
|
||||
bops.mark_domains();
|
||||
Equal equal(pA.number_of_polygons_with_holes());
|
||||
return bops(equal);
|
||||
}
|
||||
|
||||
template <typename PA, typename PB, typename K = Default>
|
||||
decltype(auto) // Multipolygon_with_holes_2<K>
|
||||
intersection(const PA& pA, const PB& pB, const K& k = Default())
|
||||
{
|
||||
typedef typename Default::Get<K, typename PA::Traits>::type Traits;
|
||||
|
||||
struct Equal {
|
||||
bool operator()(int i) const
|
||||
{
|
||||
return i == 2;
|
||||
}
|
||||
};
|
||||
|
||||
CGAL::Polygon_repair::Boolean<Traits> bops;
|
||||
bops.insert(pA);
|
||||
bops.insert(pB);
|
||||
bops.mark_domains();
|
||||
Equal equal;
|
||||
return bops(equal);
|
||||
}
|
||||
|
||||
} // namespace Polygon_repair
|
||||
} //namespace CGAL
|
||||
|
||||
|
|
|
|||
|
|
@ -109,14 +109,16 @@ Multipolygon_with_holes_2<Kernel, Container> repair(const Multipolygon_with_hole
|
|||
template <class Kernel, class Container>
|
||||
Multipolygon_with_holes_2<Kernel, Container> repair(const Multipolygon_with_holes_2<Kernel, Container>& p, Union_rule)
|
||||
{
|
||||
CGAL::Polygon_repair::Boolean<Kernel> bops;
|
||||
bops.insert(p);
|
||||
struct Larger_than_zero {
|
||||
bool operator()(int i) const
|
||||
{
|
||||
return i > 0;
|
||||
}
|
||||
};
|
||||
|
||||
CGAL::Polygon_repair::Boolean<Kernel> bops;
|
||||
bops.insert(p);
|
||||
bops.mark_domains();
|
||||
Larger_than_zero ltz;
|
||||
return bops(ltz);
|
||||
}
|
||||
|
|
@ -125,8 +127,6 @@ Multipolygon_with_holes_2<Kernel, Container> repair(const Multipolygon_with_hole
|
|||
template <class Kernel, class Container>
|
||||
Multipolygon_with_holes_2<Kernel, Container> repair(const Multipolygon_with_holes_2<Kernel, Container>& p, Intersection_rule)
|
||||
{
|
||||
CGAL::Polygon_repair::Boolean<Kernel> bops;
|
||||
bops.insert(p);
|
||||
struct Equal {
|
||||
int val;
|
||||
Equal(int val)
|
||||
|
|
@ -138,6 +138,10 @@ Multipolygon_with_holes_2<Kernel, Container> repair(const Multipolygon_with_hole
|
|||
return i == val;
|
||||
}
|
||||
};
|
||||
|
||||
CGAL::Polygon_repair::Boolean<Kernel> bops;
|
||||
bops.insert(p);
|
||||
bops.mark_domains();
|
||||
Equal equal(p.number_of_polygons_with_holes());
|
||||
return bops(equal);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue