mirror of https://github.com/CGAL/cgal
Added Construct_curve_2. This is used by the (generic) code of the polyline traits.
This commit is contained in:
parent
5f436125e6
commit
c0838c533a
|
|
@ -723,29 +723,39 @@ public:
|
|||
return Approximate_2();
|
||||
}
|
||||
|
||||
class Construct_x_monotone_curve_2
|
||||
{
|
||||
//! Functor
|
||||
class Construct_x_monotone_curve_2 {
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Return an x-monotone curve connecting the two given endpoints.
|
||||
/*! Return an x-monotone curve connecting the two given endpoints.
|
||||
* \param p The first point.
|
||||
* \param q The second point.
|
||||
* \pre p and q must not be the same.
|
||||
* \return A segment connecting p and q.
|
||||
*/
|
||||
X_monotone_curve_2 operator() (const Point_2& p,
|
||||
const Point_2& q) const
|
||||
{
|
||||
return (X_monotone_curve_2 (p, q));
|
||||
}
|
||||
X_monotone_curve_2 operator()(const Point_2& p, const Point_2& q) const
|
||||
{ return (X_monotone_curve_2(p, q)); }
|
||||
};
|
||||
|
||||
/*! Get a Construct_x_monotone_curve_2 functor object. */
|
||||
Construct_x_monotone_curve_2 construct_x_monotone_curve_2_object () const
|
||||
{
|
||||
return Construct_x_monotone_curve_2();
|
||||
}
|
||||
{ return Construct_x_monotone_curve_2(); }
|
||||
|
||||
//! Functor
|
||||
class Construct_curve_2 {
|
||||
public:
|
||||
/*! Return a curve connecting the two given endpoints.
|
||||
* \param p The first point.
|
||||
* \param q The second point.
|
||||
* \pre p and q must not be the same.
|
||||
* \return A segment connecting p and q.
|
||||
*/
|
||||
Curve_2 operator()(const Point_2& p, const Point_2& q) const
|
||||
{ return (Curve_2(p, q)); }
|
||||
};
|
||||
|
||||
/*! Get a Construct_curve_2 functor object. */
|
||||
Construct_curve_2 construct_curve_2_object () const
|
||||
{ return Construct_curve_2(); }
|
||||
//@}
|
||||
|
||||
/// \name Functor definitions for the Boolean set-operation traits.
|
||||
|
|
|
|||
|
|
@ -199,6 +199,35 @@ public:
|
|||
_set (rat_coeffs);
|
||||
}
|
||||
|
||||
/*! Construct a segment conic arc from two endpoints.
|
||||
* \param source the source point with rational coordinates.
|
||||
*/
|
||||
_Conic_arc_2(Point_2& source, const Point_2& target) :
|
||||
_orient (COLLINEAR),
|
||||
_info(static_cast<int>(IS_VALID)),
|
||||
_source(source),
|
||||
_target(target),
|
||||
_extra_data_P(nullptr)
|
||||
{
|
||||
CGAL_precondition(Alg_kernel().compare_xy_2_object()(_source, _target) !=
|
||||
EQUAL);
|
||||
|
||||
// Compose the equation of the underlying line.
|
||||
const Algebraic x1 = source.x();
|
||||
const Algebraic y1 = source.y();
|
||||
const Algebraic x2 = target.x();
|
||||
const Algebraic y2 = target.y();
|
||||
|
||||
// The supporting line is A*x + B*y + C = 0, where:
|
||||
// A = y2 - y1, B = x1 - x2, C = x2*y1 - x1*y2
|
||||
// We use the extra data field to store the equation of this line.
|
||||
_extra_data_P = new Extra_data;
|
||||
_extra_data_P->a = y2 - y1;
|
||||
_extra_data_P->b = x1 - x2;
|
||||
_extra_data_P->c = x2*y1 - x1*y2;
|
||||
_extra_data_P->side = ZERO;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Construct a conic arc from the given line segment.
|
||||
* \param seg The line segment with rational endpoints.
|
||||
|
|
@ -325,7 +354,7 @@ public:
|
|||
// and it squared radius is R^2, that its equation is:
|
||||
// x^2 + y^2 - 2*x0*x - 2*y0*y + (x0^2 + y0^2 - R^2) = 0
|
||||
// Since this equation describes a curve with a negative (clockwise)
|
||||
// orientation, we multiply it by -1 if necessary to obtain a positive
|
||||
// orientation, we multiply it by -1 if nece_Conic_arc_2 ssary to obtain a positive
|
||||
// (counterclockwise) orientation.
|
||||
const Rational _zero (0);
|
||||
Rational rat_coeffs[6];
|
||||
|
|
|
|||
|
|
@ -177,58 +177,27 @@ public:
|
|||
_set();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Construct a special segment connecting to given endpoints (for the usage
|
||||
/*! Construct a special segment connecting to given endpoints (for the usage
|
||||
* of the landmarks point-location strategy).
|
||||
* \param source The source point.
|
||||
* \param target The target point.
|
||||
*/
|
||||
_Conic_x_monotone_arc_2(const Point_2& source, const Point_2& target) :
|
||||
Base()
|
||||
Base(source, target)
|
||||
{
|
||||
// Set the basic properties and clear the _info bits.
|
||||
this->_source = source;
|
||||
this->_target = target;
|
||||
this->_orient = COLLINEAR;
|
||||
this->_info = 0;
|
||||
this->_info != static_cast<int>(DEGREE_1);
|
||||
|
||||
// Check if the arc is directed right (the target is lexicographically
|
||||
// greater than the source point), or to the left.
|
||||
Alg_kernel ker;
|
||||
Comparison_result dir_res =
|
||||
ker.compare_xy_2_object()(this->_source, this->_target);
|
||||
|
||||
CGAL_precondition (dir_res != EQUAL);
|
||||
// Invalid arc:
|
||||
if (dir_res == EQUAL) return;
|
||||
|
||||
this->_info = (static_cast<int>(Conic_arc_2::IS_VALID) | static_cast<int>(DEGREE_1));
|
||||
if (dir_res == SMALLER)
|
||||
this->_info = (this->_info | IS_DIRECTED_RIGHT);
|
||||
|
||||
// Compose the equation of the underlying line.
|
||||
const Algebraic x1 = source.x(), y1 = source.y();
|
||||
const Algebraic x2 = target.x(), y2 = target.y();
|
||||
|
||||
// The supporting line is A*x + B*y + C = 0, where:
|
||||
//
|
||||
// A = y2 - y1, B = x1 - x2, C = x2*y1 - x1*y2
|
||||
//
|
||||
// We use the extra data field to store the equation of this line.
|
||||
this->_extra_data_P = new typename Base::Extra_data;
|
||||
this->_extra_data_P->a = y2 - y1;
|
||||
this->_extra_data_P->b = x1 - x2;
|
||||
this->_extra_data_P->c = x2*y1 - x1*y2;
|
||||
this->_extra_data_P->side = ZERO;
|
||||
auto cmp_xy = ker.compare_xy_2_object();
|
||||
Comparison_result dir_res = cmp_xy(this->_source, this->_target);
|
||||
if (dir_res == SMALLER) this->_info != IS_DIRECTED_RIGHT;
|
||||
|
||||
// Check if the segment is vertical.
|
||||
if (CGAL::sign (this->_extra_data_P->b) == ZERO)
|
||||
this->_info = (this->_info | IS_VERTICAL_SEGMENT);
|
||||
if (CGAL::sign(this->_extra_data_P->b) == ZERO)
|
||||
this->_info != IS_VERTICAL_SEGMENT;
|
||||
|
||||
// Mark that this is a special segment.
|
||||
this->_info = (this->_info | IS_SPECIAL_SEGMENT);
|
||||
|
||||
return;
|
||||
this->_info != IS_SPECIAL_SEGMENT;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -1535,6 +1535,7 @@ public:
|
|||
/*! Obtain an Approximate_2 functor object. */
|
||||
Approximate_2 approximate_2_object() const { return Approximate_2(); }
|
||||
|
||||
//! Functor
|
||||
class Construct_x_monotone_curve_2 {
|
||||
public:
|
||||
/*! Obtain an x-monotone curve connecting the two given endpoints.
|
||||
|
|
@ -1556,6 +1557,17 @@ public:
|
|||
Construct_x_monotone_curve_2 construct_x_monotone_curve_2_object() const
|
||||
{ return Construct_x_monotone_curve_2(); }
|
||||
//@}
|
||||
|
||||
/// \name Functor definitions for polylines.
|
||||
//@{
|
||||
|
||||
//! Functor
|
||||
typedef Construct_x_monotone_curve_2 Construct_curve_2;
|
||||
|
||||
/*! Obtain a Construct_curve_2 functor object. */
|
||||
Construct_curve_2 construct_curve_2_object() const
|
||||
{ return Construct_x_monotone_curve_2(*this); }
|
||||
//@}
|
||||
};
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -403,6 +403,18 @@ public:
|
|||
Compare_endpoints_xy_2 compare_endpoints_xy_2_object() const
|
||||
{ return Compare_endpoints_xy_2(); }
|
||||
//@}
|
||||
|
||||
//! \name Functor definitions for constructions.
|
||||
//@{
|
||||
|
||||
//! Functor
|
||||
typedef typename Kernel::Construct_segment_2 Construct_curve_2;
|
||||
|
||||
/*! Obtain a Construct_curve_2 functor object. */
|
||||
Construct_curve_2 construct_curve_2_object() const
|
||||
{ return this->construct_segment_2_object(); }
|
||||
|
||||
//@}
|
||||
};
|
||||
|
||||
} //namespace CGAL
|
||||
|
|
|
|||
|
|
@ -900,6 +900,7 @@ public:
|
|||
/*! Obtain an Approximate_2 functor object. */
|
||||
Approximate_2 approximate_2_object() const { return Approximate_2(); }
|
||||
|
||||
//! Functor
|
||||
class Construct_x_monotone_curve_2 {
|
||||
protected:
|
||||
typedef Arr_segment_traits_2<Kernel> Traits;
|
||||
|
|
@ -994,6 +995,17 @@ public:
|
|||
{ return Construct_x_monotone_curve_2(*this); }
|
||||
//@}
|
||||
|
||||
/// \name Functor definitions for polylines.
|
||||
//@{
|
||||
|
||||
//! Functor
|
||||
typedef Construct_x_monotone_curve_2 Construct_curve_2;
|
||||
|
||||
/*! Obtain a Construct_curve_2 functor object. */
|
||||
Construct_curve_2 construct_curve_2_object() const
|
||||
{ return Construct_x_monotone_curve_2(*this); }
|
||||
//@}
|
||||
|
||||
/// \name Functor definitions for the Boolean set-operation traits.
|
||||
//@{
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue