mirror of https://github.com/CGAL/cgal
split MyPointC2.h into several .h files so that we can use
those files and avoid the doc to be not in sync with examples.
This commit is contained in:
parent
8b24541338
commit
13781476af
|
|
@ -1687,6 +1687,10 @@ Kernel_23/doc_tex/Kernel_23_ref/fig/compare_x_at_y.pdf -text svneol=unset#applic
|
|||
Kernel_23/doc_tex/Kernel_23_ref/fig/transvecthree.gif -text svneol=unset#image/gif
|
||||
Kernel_23/doc_tex/Kernel_23_ref/fig/transvectwo.gif -text svneol=unset#image/gif
|
||||
Kernel_23/doc_tex/Kernel_23_ref/radical_line.tex -text
|
||||
Kernel_23/examples/Kernel_23/MyConstruct_bbox_2.h -text
|
||||
Kernel_23/examples/Kernel_23/MyConstruct_coord_iterator.h -text
|
||||
Kernel_23/examples/Kernel_23/MyConstruct_point_2.h -text
|
||||
Kernel_23/examples/Kernel_23/MyPointC2_iostream.h -text
|
||||
Kernel_23/examples/Kernel_23/cartesian_converter.cpp -text
|
||||
Kernel_23/include/CGAL/functions_on_enums.h -text
|
||||
Kernel_23/include/CGAL/internal/Projection_traits_3.h -text
|
||||
|
|
|
|||
|
|
@ -25,58 +25,7 @@ Assume you have the following point class, where the coordinates are
|
|||
stored in an array of \ccc{doubles}, where we have another data member
|
||||
\ccc{color}, which shows up in the constructor.
|
||||
|
||||
\ccHtmlLinksOff
|
||||
\begin{ccExampleCode}
|
||||
class MyPointC2 {
|
||||
|
||||
private:
|
||||
double vec[2];
|
||||
int col;
|
||||
|
||||
public:
|
||||
|
||||
MyPointC2()
|
||||
: col(0)
|
||||
{
|
||||
*vec = 0;
|
||||
*(vec+1) = 0;
|
||||
}
|
||||
|
||||
|
||||
MyPointC2(const double x, const double y, int c)
|
||||
: col(c)
|
||||
{
|
||||
*vec = x;
|
||||
*(vec+1) = y;
|
||||
}
|
||||
|
||||
const double& x() const { return *vec; }
|
||||
|
||||
const double& y() const { return *(vec+1); }
|
||||
|
||||
double & x() { return *vec; }
|
||||
|
||||
double& y() { return *(vec+1); }
|
||||
|
||||
int color() const { return col; }
|
||||
|
||||
int& color() { return col; }
|
||||
|
||||
|
||||
bool operator==(const MyPointC2 &p) const
|
||||
{
|
||||
return ( *vec == *(p.vec) ) && ( *(vec+1) == *(p.vec + 1) && ( col == p.col) );
|
||||
}
|
||||
|
||||
bool operator!=(const MyPointC2 &p) const
|
||||
{
|
||||
return !(*this == p);
|
||||
}
|
||||
|
||||
};
|
||||
\end{ccExampleCode}
|
||||
\ccHtmlLinksOn
|
||||
|
||||
\ccIncludeExampleCode{Kernel_23/MyPointC2.h}
|
||||
|
||||
As said earlier the class is pretty minimalistic, for
|
||||
example it has no \ccc{bbox()} method. One
|
||||
|
|
@ -89,44 +38,14 @@ use of the functor \ccc{Kernel::Construct_bbox_2}.
|
|||
To make the right thing happen with \ccc{MyPointC2} we
|
||||
have to provide the following functor.
|
||||
|
||||
\ccHtmlLinksOff
|
||||
\begin{ccExampleCode}
|
||||
template <class ConstructBbox_2>
|
||||
class MyConstruct_bbox_2 : public ConstructBbox_2 {
|
||||
public:
|
||||
using ConstructBbox_2::operator();
|
||||
|
||||
CGAL::Bbox_2 operator()(const typename MyPointC2& p) const {
|
||||
return CGAL::Bbox_2(p.x(), p.y(), p.x(), p.y());
|
||||
}
|
||||
};
|
||||
\end{ccExampleCode}
|
||||
\ccHtmlLinksOn
|
||||
|
||||
\ccIncludeExampleCode{Kernel_23/MyConstruct_bbox_2.h}
|
||||
|
||||
Things are similar for random access to the \ccHtmlNoLinksFrom{Cartesian}
|
||||
coordinates of a point. As the coordinates are stored
|
||||
in an array of \ccc{doubles} we can use \ccc{double*} as
|
||||
random access iterator.
|
||||
|
||||
\ccHtmlLinksOff
|
||||
\begin{ccExampleCode}
|
||||
class MyConstruct_coord_iterator {
|
||||
public:
|
||||
const double* operator()(const MyPointC2& p)
|
||||
{
|
||||
return &p.x();
|
||||
}
|
||||
|
||||
const double* operator()(const MyPointC2& p, int)
|
||||
{
|
||||
const double* pyptr = &p.y();
|
||||
pyptr++;
|
||||
return pyptr;
|
||||
}
|
||||
};
|
||||
\end{ccExampleCode}
|
||||
\ccHtmlLinksOn
|
||||
\ccIncludeExampleCode{Kernel_23/MyConstruct_coord_iterator.h}
|
||||
|
||||
The last functor we have to provide is the one which constructs
|
||||
points. That is you are not forced to add the constructor
|
||||
|
|
@ -135,55 +54,14 @@ homogeneous coordinates.
|
|||
The functor is a kind of glue layer between the \cgal\ algorithms
|
||||
and your class.
|
||||
|
||||
\ccHtmlLinksOff
|
||||
\begin{ccExampleCode}
|
||||
template <typename K>
|
||||
class MyConstruct_point_2
|
||||
{
|
||||
typedef typename K::RT RT;
|
||||
typedef typename K::Point_2 Point_2;
|
||||
public:
|
||||
typedef Point_2 result_type;
|
||||
|
||||
Point_2
|
||||
operator()(CGAL::Origin o) const
|
||||
{ return Point_2(0,0, 0); }
|
||||
|
||||
Point_2
|
||||
operator()(const RT& x, const RT& y) const
|
||||
{ return Point_2(x, y, 0); }
|
||||
|
||||
|
||||
// We need this one, as such a functor is in the Filtered_kernel
|
||||
Point_2
|
||||
operator()(const RT& x, const RT& y, const RT& w) const
|
||||
{
|
||||
if(w != 1){
|
||||
return Point_2(x/w, y/w, 0);
|
||||
} else {
|
||||
return Point_2(x,y, 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
\end{ccExampleCode}
|
||||
\ccHtmlLinksOn
|
||||
|
||||
\ccIncludeExampleCode{Kernel_23/MyConstruct_point_2.h}
|
||||
|
||||
Now we are ready to put the puzzle together. We won't explain it in
|
||||
detail, but you see that there are \ccc{typedefs} to the new point
|
||||
class and the functors. All the other types are inherited.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
\ccIncludeExampleCode{Kernel_23/MyKernel.h}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Finally, we give an example how this new kernel can be used.
|
||||
Predicates and constructions work with the new point, they
|
||||
can be a used to construct segments and triangles with, and
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef MYCONSTRUCT_BBOX_2_H
|
||||
#define MYCONSTRUCT_BBOX_2_H
|
||||
|
||||
|
||||
template <class ConstructBbox_2>
|
||||
class MyConstruct_bbox_2 : public ConstructBbox_2 {
|
||||
public:
|
||||
using ConstructBbox_2::operator();
|
||||
|
||||
CGAL::Bbox_2 operator()(const MyPointC2& p) const {
|
||||
return CGAL::Bbox_2(p.x(), p.y(), p.x(), p.y());
|
||||
}
|
||||
};
|
||||
|
||||
#endif //MYCONSTRUCT_BBOX_2_H
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef MYCONSTRUCT_COORD_ITERATOR_H
|
||||
#define MYCONSTRUCT_COORD_ITERATOR_H
|
||||
|
||||
class MyConstruct_coord_iterator {
|
||||
public:
|
||||
const double* operator()(const MyPointC2& p)
|
||||
{
|
||||
return &p.x();
|
||||
}
|
||||
|
||||
const double* operator()(const MyPointC2& p, int)
|
||||
{
|
||||
const double* pyptr = &p.y();
|
||||
pyptr++;
|
||||
return pyptr;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //MYCONSTRUCT_COORD_ITERATOR_H
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
#ifndef MYCONSTRUCT_POINT_2_H
|
||||
#define MYCONSTRUCT_POINT_2_H
|
||||
|
||||
template <typename K, typename OldK>
|
||||
class MyConstruct_point_2
|
||||
{
|
||||
typedef typename K::RT RT;
|
||||
typedef typename K::Point_2 Point_2;
|
||||
typedef typename K::Line_2 Line_2;
|
||||
typedef typename Point_2::Rep Rep;
|
||||
public:
|
||||
typedef Point_2 result_type;
|
||||
|
||||
// Note : the CGAL::Return_base_tag is really internal CGAL stuff.
|
||||
// Unfortunately it is needed for optimizing away copy-constructions,
|
||||
// due to current lack of delegating constructors in the C++ standard.
|
||||
Rep // Point_2
|
||||
operator()(CGAL::Return_base_tag, CGAL::Origin o) const
|
||||
{ return Rep(o); }
|
||||
|
||||
Rep // Point_2
|
||||
operator()(CGAL::Return_base_tag, const RT& x, const RT& y) const
|
||||
{ return Rep(x, y); }
|
||||
|
||||
Rep // Point_2
|
||||
operator()(CGAL::Return_base_tag, const RT& x, const RT& y, const RT& w) const
|
||||
{ return Rep(x, y, w); }
|
||||
|
||||
Point_2
|
||||
operator()(CGAL::Origin o) const
|
||||
{ return MyPointC2(0, 0, 0); }
|
||||
|
||||
Point_2
|
||||
operator()(const RT& x, const RT& y) const
|
||||
{
|
||||
return MyPointC2(x, y, 0);
|
||||
}
|
||||
|
||||
Point_2
|
||||
operator()(const Line_2& l) const
|
||||
{
|
||||
typename OldK::Construct_point_2 base_operator;
|
||||
Point_2 p = base_operator(l);
|
||||
return p;
|
||||
}
|
||||
|
||||
Point_2
|
||||
operator()(const Line_2& l, int i) const
|
||||
{
|
||||
typename OldK::Construct_point_2 base_operator;
|
||||
return base_operator(l, i);
|
||||
}
|
||||
|
||||
// We need this one, as such a functor is in the Filtered_kernel
|
||||
Point_2
|
||||
operator()(const RT& x, const RT& y, const RT& w) const
|
||||
{
|
||||
if(w != 1){
|
||||
return MyPointC2(x/w, y/w, 0);
|
||||
} else {
|
||||
return MyPointC2(x,y, 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif //MYCONSTRUCT_POINT_2_H
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
#include <CGAL/squared_distance_2.h>
|
||||
#include <cassert>
|
||||
#include "MyKernel.h"
|
||||
|
||||
#include "MyPointC2_iostream.h"
|
||||
|
||||
typedef MyKernel<double> MK;
|
||||
typedef CGAL::Filtered_kernel_adaptor<MK> K;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
#include <CGAL/Cartesian.h>
|
||||
#include "MyPointC2.h"
|
||||
#include "MySegmentC2.h"
|
||||
#include "MyConstruct_bbox_2.h"
|
||||
#include "MyConstruct_coord_iterator.h"
|
||||
#include "MyConstruct_point_2.h"
|
||||
|
||||
// K_ is the new kernel, and K_Base is the old kernel
|
||||
template < typename K_, typename K_Base >
|
||||
|
|
|
|||
|
|
@ -54,136 +54,4 @@ public:
|
|||
|
||||
};
|
||||
|
||||
template <class ConstructBbox_2>
|
||||
class MyConstruct_bbox_2 : public ConstructBbox_2 {
|
||||
public:
|
||||
using ConstructBbox_2::operator();
|
||||
|
||||
CGAL::Bbox_2 operator()(const MyPointC2& p) const {
|
||||
return CGAL::Bbox_2(p.x(), p.y(), p.x(), p.y());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class MyConstruct_coord_iterator {
|
||||
public:
|
||||
const double* operator()(const MyPointC2& p)
|
||||
{
|
||||
return &p.x();
|
||||
}
|
||||
|
||||
const double* operator()(const MyPointC2& p, int)
|
||||
{
|
||||
const double* pyptr = &p.y();
|
||||
pyptr++;
|
||||
return pyptr;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename OldK>
|
||||
class MyConstruct_point_2
|
||||
{
|
||||
typedef typename K::RT RT;
|
||||
typedef typename K::Point_2 Point_2;
|
||||
typedef typename K::Line_2 Line_2;
|
||||
typedef typename Point_2::Rep Rep;
|
||||
public:
|
||||
typedef Point_2 result_type;
|
||||
|
||||
// Note : the CGAL::Return_base_tag is really internal CGAL stuff.
|
||||
// Unfortunately it is needed for optimizing away copy-constructions,
|
||||
// due to current lack of delegating constructors in the C++ standard.
|
||||
Rep // Point_2
|
||||
operator()(CGAL::Return_base_tag, CGAL::Origin o) const
|
||||
{ return Rep(o); }
|
||||
|
||||
Rep // Point_2
|
||||
operator()(CGAL::Return_base_tag, const RT& x, const RT& y) const
|
||||
{ return Rep(x, y); }
|
||||
|
||||
Rep // Point_2
|
||||
operator()(CGAL::Return_base_tag, const RT& x, const RT& y, const RT& w) const
|
||||
{ return Rep(x, y, w); }
|
||||
|
||||
Point_2
|
||||
operator()(CGAL::Origin o) const
|
||||
{ return MyPointC2(0, 0, 0); }
|
||||
|
||||
Point_2
|
||||
operator()(const RT& x, const RT& y) const
|
||||
{
|
||||
return MyPointC2(x, y, 0);
|
||||
}
|
||||
|
||||
Point_2
|
||||
operator()(const Line_2& l) const
|
||||
{
|
||||
typename OldK::Construct_point_2 base_operator;
|
||||
Point_2 p = base_operator(l);
|
||||
return p;
|
||||
}
|
||||
|
||||
Point_2
|
||||
operator()(const Line_2& l, int i) const
|
||||
{
|
||||
typename OldK::Construct_point_2 base_operator;
|
||||
return base_operator(l, i);
|
||||
}
|
||||
|
||||
// We need this one, as such a functor is in the Filtered_kernel
|
||||
Point_2
|
||||
operator()(const RT& x, const RT& y, const RT& w) const
|
||||
{
|
||||
if(w != 1){
|
||||
return MyPointC2(x/w, y/w, 0);
|
||||
} else {
|
||||
return MyPointC2(x,y, 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &os, const MyPointC2 &p)
|
||||
{
|
||||
switch(os.iword(CGAL::IO::mode)) {
|
||||
case CGAL::IO::ASCII :
|
||||
return os << p.x() << ' ' << p.y() << ' ' << p.color();
|
||||
case CGAL::IO::BINARY :
|
||||
CGAL::write(os, p.x());
|
||||
CGAL::write(os, p.y());
|
||||
CGAL::write(os, p.color());
|
||||
return os;
|
||||
default:
|
||||
return os << "MyPointC2(" << p.x() << ", " << p.y() << ", " << p.color() << ')';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::istream &
|
||||
operator>>(std::istream &is, MyPointC2 &p)
|
||||
{
|
||||
double x, y;
|
||||
int c;
|
||||
switch(is.iword(CGAL::IO::mode)) {
|
||||
case CGAL::IO::ASCII :
|
||||
is >> x >> y >> c;
|
||||
break;
|
||||
case CGAL::IO::BINARY :
|
||||
CGAL::read(is, x);
|
||||
CGAL::read(is, y);
|
||||
CGAL::read(is, c);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "" << std::endl;
|
||||
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
|
||||
break;
|
||||
}
|
||||
if (is) {
|
||||
p = MyPointC2(x, y, c);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
#endif // MY_POINTC2_H
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef MYPOINTC2_IOSTREAM_H
|
||||
#define MYPOINTC2_IOSTREAM_H
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &os, const MyPointC2 &p)
|
||||
{
|
||||
switch(os.iword(CGAL::IO::mode)) {
|
||||
case CGAL::IO::ASCII :
|
||||
return os << p.x() << ' ' << p.y() << ' ' << p.color();
|
||||
case CGAL::IO::BINARY :
|
||||
CGAL::write(os, p.x());
|
||||
CGAL::write(os, p.y());
|
||||
CGAL::write(os, p.color());
|
||||
return os;
|
||||
default:
|
||||
return os << "MyPointC2(" << p.x() << ", " << p.y() << ", " << p.color() << ')';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::istream &
|
||||
operator>>(std::istream &is, MyPointC2 &p)
|
||||
{
|
||||
double x, y;
|
||||
int c;
|
||||
switch(is.iword(CGAL::IO::mode)) {
|
||||
case CGAL::IO::ASCII :
|
||||
is >> x >> y >> c;
|
||||
break;
|
||||
case CGAL::IO::BINARY :
|
||||
CGAL::read(is, x);
|
||||
CGAL::read(is, y);
|
||||
CGAL::read(is, c);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "" << std::endl;
|
||||
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
|
||||
break;
|
||||
}
|
||||
if (is) {
|
||||
p = MyPointC2(x, y, c);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
#endif //MYPOINTC2_IOSTREAM_H
|
||||
Loading…
Reference in New Issue