mirror of https://github.com/CGAL/cgal
added Construct_projected_point_2(Segment_2, Point_2)
This commit is contained in:
parent
56ac3a5c31
commit
911ac1a34d
|
|
@ -3295,9 +3295,28 @@ namespace CartesianKernelFunctors {
|
||||||
Point_2
|
Point_2
|
||||||
operator()( const Segment_2& s, const Point_2& p ) const
|
operator()( const Segment_2& s, const Point_2& p ) const
|
||||||
{
|
{
|
||||||
assert(false);
|
const Point_2& a = s.source();
|
||||||
return p;
|
const Point_2& b = s.target();
|
||||||
// CommonKernelFunctors::Construct_projected_point_3<K>()(s,p,K());
|
typename K::FT dx = b.x() - a.x();
|
||||||
|
typename K::FT dy = b.y() - a.y();
|
||||||
|
|
||||||
|
// Degenerate segment
|
||||||
|
if (dx == 0 && dy == 0)
|
||||||
|
return a;
|
||||||
|
|
||||||
|
typename K::FT px = p.x() - a.x();
|
||||||
|
typename K::FT py = p.y() - a.y();
|
||||||
|
|
||||||
|
typename K::FT proj = (dx * px + dy * py) / (dx * dx + dy * dy);
|
||||||
|
|
||||||
|
if (proj <= 0.0)
|
||||||
|
return a;
|
||||||
|
|
||||||
|
if (proj >= 1.0)
|
||||||
|
return b;
|
||||||
|
|
||||||
|
typename K::Construct_point_2 construct_point_2;
|
||||||
|
return construct_point_2(a.x() + proj * dx, a.y() + proj * dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point_2
|
Point_2
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
bool
|
bool
|
||||||
_test_fct_constructions_2(const R&)
|
_test_fct_constructions_2(const R& r)
|
||||||
{
|
{
|
||||||
typedef typename R::RT RT;
|
typedef typename R::RT RT;
|
||||||
typedef CGAL::Point_2<R> Point;
|
typedef CGAL::Point_2<R> Point;
|
||||||
|
|
@ -89,6 +89,15 @@ _test_fct_constructions_2(const R&)
|
||||||
|
|
||||||
assert( CGAL::weighted_circumcenter( wpnw_b, wpse_b, wpsw_b ) == psw);
|
assert( CGAL::weighted_circumcenter( wpnw_b, wpse_b, wpsw_b ) == psw);
|
||||||
|
|
||||||
|
Point a(0.0, 1.0);
|
||||||
|
Point b(3.0, 4.0);
|
||||||
|
Segment seg(a, b);
|
||||||
|
|
||||||
|
assert(r.construct_projected_point_2_object()(seg, Point(0, 0)) == a);
|
||||||
|
assert(r.construct_projected_point_2_object()(seg, Point(5.0, 0)) == Point(2.0, 3.0));
|
||||||
|
assert(r.construct_projected_point_2_object()(seg, Point(5.0, 4.0)) == b);
|
||||||
|
assert(r.construct_projected_point_2_object()(seg, Point(2.0, 4.0)) == Point(2.5, 3.5));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue