From cb6639b85ad3f4a57860a6ac36b4c8889342659b Mon Sep 17 00:00:00 2001 From: Sylvain Pion Date: Mon, 7 Aug 2006 12:34:24 +0000 Subject: [PATCH] Introduce wmult_hw(), a new abstraction for Homogeneous/Cartesian, similar to wmult(), for calls .hw() on the last argument (i.e., does absolutely nothing in the Cartesian case). --- .../Intersections_3/intersection_3_1_impl.h | 34 +++---- Kernel_23/include/CGAL/Kernel/Wutils.h | 96 +++++++++++++++++++ 2 files changed, 113 insertions(+), 17 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h b/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h index d102be52b65..864bdc9bff9 100644 --- a/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h +++ b/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h @@ -42,7 +42,7 @@ intersection(const typename CGAL_WRAP(K)::Plane_3 &plane, const Direction_3 &line_dir = line.direction(); RT num = plane.a()*line_pt.hx() + plane.b()*line_pt.hy() - + plane.c()*line_pt.hz() + wmult((K*)0, plane.d(), line_pt.hw()); + + plane.c()*line_pt.hz() + wmult_hw((K*)0, plane.d(), line_pt); RT den = plane.a()*line_dir.dx() + plane.b()*line_dir.dy() + plane.c()*line_dir.dz(); if (den == 0) { @@ -58,7 +58,7 @@ intersection(const typename CGAL_WRAP(K)::Plane_3 &plane, den*line_pt.hx()-num*line_dir.dx(), den*line_pt.hy()-num*line_dir.dy(), den*line_pt.hz()-num*line_dir.dz(), - wmult((K*)0, den, line_pt.hw()))); + wmult_hw((K*)0, den, line_pt))); } template @@ -172,7 +172,7 @@ do_intersect(const typename CGAL_WRAP(K)::Plane_3 &plane, if (den != 0) return true; RT num = plane.a()*line_pt.hx() + plane.b()*line_pt.hy() - + plane.c()*line_pt.hz() + wmult((K*)0, plane.d(), line_pt.hw()); + + plane.c()*line_pt.hz() + wmult_hw((K*)0, plane.d(), line_pt); if (num == 0) { // all line return true; @@ -695,36 +695,36 @@ intersection( } else { newmin = Point_3( min_idx[0] == 0 - ? wmult((K*)0, min_points[0].hx(), min_points[1].hw()) - : wmult((K*)0, min_points[1].hx(), min_points[0].hw()) + ? wmult_hw((K*)0, min_points[0].hx(), min_points[1]) + : wmult_hw((K*)0, min_points[1].hx(), min_points[0]) , min_idx[1] == 0 - ? wmult((K*)0, min_points[0].hy(), min_points[1].hw()) - : wmult((K*)0, min_points[1].hy(), min_points[0].hw()) + ? wmult_hw((K*)0, min_points[0].hy(), min_points[1]) + : wmult_hw((K*)0, min_points[1].hy(), min_points[0]) , min_idx[2] == 0 - ? wmult((K*)0, min_points[0].hz(), min_points[1].hw()) - : wmult((K*)0, min_points[1].hz(), min_points[0].hw()) + ? wmult_hw((K*)0, min_points[0].hz(), min_points[1]) + : wmult_hw((K*)0, min_points[1].hz(), min_points[0]) , - wmult((K*)0, min_points[0].hw(), min_points[1].hw()) ); + wmult_hw((K*)0, min_points[0].hw(), min_points[1]) ); } if (max_idx[0] == max_idx[1] && max_idx[0] == max_idx[2]) { newmax = max_points[max_idx[0]]; } else { newmax = Point_3( max_idx[0] == 0 - ? wmult((K*)0, max_points[0].hx(), max_points[1].hw()) - : wmult((K*)0, max_points[1].hx(), max_points[0].hw()) + ? wmult_hw((K*)0, max_points[0].hx(), max_points[1]) + : wmult_hw((K*)0, max_points[1].hx(), max_points[0]) , max_idx[1] == 0 - ? wmult((K*)0, max_points[0].hy(), max_points[1].hw()) - : wmult((K*)0, max_points[1].hy(), max_points[0].hw()) + ? wmult_hw((K*)0, max_points[0].hy(), max_points[1]) + : wmult_hw((K*)0, max_points[1].hy(), max_points[0]) , max_idx[2] == 0 - ? wmult((K*)0, max_points[0].hz(), max_points[1].hw()) - : wmult((K*)0, max_points[1].hz(), max_points[0].hw()) + ? wmult_hw((K*)0, max_points[0].hz(), max_points[1]) + : wmult_hw((K*)0, max_points[1].hz(), max_points[0]) , - wmult((K*)0, max_points[0].hw(), max_points[1].hw()) ); + wmult_hw((K*)0, max_points[0].hw(), max_points[1]) ); } Object result = make_object(Iso_cuboid_3(newmin, newmax)); return result; diff --git a/Kernel_23/include/CGAL/Kernel/Wutils.h b/Kernel_23/include/CGAL/Kernel/Wutils.h index 4b132f12167..ab5c9318537 100644 --- a/Kernel_23/include/CGAL/Kernel/Wutils.h +++ b/Kernel_23/include/CGAL/Kernel/Wutils.h @@ -84,6 +84,56 @@ struct wmult_functor : public wmult_tag {}; +template < typename Rep_Tag > struct wmult_hw_tag; + +template <> +struct wmult_hw_tag +{ + template < typename RT, typename T > + const RT & operator()(const RT &a, const T &) const + { return a; } + + template < typename RT, typename T > + const RT & operator()(const RT &a, const RT &, const T &) const + { return a; } + + template < typename RT, typename T > + const RT & operator()(const RT &a, const RT &, const RT &, const T &) const + { return a; } + + template < typename RT, typename T > + const RT & operator()(const RT &a, const RT &, const RT &, const RT &, + const T &) const + { return a; } +}; + +template <> +struct wmult_hw_tag +{ + template < typename RT, typename T > + RT operator()(const RT &a, const T &t) const + { return a*t.hw(); } + + template < typename RT, typename T > + RT operator()(const RT &a, const RT &w1, const T &t) const + { return a*w1*t.hw(); } + + template < typename RT, typename T > + RT operator()(const RT &a, const RT &w1, const RT &w2, const T &t) const + { return a*w1*w2*t.hw(); } + + template < typename RT, typename T > + RT operator()(const RT &a, const RT &w1, const RT &w2, const RT &w3, + const T &t) const + { return a*w1*w2*w3*t.hw(); } +}; + + +template < typename K > +struct wmult_hw_functor + : public wmult_hw_tag {}; + + template < typename Rep_Tag > struct wcross_tag_2; template <> @@ -166,6 +216,52 @@ struct wcross_functor_3 } // end namespace CGALi +// wmult_hw() is like wmult(), except it calls .hw() on its last argument. +// This way, we can completely avoid creating FT(1) for Cartesian. + +template < typename K, typename T > +inline +typename K::RT +wmult_hw(K*, const typename K::RT &a, + const T &t) +{ + return CGALi::wmult_hw_functor()(a, t); +} + +template < typename K, typename T > +inline +typename K::RT +wmult_hw(K*, const typename K::RT &a, + const typename K::RT &w1, + const T &t) +{ + return CGALi::wmult_hw_functor()(a, w1, t); +} + +template < typename K, typename T > +inline +typename K::RT +wmult_hw(K*, const typename K::RT &a, + const typename K::RT &w1, + const typename K::RT &w2, + const T &t) +{ + return CGALi::wmult_hw_functor()(a, w1, w2, t); +} + +template < typename K, typename T > +inline +typename K::RT +wmult_hw(K*, const typename K::RT &a, + const typename K::RT &w1, + const typename K::RT &w2, + const typename K::RT &w3, + const T &t) +{ + return CGALi::wmult_hw_functor()(a, w1, w2, w3, t); +} + + template < typename K > inline typename K::RT