diff --git a/Packages/Kernel_d/include/CGAL/Convex_hull_d.h b/Packages/Kernel_d/include/CGAL/Convex_hull_d.h index afda7c30176..9ac13277c4f 100644 --- a/Packages/Kernel_d/include/CGAL/Convex_hull_d.h +++ b/Packages/Kernel_d/include/CGAL/Convex_hull_d.h @@ -442,7 +442,7 @@ public: Vertex_handle z; Forward_iterator it(first); std::list< Point_d > OtherPoints; - std::list< Point_d >::iterator pit, pred; + typename std::list< Point_d >::iterator pit, pred; while ( it != last ) { Point_d x = *it++; if ( current_dimension() == -1 ) { @@ -531,7 +531,7 @@ public: ++num_of_vertices; Vertex_handle z = new_vertex(p); std::list NewSimplices; - std::list::iterator it; + typename std::list::iterator it; CGAL_assertion(OtherPoints.empty()); for (it = VisibleFacets.begin(); it != VisibleFacets.end(); ++it) { OtherPoints.splice(OtherPoints.end(),PointsOf[*it]); diff --git a/Packages/Kernel_d/include/CGAL/Convex_hull_d_to_polyhedron_3.h b/Packages/Kernel_d/include/CGAL/Convex_hull_d_to_polyhedron_3.h index 0dfe78b9a0c..e80efec9cac 100644 --- a/Packages/Kernel_d/include/CGAL/Convex_hull_d_to_polyhedron_3.h +++ b/Packages/Kernel_d/include/CGAL/Convex_hull_d_to_polyhedron_3.h @@ -35,7 +35,7 @@ void operator()(HDS& hds ) // Chull available other than print_statistics() Hash_map index( -1); std::list L = ch.all_facets(); - std::list::iterator fit; + typename std::list::iterator fit; Facet_handle f; Vertex_handle v; int i = 0; diff --git a/Packages/Kernel_d/include/CGAL/IO/Convex_hull_d_window_stream.h b/Packages/Kernel_d/include/CGAL/IO/Convex_hull_d_window_stream.h index 7916bba5f9d..e6960b30f07 100644 --- a/Packages/Kernel_d/include/CGAL/IO/Convex_hull_d_window_stream.h +++ b/Packages/Kernel_d/include/CGAL/IO/Convex_hull_d_window_stream.h @@ -164,7 +164,7 @@ void d3_surface_map(const Convex_hull_d& C, int facet_num = 0; std::list Surface = C.all_facets(); - std::list::iterator it; + typename std::list::iterator it; for(it = Surface.begin(); it != Surface.end(); ++it) { f = *it; ++facet_num; diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Aff_transformationHd.C b/Packages/Kernel_d/include/CGAL/Kernel_d/Aff_transformationHd.C index ff82e375509..19786839f3e 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Aff_transformationHd.C +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Aff_transformationHd.C @@ -93,11 +93,11 @@ Aff_transformationHd(int d, const DirectionHd& dir, lower_ok = (common_part + diff_part > rhs); if ( lower_ok && upper_ok ) { - if ( CGAL_NTS square(p)%2 + CGAL_NTS square(q)%2 > 1) { + if ( CGAL_NTS square(p)%RT(2) + CGAL_NTS square(q)%RT(2) > 1) { sin = p*q; - cos = (CGAL_NTS square(q) - CGAL_NTS square(p))/2; + cos = (CGAL_NTS square(q) - CGAL_NTS square(p))/RT(2); // exact division - denom = (CGAL_NTS square(p) + CGAL_NTS square(q))/2; + denom = (CGAL_NTS square(p) + CGAL_NTS square(q))/RT(2); // exact division } else { cos = CGAL_NTS square(q) - CGAL_NTS square(p); diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionCd.C b/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionCd.C index d79a915d072..cfaa3c60553 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionCd.C +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionCd.C @@ -42,8 +42,8 @@ cmp(const DirectionCd& h1, { if (h1.identical(h2)) return EQUAL; int i, d = h1.dimension(); - for (i = 0; i < d && h1.delta(i)==0 && - h2.delta(i)==0; ++i) ; // no body + for (i = 0; i < d && h1.delta(i)==FT(0) && + h2.delta(i)==FT(0); ++i) ; // no body int c1 = CGAL_NTS sign(h1.delta(i)); int c2 = CGAL_NTS sign(h2.delta(i)); if (c1 != c2) return CGAL_NTS compare(c1,c2); diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionCd.h b/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionCd.h index c7b2a4627c2..e4452208153 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionCd.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionCd.h @@ -61,10 +61,22 @@ DirectionCd(int d = 0) : Base( Tuple(d) ) {} DirectionCd(const VectorCd& v); +#ifndef CGAL_SIMPLE_INTERFACE + template DirectionCd(int d, InputIterator first, InputIterator last) : Base( Tuple(d,first,last) ) {} +#else +#define FIXDIRCD(I) \ +DirectionCd(int d, I first, I last) : Base( Tuple(d,first,last) ) {} +FIXDIRCD(int*) +FIXDIRCD(const int*) +FIXDIRCD(RT*) +FIXDIRCD(const RT*) +#undef FIXDIRCD +#endif + DirectionCd(Base_direction, int d, int i) : Base( Tuple(d) ) { if ( d==0 ) return; CGAL_assertion_msg((0<=i&&i> <> +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS (std::istream& I, DirectionCd& d); -friend std::ostream& operator<< <> +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS (std::ostream& O, const DirectionCd& d); }; // end of class DirectionCd diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionHd.h b/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionHd.h index 9ed72beca32..2301f734e6d 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionHd.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/DirectionHd.h @@ -96,6 +96,9 @@ initialized to some direction in $d$-dimensional space.}*/ DirectionHd(const VectorHd& v); /*{\Mcreate introduces a variable |\Mvar| of type |DirectionHd| initialized to the direction of |v|.}*/ + +#ifndef CGAL_SIMPLE_INTERFACE + template DirectionHd(int d, InputIterator first, InputIterator last) : Base( Tuple(d+1,first,last,1) ) {} @@ -104,6 +107,16 @@ with representation tuple |set [first,last)|. \precond |d| is nonnegative, |[first,last)| has |d| elements and the value type of |InputIterator| is |RT|.}*/ +#else +#define FIXDIRHD(I) \ +DirectionHd(int d, I first, I last) : Base( Tuple(d+1,first,last,1) ) {} +FIXDIRHD(int*) +FIXDIRHD(const int*) +FIXDIRHD(RT*) +FIXDIRHD(const RT*) +#undef FIXDIRHD +#endif + DirectionHd(Base_direction, int d, int i) : Base( Tuple(d+1) ) /*{\Mcreate returns a variable |\Mvar| of type |\Mname| initialized to the direction of the $i$-th base vector of dimension $d$. }*/ @@ -198,9 +211,9 @@ RT dx() const { return delta(0); } RT dy() const { return delta(1); } RT dz() const { return delta(2); } -friend std::istream& operator>> <> +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS (std::istream& I, DirectionHd& d); -friend std::ostream& operator<< <> +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS (std::ostream& O, const DirectionHd& d); }; // end of class DirectionHd diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Direction_d.h b/Packages/Kernel_d/include/CGAL/Kernel_d/Direction_d.h index a296f6b66a4..84d72281313 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Direction_d.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Direction_d.h @@ -34,19 +34,35 @@ class Direction_d : public pR::Direction_d_base typedef typename R::RT RT; typedef typename R::FT FT; typedef typename R::LA LA; + typedef typename Base::Base_direction Base_direction; Direction_d(int d=0) : Base(d) {} Direction_d(int a, int b) : Base(a,b) {} Direction_d(const RT& a, const RT& b) : Base(a,b) {} Direction_d(int a, int b, int c) : Base(a,b,c) {} Direction_d(const RT& a, const RT& b, const RT& c) : Base(a,b,c) {} + +#ifndef CGAL_SIMPLE_INTERFACE + template Direction_d (int d, InputIterator first, InputIterator last) : Base(d, first, last) {} + +#else +#define FIXDIRD(I) \ +Direction_d (int d, I first, I last) : Base(d, first, last) {} + +FIXDIRD(int*) +FIXDIRD(const int*) +FIXDIRD(RT*) +FIXDIRD(const RT*) +#undef FIXDIRD +#endif + Direction_d(const Direction_d &d) : Base(d) {} Direction_d(const Vector_d &v) : Base(v) {} - Direction_d(typename Base::Base_direction, int d, int i) : - Base(typename Base::Base_direction(),d,i) {} + Direction_d(Base_direction, int d, int i) : + Base(Base_direction(),d,i) {} Direction_d(const Base& p) : Base(p) {} Self operator-() const { return Base::operator-(); } diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneCd.C b/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneCd.C index 140b68d1779..79f35b9f586 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneCd.C +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneCd.C @@ -40,10 +40,10 @@ weak_cmp(const HyperplaneCd& h1, int i, d = h1.dimension(); for (i = 0; i <= d && - h1.coefficient(i) == 0 && - h2.coefficient(i) == 0; i++); // no body - if (h1.coefficient(i) == 0) return SMALLER; - if (h2.coefficient(i) == 0) return LARGER; + h1.coefficient(i) == FT(0) && + h2.coefficient(i) == FT(0); i++); // no body + if (h1.coefficient(i) == FT(0)) return SMALLER; + if (h2.coefficient(i) == FT(0)) return LARGER; int s = CGAL_NTS sign(h1.coefficient(i)) * CGAL_NTS sign(h2.coefficient(i)); @@ -73,8 +73,8 @@ strong_cmp(const HyperplaneCd& h1, int i; int d = h1.dimension(); for (i = 0; i <=d && - h1.coefficient(i)==0 && - h2.coefficient(i)==0; i++) ; // no body + h1.coefficient(i)==FT(0) && + h2.coefficient(i)==FT(0); i++) ; // no body int c1 = CGAL_NTS sign(h1.coefficient(i)); int c2 = CGAL_NTS sign(h2.coefficient(i)); if (c1 != c2) return CGAL_NTS compare(c1,c2); diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneCd.h b/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneCd.h index 468e0971467..fa088763929 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneCd.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneCd.h @@ -53,19 +53,32 @@ typedef typename Tuple::const_iterator Coefficient_const_iterator; HyperplaneCd(int d = 0) : Base( Tuple(d+1) ) {} +#ifndef CGAL_SIMPLE_INTERFACE + template -HyperplaneCd(int d, InputIterator first, InputIterator last, FT D) +HyperplaneCd(int d, InputIterator first, InputIterator last, const FT& D) : Base( Tuple(d+1,first,last,D) ) {} template HyperplaneCd(int d, InputIterator first, InputIterator last) : Base( Tuple(d+1,first,last) ) {} -template -HyperplaneCd(ForwardIterator first, ForwardIterator last, - const PointCd& o, - Oriented_side side = Oriented_side(0)) - : Base( Tuple(o.dimension()+1) ) +#else +#define FIXHYPCD(I)\ +HyperplaneCd(int d, I first, I last) : Base( Tuple(d+1,first,last) ) {}\ +HyperplaneCd(int d, I first, I last, const FT& D) \ + : Base(Tuple(d+1,first,last,D)) {} +FIXHYPCD(int*) +FIXHYPCD(const int*) +FIXHYPCD(RT*) +FIXHYPCD(const RT*) +#undef FIXHYPCD +#endif + +template +void +construct_from_points(ForwardIterator first, ForwardIterator last, + const PointCd& o, Oriented_side side) { // inline due to template parameter TUPLE_DIM_CHECK(first,last,hyperplane::construction); @@ -108,6 +121,40 @@ HyperplaneCd(ForwardIterator first, ForwardIterator last, invert_rep(); } +#ifndef CGAL_SIMPLE_INTERFACE + +template +HyperplaneCd(ForwardIterator first, ForwardIterator last, + const PointCd& o, + Oriented_side side = Oriented_side(0)) + : Base( Tuple(o.dimension()+1) ) +{ construct_from_points(first,last,o,side); } + +#else + +HyperplaneCd(const PointCd* first, const PointCd* last, + const PointCd& o, + Oriented_side side = Oriented_side(0)) + : Base( Tuple(o.dimension()+1) ) +{ construct_from_points(first,last,o,side); } + +typedef typename std::vector >::iterator vecpntit; +typedef typename std::vector >::const_iterator vecpntcit; + +HyperplaneCd(vecpntit first, vecpntit last, + const PointCd& o, + Oriented_side side = Oriented_side(0)) + : Base( Tuple(o.dimension()+1) ) +{ construct_from_points(first,last,o,side); } + +HyperplaneCd(vecpntcit first, vecpntcit last, + const PointCd& o, + Oriented_side side = Oriented_side(0)) + : Base( Tuple(o.dimension()+1) ) +{ construct_from_points(first,last,o,side); } + +#endif + HyperplaneCd(const PointCd& p, const DirectionCd& dir) : Base( Tuple(p.dimension()+1) ) { @@ -207,9 +254,9 @@ bool operator==(const HyperplaneCd& h2) const bool operator!=(const HyperplaneCd& h2) const { return !operator==(h2); } -friend std::istream& operator>> <> +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS (std::istream&, HyperplaneCd&); -friend std::ostream& operator<< <> +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS (std::ostream&, const HyperplaneCd&); }; // end of class HyperplaneCd diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneHd.C b/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneHd.C index 0511c95d731..a8466626706 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneHd.C +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneHd.C @@ -1,8 +1,24 @@ -//--------------------------------------------------------------------- -// file generated by notangle from HyperplaneHd.lw -// please debug or modify noweb file -// coding: K. Mehlhorn, M. Seel -//--------------------------------------------------------------------- +// ====================================================================== +// +// Copyright (c) 2001 The CGAL Consortium +// +// This software and related documentation is part of an INTERNAL release +// of the Computational Geometry Algorithms Library (CGAL). It is not +// intended for general use. +// +// ---------------------------------------------------------------------- +// +// release : $CGAL_Revision: CGAL-2.3-I-67 $ +// release_date : $CGAL_Date: 2001/05/29 $ +// +// file : include/CGAL/Kernel_d/HyperplaneCd.C +// package : Kernel_d (0.9.19) +// maintainer : Michael Seel +// author(s) : Michael Seel +// coordinator : Susan Hert +// +// ====================================================================== + #ifndef CGAL_HYPERPLANEHD_C #define CGAL_HYPERPLANEHD_C CGAL_BEGIN_NAMESPACE diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneHd.h b/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneHd.h index 1bae888ad51..11e5287affd 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneHd.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/HyperplaneHd.h @@ -20,11 +20,6 @@ // coordinator : MPI Saarbruecken (Susan.Hert@mpi-sb.mpg.de) // // ====================================================================== -//--------------------------------------------------------------------- -// file generated by notangle from HyperplaneHd.lw -// please debug or modify noweb file -// coding: K. Mehlhorn, M. Seel -//--------------------------------------------------------------------- #ifndef CGAL_HYPERPLANEHD_H #define CGAL_HYPERPLANEHD_H @@ -100,13 +95,7 @@ HyperplaneHd(int d = 0) : Base( Tuple(d+1) ) {} /*{\Mcreate introduces a variable |\Mvar| of type |\Mname| initialized to some hyperplane in $d$ - dimensional space. }*/ -template -HyperplaneHd(int d, InputIterator first, InputIterator last, RT D) - : Base( Tuple(d+1,first,last,D) ) {} -/*{\Mcreate introduces a variable |\Mvar| of type |\Mname| -initialized to the hyperplane with coefficients |set [first,last)| and -|D|. \precond |size [first,last) == d| and the value type of -InputIterator is |RT|.}*/ +#ifndef CGAL_SIMPLE_INTERFACE template HyperplaneHd(int d, InputIterator first, InputIterator last) @@ -116,17 +105,44 @@ initialized to the hyperplane with coefficients |set [first,last)|. \precond |size [first,last) == d+1| and the value type of InputIterator is |RT|.}*/ -template -HyperplaneHd(ForwardIterator first, ForwardIterator last, - const PointHd& o, - Oriented_side side = Oriented_side(0)) -/*{\Mcreate constructs some hyperplane that passes through the points -in |set [first,last)|. If |side| is |ON_POSITIVE_SIDE| or -|ON_NEGATIVE_SIDE| then |o| is on that side of the constructed -hyperplane. \precond A hyperplane with the stated properties must -exist. The value type of |ForwardIterator| is |PointHd|. }*/ +template +HyperplaneHd(int d, InputIterator first, InputIterator last, const RT& D) + : Base( Tuple(d+1,first,last,D) ) {} +/*{\Mcreate introduces a variable |\Mvar| of type |\Mname| +initialized to the hyperplane with coefficients |set [first,last)| and +|D|. \precond |size [first,last) == d| and the value type of +InputIterator is |RT|.}*/ - : Base( Tuple(o.dimension()+1) ) { +#else +#define FIXHYPHD(I)\ +HyperplaneHd(int d, I first, I last) : Base( Tuple(d+1,first,last) ) {}\ +HyperplaneHd(int d, I first, I last, const RT& D) \ + : Base(Tuple(d+1,first,last,D)) {} +FIXHYPHD(int*) +FIXHYPHD(const int*) +FIXHYPHD(RT*) +FIXHYPHD(const RT*) +#undef FIXHYPHD +#endif + +/* We want to construct a hyperplane that passes through a set |P = +set [first,last)| of points in $d$-dimensional space and has a +specified point $o$ on a specified side. We simply have to find a +vector $x$ such that $P^T \cdot x = 0$ for every point in $P$. This +amounts to solving a homogeneous linear system. If the system has only +a trivial solution the task at hand is unsolvable and we report an +error. So assume that the system has a non-trivial solution. Let +vectors $s_1, \ldots, s_k$ span the solution space. if |side == ZERO| +we may take any $s_j$ as the normal vector of our hyperplane. if +$|side| \neq 0$ and the task at hand is solvable there must be a $j$ +such that $o^T \cdot s_j \neq 0$. We take $s_j$ as the normal vector +of our hyperplane and use |o| to normalize the hyperplane equation. */ + +template +void +construct_from_points(ForwardIterator first, ForwardIterator last, + const PointHd& o, Oriented_side side) +{ TUPLE_DIM_CHECK(first,last,hyperplane::construction); CGAL_assertion_msg((first->dimension()==o.dimension()), "hyperplane::construction: dimensions disagree."); @@ -170,6 +186,47 @@ exist. The value type of |ForwardIterator| is |PointHd|. }*/ invert_rep(); } + +#ifndef CGAL_SIMPLE_INTERFACE + +template +HyperplaneHd(ForwardIterator first, ForwardIterator last, + const PointHd& o, + Oriented_side side = Oriented_side(0)) +/*{\Mcreate constructs some hyperplane that passes through the points +in |set [first,last)|. If |side| is |ON_POSITIVE_SIDE| or +|ON_NEGATIVE_SIDE| then |o| is on that side of the constructed +hyperplane. \precond A hyperplane with the stated properties must +exist. The value type of |ForwardIterator| is |PointHd|. }*/ + : Base( Tuple(o.dimension()+1) ) +{ construct_from_points(first,last,o,side); } + +#else + +HyperplaneHd(const PointHd* first, const PointHd* last, + const PointHd& o, + Oriented_side side = Oriented_side(0)) : + Base( Tuple(o.dimension()+1) ) +{ construct_from_points(first,last,o,side); } + +typedef typename std::vector >::iterator vecpntit; +typedef typename std::vector >::const_iterator vecpntcit; + +HyperplaneHd(vecpntit first, vecpntit last, + const PointHd& o, + Oriented_side side = Oriented_side(0)) : + Base( Tuple(o.dimension()+1) ) +{ construct_from_points(first,last,o,side); } + +HyperplaneHd(vecpntcit first, vecpntcit last, + const PointHd& o, + Oriented_side side = Oriented_side(0)) : + Base( Tuple(o.dimension()+1) ) +{ construct_from_points(first,last,o,side); } + +#endif + + HyperplaneHd(const PointHd& p, const DirectionHd& dir) /*{\Mcreate constructs the hyperplane with normal direction |dir| that passes through $p$. The direction |dir| points into the positive @@ -307,9 +364,9 @@ bool operator==(const HyperplaneHd& h2) const bool operator!=(const HyperplaneHd& h2) const { return !operator==(h2); } -friend std::istream& operator>> <> +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS (std::istream&, HyperplaneHd&); -friend std::ostream& operator<< <> +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS (std::ostream&, const HyperplaneHd&); }; // end of class HyperplaneHd @@ -330,10 +387,8 @@ arithmetic, input and output on a hyperplane $h$ take time $O(|h.dimension()|)$. coordinate access and |dimension()| take constant time. The space requirement is $O(|h.dimension()|)$. }*/ -//----------------------- end of file ---------------------------------- - - - CGAL_END_NAMESPACE #endif // CGAL_HYPERPLANEHD_H +//----------------------- end of file ---------------------------------- + diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Hyperplane_d.h b/Packages/Kernel_d/include/CGAL/Kernel_d/Hyperplane_d.h index 6c13558095a..90af661b7e2 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Hyperplane_d.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Hyperplane_d.h @@ -49,6 +49,8 @@ class Hyperplane_d : public pR::Hyperplane_d_base Hyperplane_d(const Hyperplane_d &h) : Base(h) {} Hyperplane_d(const Base& p) : Base(p) {} +#ifndef CGAL_SIMPLE_INTERFACE + template Hyperplane_d(int d, InputIterator first, InputIterator last) : Base (d, first, last) {} @@ -63,6 +65,30 @@ class Hyperplane_d : public pR::Hyperplane_d_base const Point_d& o, Oriented_side side = Oriented_side(0)) : Base(first,last,o,side) {} +#else +#define FIXHYPD(I) \ +Hyperplane_d(int d, I first, I last) : Base (d,first,last) {} \ +Hyperplane_d(int d, I first, I last, const RT& D) : Base (d,first,last,D) {} +#define FIXHYPDD(I) \ +Hyperplane_d(I first, I last, const Point_d& o, Oriented_side side = \ +Oriented_side(0)) : Base(o.dimension()) \ +{ construct_from_points(first,last,o,side); } + + //Oriented_side(0)) : Base(first,last,o,side) {} + +FIXHYPD(int*) +FIXHYPD(const int*) +FIXHYPD(RT*) +FIXHYPD(const RT*) +#undef FIXHYPD +FIXHYPDD(Point_d*) +FIXHYPDD(const Point_d*) +FIXHYPDD(typename std::vector< Point_d >::iterator) +FIXHYPDD(typename std::vector< Point_d >::const_iterator) + +#undef FIXHYPDD +#endif + Vector_d orthogonal_vector() const { return Base::orthogonal_vector(); } Direction_d orthogonal_direction() const diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Ivector.h b/Packages/Kernel_d/include/CGAL/Kernel_d/Ivector.h index 930db676de6..34f9b7cf7cc 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Ivector.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Ivector.h @@ -48,7 +48,7 @@ CGAL_BEGIN_NAMESPACE -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__BORLANDC__) #define CGAL_SIMPLE_INTERFACE #endif @@ -67,7 +67,6 @@ Ivector(T f, T l) \ #define ERROR_HANDLER(n,s) CGAL_assertion_msg(!(n),s) /*{\Msubst -<># <_NT,_ALLOC># Ivector#Vector Imatrix#Matrix @@ -241,7 +240,7 @@ Ivector(Forward_iterator first, Forward_iterator last) private: void init(int d, const NT& x0, const NT& x1, const NT& x2=0, const NT& x3=0) { dim = d; allocate_vec_space(v,dim); - v[0]=x0; v[1]=x1; ( d>2 ? (v[2]=x2) : 0); ( d>3 ? (v[3]=x3) : 0); + v[0]=x0; v[1]=x1; if ( d>2 ) v[2]=x2; if ( d>3 ) v[3]=x3; } public: diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Line_d.h b/Packages/Kernel_d/include/CGAL/Kernel_d/Line_d.h index 3c69bed32e2..d893e1c810c 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Line_d.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Line_d.h @@ -160,8 +160,10 @@ bool operator==(const Line_d& l1) const bool operator!=(const Line_d& l1) const { return !operator==(l1); } -friend std::istream& operator>> <> (std::istream&, Line_d&); -friend std::ostream& operator<< <> (std::ostream&, const Line_d&); +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS +(std::istream&, Line_d&); +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS +(std::ostream&, const Line_d&); }; // end of class diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Linear_algebraCd.C b/Packages/Kernel_d/include/CGAL/Kernel_d/Linear_algebraCd.C index c8ba4196b1b..6a125a29e0b 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Linear_algebraCd.C +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Linear_algebraCd.C @@ -188,10 +188,10 @@ inverse(const Matrix &M, Matrix &I, FT &D, Vector &c) typename Matrix::row_iterator rit, wit; for (rank=0; rank; PointCd(int d = 0) : Base( Tuple(d) ) {} PointCd(int d, const Origin&) : Base( Tuple(d) ) {} +#ifndef CGAL_SIMPLE_INTERFACE + template PointCd(int d, InputIterator first, InputIterator last) - : Base( Tuple(d,first,last) ) {} + : Base( Tuple(d,first,last) ) +{ if ( first == last ) return; + // else first specifies common denominator: + CGAL_assertion_msg(*first!=FT(0), + "PointCd::constructor: denominator must be nonzero."); + for (register int i=0; i PointCd (int d, InputIterator first, InputIterator last, @@ -77,6 +85,26 @@ PointCd (int d, InputIterator first, InputIterator last, for (register int i=0; i> <> +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS (std::istream&, PointCd&); -friend std::ostream& operator<< <> +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS (std::ostream&, const PointCd&); FT hx() const { return cartesian(0); } diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/PointHd.h b/Packages/Kernel_d/include/CGAL/Kernel_d/PointHd.h index 622238d2792..c6a856fc489 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/PointHd.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/PointHd.h @@ -102,6 +102,8 @@ $d$-dimensional space, initialized to the origin.}*/ : Base( Tuple(d+1) ) { entry(d) = 1; } +#ifndef CGAL_SIMPLE_INTERFACE + template PointHd(int d, InputIterator first, InputIterator last) /*{\Mcreate introduces a variable |\Mvar| of type |\Mname| in @@ -114,8 +116,10 @@ chosen is the sign of $h_d$. \precond |d| is nonnegative, non-zero, and the value type of |InputIterator| is |RT|.}*/ : Base( Tuple(d+1,first,last) ) { RT D = entry(d); - CGAL_assertion_msg(D!=0,"PointHd::constructor: denom must be nonzero."); - if ( D < 0 ) invert_rep(); + CGAL_assertion_msg(first!=last || D!=RT(0), + "PointHd::constructor: denominator must be nonzero."); + if ( D == RT(0) ) entry(d) = 1; + if ( D < RT(0) ) invert_rep(); } template @@ -128,10 +132,31 @@ defined by |H = set [first,last)| and |D|: $(\pm |H[0]|, \pm|H[1]|, $D$. \precond |D| is non-zero, the iterator range defines a $d$-tuple of |RT|, and the value type of |InputIterator| is |RT|. }*/ : Base( Tuple(d+1,first,last,D) ) -{ CGAL_assertion_msg(D!=0,"PointHd::constructor: D must be nonzero."); - if (D < 0) invert_rep(); +{ CGAL_assertion_msg(D!=RT(0),"PointHd::constructor: D must be nonzero."); + if (D < RT(0)) invert_rep(); } +#else +#define FIXPNTHD(I) \ +PointHd(int d, I first, I last) : Base( Tuple(d+1,first,last) )\ +{ RT D = entry(d);\ + CGAL_assertion_msg(first!=last || D!=RT(0),\ + "PointHd::constructor: denominator must be nonzero.");\ + if ( D == RT(0) ) entry(d) = 1; if ( D < RT(0) ) invert_rep(); \ +} \ +PointHd (int d, I first, I last, const RT& D) : Base(Tuple(d+1,first,last,D))\ +{ CGAL_assertion_msg(D!=RT(0),"PointHd::constructor: D must be nonzero.");\ + if (D < RT(0)) invert_rep();\ +} + +FIXPNTHD(int*) +FIXPNTHD(const int*) +FIXPNTHD(RT*) +FIXPNTHD(const RT*) +#undef FIXPNTHD + +#endif + PointHd(int x, int y, int w = 1) : Base( Tuple((RT)x,(RT)y,(RT)w) ) { CGAL_assertion_msg((w != 0),"PointHd::construction: w == 0."); if (w < 0) invert_rep(); @@ -258,9 +283,9 @@ bool operator==(const Origin&) const return true; } -friend std::istream& operator>> <> +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS (std::istream&, PointHd&); -friend std::ostream& operator<< <> +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS (std::ostream&, const PointHd&); /*{\Mtext \headerline{Downward compatibility} We provide operations of the lower dimensional interface |x()|, |y()|, diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Point_d.h b/Packages/Kernel_d/include/CGAL/Kernel_d/Point_d.h index 1e5c5c1a55a..7fab7c137f7 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Point_d.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Point_d.h @@ -45,12 +45,27 @@ class Point_d : public pR::Point_d_base Point_d(const RT& a, const RT& b, const RT& c, const RT& d) : Base(a,b,c,d) {} +#ifndef CGAL_SIMPLE_INTERFACE + template Point_d (int d, InputIterator first, InputIterator last) : Base (d, first, last) {} template Point_d(int d, InputIterator first, InputIterator last, const RT& D) : Base (d, first, last, D) {} + +#else +#define FIXPNTD(I) \ +Point_d (int d, I first, I last) : Base (d, first, last) {} \ +Point_d(int d, I first, I last, const RT& D) : Base (d, first, last, D) {} + +FIXPNTD(int*) +FIXPNTD(const int*) +FIXPNTD(RT*) +FIXPNTD(const RT*) +#undef FIXPNTD +#endif + Point_d(const Self &p) : Base(p) {} Point_d(const Base& p) : Base(p) {} diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Ray_d.h b/Packages/Kernel_d/include/CGAL/Kernel_d/Ray_d.h index 5ed63bc71f1..90216a71a96 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Ray_d.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Ray_d.h @@ -157,8 +157,10 @@ bool operator==(const Ray_d& r1) const bool operator!=(const Ray_d& r1) { return !operator==(r1); } -friend std::istream& operator>> <> (std::istream&, Ray_d&); -friend std::ostream& operator<< <> (std::ostream&, const Ray_d&); +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS +(std::istream&, Ray_d&); +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS +(std::ostream&, const Ray_d&); }; // end of class diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Segment_d.h b/Packages/Kernel_d/include/CGAL/Kernel_d/Segment_d.h index 5d72e2cea45..acdc393704f 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Segment_d.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Segment_d.h @@ -180,8 +180,10 @@ bool operator==(const Segment_d& t) const bool operator!=(const Segment_d& t) const { return !operator==(t); } -friend std::istream& operator>> <> (std::istream&, Segment_d&); -friend std::ostream& operator<< <> (std::ostream&, const Segment_d&); +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS +(std::istream&, Segment_d&); +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS +(std::ostream&, const Segment_d&); }; // end of class diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Sphere_d.h b/Packages/Kernel_d/include/CGAL/Kernel_d/Sphere_d.h index 3c0057635c2..1cff4db2fca 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Sphere_d.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Sphere_d.h @@ -37,7 +37,8 @@ class Sphere_d_rep : public Ref_counted { typedef typename R::Point_d Point_d; friend class Sphere_d; - friend bool equal_as_sets <> (const Sphere_d&, const Sphere_d&); + friend bool equal_as_sets CGAL_NULL_TMPL_ARGS + (const Sphere_d&, const Sphere_d&); std::vector< Point_d > P; // d+1 defining points, index range 0-d Orientation orient; // orientation(P) @@ -156,9 +157,28 @@ non-zero or if they are all equal.}*/ return true; } -Point_d center() const; +Point_d center() const /*{\Mop returns the center of |\Mvar|. \precond The orientation of |\Mvar| is non-zero. }*/ +{ + if (ptr->cp == 0) { + if (ptr->orient == 0) { + const std::vector< Point_d >& A = ptr->P; + Point_d po = A[0]; + for (int i = 1; i < int(A.size()); ++i) + if (A[i] != po) + CGAL_assertion_msg(0,"Sphere_d::center(): points are illegal."); + ptr->cp = new Point_d(A[0]); + return *(ptr->cp); + } + typename R::Center_of_sphere_d center_of_sphere_; + ptr->cp = new Point_d(center_of_sphere_(points_begin(),points_end())); + } + return *(ptr->cp); +} + + + FT squared_radius() const /*{\Mop returns the squared radius of the sphere.}*/ { if (is_degenerate()) return 0; @@ -302,28 +322,6 @@ center. We may tentatively assume that $c_d = 1$, solve the corresponding linear system, and then define the center. */ - -template -typename R::Point_d -Sphere_d::center() const -{ - if (ptr->cp == 0) { - if (ptr->orient == 0) { - const std::vector< Point_d >& A = ptr->P; - Point_d po = A[0]; - for (int i = 1; i < int(A.size()); ++i) - if (A[i] != po) - CGAL_assertion_msg(0,"Sphere_d::center(): points are illegal."); - ptr->cp = new Point_d(A[0]); - return *(ptr->cp); - } - typename R::Center_of_sphere_d center_of_sphere; - ptr->cp = new Point_d(center_of_sphere(points_begin(),points_end())); - } - return *(ptr->cp); -} - - CGAL_END_NAMESPACE #endif // CGAL_SPHERE_D_H diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Tuple_d.h b/Packages/Kernel_d/include/CGAL/Kernel_d/Tuple_d.h index d8ad61832b0..f2f8a5403d8 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Tuple_d.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Tuple_d.h @@ -135,11 +135,16 @@ public: Tuple_d(const NT& a, const NT& b, const NT& c, const NT& d) : v(4) { v[0]=a; v[1]=b; v[2]=c; v[3]=d; } +#ifndef CGAL_SIMPLE_INTERFACE + template - Tuple_d(int d, I start, I end) : v(d) + Tuple_d(int d, I& start, I end) : v(d) { int i(0); while ( i < d && start != end ) v[i++] = *start++; - } + } + /* this constructor returns the final position of start + to offer access to a possible common denominator as + part of the tuple range */ template Tuple_d(int d, I start, I end, NT D) : v(d) @@ -148,8 +153,20 @@ public: v[d-1] = D; } - // Tuple_d(const Self& t) : v(t.v) {} - // Self& operator=(const Self& t) { v.operator=(t.v); return *this; } +#else // provide instantiated constructors: +#define FIXTUPLE(I) \ +Tuple_d(int d, I& start, I end) : v(d) \ +{ int i(0); while ( i < d && start != end ) v[i++] = *start++; } \ +Tuple_d(int d, I start, I end, NT D) : v(d) \ +{ int i(0); while ( i < d && start != end ) v[i++] = *start++; v[d-1] = D; } + +FIXTUPLE(int*) +FIXTUPLE(const int*) +FIXTUPLE(NT*) +FIXTUPLE(const NT*) + +#undef FIXTUPLE +#endif int size() const { return v.dimension(); } const_iterator begin() const { return v.begin(); } diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/VectorCd.h b/Packages/Kernel_d/include/CGAL/Kernel_d/VectorCd.h index eaece104132..f171af9d798 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/VectorCd.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/VectorCd.h @@ -67,17 +67,45 @@ friend class HyperplaneCd; VectorCd(int d = 0) : Base( Tuple(d) ) {} VectorCd(int d, Null_vector NULL_VECTOR) : Base( Tuple(d) ) {} +#ifndef CGAL_SIMPLE_INTERFACE + template VectorCd(int d, InputIterator first, InputIterator last) - : Base( Tuple(d,first,last) ) {} + : Base( Tuple(d,first,last) ) +{ if ( first == last ) return; + // else first specifies common denominator: + CGAL_assertion_msg(*first!=FT(0), + "VectorCd::constructor: denominator must be nonzero."); + for (register int i=0; i VectorCd(int d, InputIterator first, InputIterator last, const FT& D) : Base( Tuple(d,first,last) ) -{ CGAL_assertion_msg(D!=0, "VectorCd::constructor: D must be nonzero."); +{ CGAL_assertion_msg(D!=FT(0), "VectorCd::constructor: D must be nonzero."); for (register int i=0; i> <> +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS (std::istream& I, VectorCd& v); -friend std::ostream& operator<< <> +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS (std::ostream& O, const VectorCd& v); }; // end of class VectorCd diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/VectorHd.h b/Packages/Kernel_d/include/CGAL/Kernel_d/VectorHd.h index 59c6db0b9cc..e56c8db33f7 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/VectorHd.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/VectorHd.h @@ -106,6 +106,8 @@ VectorHd(int d, Null_vector NULL_VECTOR) : Base( Tuple(d+1) ) $d$-dimensional space.}*/ { if ( d > 0 ) entry(d) = 1; } +#ifndef CGAL_SIMPLE_INTERFACE + template VectorHd(int d, InputIterator first, InputIterator last) : Base( Tuple(d+1,first,last) ) @@ -117,8 +119,10 @@ homogeneous coordinates $|H = set [first,last)| = (\pm h_0, \pm h_1, \ldots, \precond |d| is nonnegative, |[first,last)| has |d| or |d+1| elements where the last has to be non-zero, and the value type of |InputIterator| is |RT|.}*/ { RT D = entry(d); - CGAL_assertion_msg(D!=0, "VectorHd::constructor: denom must be nonzero."); - if (D < 0) invert_rep(); + CGAL_assertion_msg(first!=last || D!=RT(0), + "VectorHd::constructor: denominator must be nonzero."); + if ( D == RT(0) ) entry(d) = 1; + if ( D < RT(0) ) invert_rep(); } template @@ -130,10 +134,30 @@ coordinates as defined by |H = set [first,last)| and |D|: $(\pm |H[0]|, \pm|H[1]|, \ldots, \pm|H[d-1]|, \pm|D|)$. The sign chosen is the sign of $D$. \precond |D| is non-zero, the iterator range defines a $d$-tuple of |RT|, and the value type of |InputIterator| is |RT|. }*/ -{ CGAL_assertion_msg(D!=0, "VectorHd::constructor: D must be nonzero."); - if (D < 0) invert_rep(); +{ CGAL_assertion_msg(D!=RT(0), "VectorHd::constructor: D must be nonzero."); + if (D < RT(0)) invert_rep(); } +#else +#define FIXVECHD(I) \ +VectorHd(int d, I first, I last) : Base( Tuple(d+1,first,last) ) \ +{ RT D = entry(d); \ + CGAL_assertion_msg(first!=last || D!=RT(0),\ + "VectorHd::constructor: denominator must be nonzero.");\ + if ( D == RT(0) ) entry(d) = 1; if ( D < RT(0) ) invert_rep();\ +} \ +VectorHd(int d, I first, I last, const RT& D):Base(Tuple(d+1,first,last,D))\ +{ CGAL_assertion_msg(D!=RT(0), "VectorHd::constructor: D must be nonzero.");\ + if (D < RT(0)) invert_rep();\ +} + +FIXVECHD(int*) +FIXVECHD(const int*) +FIXVECHD(RT*) +FIXVECHD(const RT*) +#undef FIXVECHD +#endif + VectorHd(Base_vector, int d, int i) : Base( Tuple(d+1) ) /*{\Mcreate returns a variable |\Mvar| of type |\Mname| initialized to the $i$-th base vector of dimension $d$. }*/ @@ -378,9 +402,9 @@ Quotient x() const { return Quotient(hx(),hw());} Quotient y() const { return Quotient(hy(),hw());} Quotient z() const { return Quotient(hz(),hw());} -friend std::istream& operator>> <> +friend std::istream& operator>> CGAL_NULL_TMPL_ARGS (std::istream& I, VectorHd& v); -friend std::ostream& operator<< <> +friend std::ostream& operator<< CGAL_NULL_TMPL_ARGS (std::ostream& O, const VectorHd& v); }; // end of class VectorHd diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/Vector_d.h b/Packages/Kernel_d/include/CGAL/Kernel_d/Vector_d.h index 9f44eafdbfb..002e75dc831 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/Vector_d.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/Vector_d.h @@ -34,6 +34,7 @@ class Vector_d : public pR::Vector_d_base typedef typename R::RT RT; typedef typename R::FT FT; typedef typename R::LA LA; + typedef typename Base::Base_vector Base_vector; Vector_d(int d=0) : Base(d) {} Vector_d(int d, Null_vector v) : Base(d,v) {} @@ -43,8 +44,10 @@ class Vector_d : public pR::Vector_d_base Vector_d(int a, int b, int c, int d) : Base(a,b,c,d) {} Vector_d(const RT& a, const RT& b, const RT& c, const RT& d) : Base(a,b,c,d) {} - Vector_d(typename Base::Base_vector, int d, int i) : - Base(typename Base::Base_vector(), d,i) {} + Vector_d(Base_vector, int d, int i) : + Base(Base_vector(), d,i) {} + +#ifndef CGAL_SIMPLE_INTERFACE template Vector_d (int d, InputIterator first, InputIterator last) @@ -52,6 +55,19 @@ class Vector_d : public pR::Vector_d_base template Vector_d (int d, InputIterator first, InputIterator last, const RT& D) : Base (d, first, last, D) {} + +#else +#define FIXVECD(I) \ +Vector_d (int d, I first, I last) : Base (d, first, last) {} \ +Vector_d(int d, I first, I last, const RT& D) : Base (d, first, last, D) {} + +FIXVECD(int*) +FIXVECD(const int*) +FIXVECD(RT*) +FIXVECD(const RT*) +#undef FIXVECD +#endif + Vector_d(const Self& v) : Base(v) {} Vector_d(const Base& v) : Base(v) {} diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/function_objectsCd.h b/Packages/Kernel_d/include/CGAL/Kernel_d/function_objectsCd.h index 76bbb43c383..9a617bdd2ea 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/function_objectsCd.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/function_objectsCd.h @@ -139,7 +139,7 @@ bool operator()(const Point_d& p, const Point_d& s, const Point_d& t, lnum_i = (p.cartesian(i) - s.cartesian(i)); lden_i = (t.cartesian(i) - s.cartesian(i)); if (lnum*lden_i != lnum_i*lden) return false; - if (lden_i != 0) { den = lden_i; num = lnum_i; } + if (lden_i != FT(0)) { den = lden_i; num = lnum_i; } } l = num/den; return true; } @@ -305,7 +305,7 @@ bool operator()(ForwardIterator first, ForwardIterator last, typename LA::Vector lambda; if ( LA::linear_solver(M,b,lambda,D) ) { for (int j = 0; j < k; j++) { - if (lambda[j] < 0) return false; + if (lambda[j] < FT(0)) return false; } return true; } @@ -382,8 +382,9 @@ bool operator()(ForwardIterator first, ForwardIterator last) template struct Compare_lexicographicallyCd { typedef typename R::Point_d Point_d; +typedef typename R::Point_d PointD; //MSVC hack Comparison_result operator()(const Point_d& p1, const Point_d& p2) -{ return Point_d::cmp(p1,p2); } +{ return PointD::cmp(p1,p2); } }; template diff --git a/Packages/Kernel_d/include/CGAL/Kernel_d/function_objectsHd.h b/Packages/Kernel_d/include/CGAL/Kernel_d/function_objectsHd.h index 077be71b107..42982933cec 100644 --- a/Packages/Kernel_d/include/CGAL/Kernel_d/function_objectsHd.h +++ b/Packages/Kernel_d/include/CGAL/Kernel_d/function_objectsHd.h @@ -382,8 +382,9 @@ bool operator()(ForwardIterator first, ForwardIterator last) template struct Compare_lexicographicallyHd { typedef typename R::Point_d Point_d; -Comparison_result operator()(const Point_d& p1, const Point_d& p2) -{ return Point_d::cmp(p1,p2); } +typedef typename R::Point_d PointD; //MSVC hack +Comparison_result operator()(const Point_d& p1, const Point_d& p2) +{ return PointD::cmp(p1,p2); } }; template diff --git a/Packages/Kernel_d/include/CGAL/predicates_d.h b/Packages/Kernel_d/include/CGAL/predicates_d.h index c74597c7253..217611e1d49 100644 --- a/Packages/Kernel_d/include/CGAL/predicates_d.h +++ b/Packages/Kernel_d/include/CGAL/predicates_d.h @@ -77,8 +77,8 @@ This is the sign of the determinant \precond |size [first,last) == d+1| and |A[i].dimension() == d| $\forall 0 \leq i \leq d$ and the value type of |ForwardIterator| is |Point_d|.}*/ -{ typedef typename std::iterator_traits::value_type Point_d; - typedef typename Point_d::R R; +{ typedef typename std::iterator_traits::value_type PointD; + typedef typename PointD::R R; typename R::Orientation_d or_; return or_(first,last); } template @@ -142,8 +142,8 @@ template int affine_rank(ForwardIterator first, ForwardIterator last) /*{\Mfunc computes the affine rank of the points in |A = tuple [first,last)|. \precond value type of |ForwardIterator| is |Point_d|.}*/ -{ typedef typename std::iterator_traits::value_type Point_d; - typedef typename Point_d::R R; +{ typedef typename std::iterator_traits::value_type PointD; + typedef typename PointD::R R; typename R::Affine_rank_d rank; return rank(first,last); } @@ -152,8 +152,8 @@ bool affinely_independent(ForwardIterator first, ForwardIterator last) /*{\Mfunc decides whether the points in |A = tuple [first,last)| are affinely independent. \precond value type of |ForwardIterator| is |Point_d|.}*/ -{ typedef typename std::iterator_traits::value_type Point_d; - typedef typename Point_d::R R; +{ typedef typename std::iterator_traits::value_type PointD; + typedef typename PointD::R R; typename R::Affinely_independent_d ind; return ind(first,last); } diff --git a/Packages/Kernel_d/noweb/Aff_transformationHd.lw b/Packages/Kernel_d/noweb/Aff_transformationHd.lw index b9326109037..be9c101afb7 100644 --- a/Packages/Kernel_d/noweb/Aff_transformationHd.lw +++ b/Packages/Kernel_d/noweb/Aff_transformationHd.lw @@ -315,11 +315,11 @@ Aff_transformationHd(int d, const DirectionHd& dir, lower_ok = (common_part + diff_part > rhs); if ( lower_ok && upper_ok ) { - if ( CGAL_NTS square(p)%2 + CGAL_NTS square(q)%2 > 1) { + if ( CGAL_NTS square(p)%RT(2) + CGAL_NTS square(q)%RT(2) > 1) { sin = p*q; - cos = (CGAL_NTS square(q) - CGAL_NTS square(p))/2; + cos = (CGAL_NTS square(q) - CGAL_NTS square(p))/RT(2); // exact division - denom = (CGAL_NTS square(p) + CGAL_NTS square(q))/2; + denom = (CGAL_NTS square(p) + CGAL_NTS square(q))/RT(2); // exact division } else { cos = CGAL_NTS square(q) - CGAL_NTS square(p); diff --git a/Packages/Kernel_d/noweb/HyperplaneHd.lw b/Packages/Kernel_d/noweb/HyperplaneHd.lw deleted file mode 100644 index a2414422c21..00000000000 --- a/Packages/Kernel_d/noweb/HyperplaneHd.lw +++ /dev/null @@ -1,545 +0,0 @@ -\documentclass[a4paper,11pt,twoside]{article} -\usepackage{Lweb} - -\begin{document} -\title{Hyperplanes with Rational Coordinates in d-Space\\ -(class HyperplaneHd)} -\author{M. Seel} -\date{\today} -\maketitle -\tableofcontents -\newpage - -@ \section{The Manual Page of class HyperplaneHd} - -\input HyperplaneHd.man - -@ \section{The Implementation of class HyperplaneHd} - -The type HyperplaneHd is an item class with representation class georep. It -shares this representation class with points, vectors, and -directions. We derive HyperplaneHd from handle\_base and derive georep from -handle\_rep. This gives us reference counting for free. We give all -implementations which are trivial directly in the header file and -postpone all others to the next section. Aside from this the header -file is in one-to-one correspondence to the manual page. - -<>= -// ====================================================================== -// -// Copyright (c) 2000,2001 The CGAL Consortium -// -// This software and related documentation is part of an INTERNAL release -// of the Computational Geometry Algorithms Library (CGAL). It is not -// intended for general use. -// -// ---------------------------------------------------------------------- -// -// release : $CGAL_Revision$ -// release_date : $CGAL_Date$ -// -// file : include/CGAL/Kernel_d/HyperplaneHd.h -// package : Kernel_d -// maintainer : Michael Seel -// revision : $Revision$ -// revision_date : $Date$ -// author(s) : Michael Seel -// coordinator : MPI Saarbruecken (Susan.Hert@mpi-sb.mpg.de) -// -// ====================================================================== -//--------------------------------------------------------------------- -// file generated by notangle from HyperplaneHd.lw -// please debug or modify noweb file -// coding: K. Mehlhorn, M. Seel -//--------------------------------------------------------------------- - -#ifndef CGAL_HYPERPLANEHD_H -#define CGAL_HYPERPLANEHD_H - -#ifndef NOCGALINCL -#include -#include -#endif -#include -#include -#include - -CGAL_BEGIN_NAMESPACE - -<> -<> - -CGAL_END_NAMESPACE -#endif // CGAL_HYPERPLANEHD_H - -<>= -// ====================================================================== -// -// Copyright (c) 2001 The CGAL Consortium -// -// This software and related documentation is part of an INTERNAL release -// of the Computational Geometry Algorithms Library (CGAL). It is not -// intended for general use. -// -// ---------------------------------------------------------------------- -// -// release : $CGAL_Revision: CGAL-2.3-I-67 $ -// release_date : $CGAL_Date: 2001/05/29 $ -// -// file : include/CGAL/Kernel_d/HyperplaneCd.C -// package : Kernel_d (0.9.19) -// maintainer : Michael Seel -// author(s) : Michael Seel -// coordinator : Susan Hert -// -// ====================================================================== -//--------------------------------------------------------------------- -// file generated by notangle from HyperplaneHd.lw -// please debug or modify noweb file -// coding: K. Mehlhorn, M. Seel -//--------------------------------------------------------------------- -#ifndef CGAL_HYPERPLANEHD_C -#define CGAL_HYPERPLANEHD_C -CGAL_BEGIN_NAMESPACE - -<> - -CGAL_END_NAMESPACE -#endif // CGAL_HYPERPLANEHD_C - - -@ \subsection{The Datatype} -And now for the class definition. We interleave the prototyping and -the implementation. -<>= -/*{\Manpage{Hyperplane_d}{R}{Hyperplanes in d-space}{h}}*/ -/*{\Msubst -Hd#_d -HyperplaneHd#Hyperplane_d -Quotient#FT -}*/ - -template -class HyperplaneHd : public Handle_for< Tuple_d<_RT,_LA> > { - typedef Tuple_d<_RT,_LA> Tuple; - typedef Handle_for Base; - typedef HyperplaneHd<_RT,_LA> Self; - -/*{\Mdefinition An instance of data type |HyperplaneHd| is an -oriented hyperplane in $d$ - dimensional space. A hyperplane $h$ is -represented by coefficients $(c_0,c_1,\ldots,c_d)$ of type |RT|. At -least one of $c_0$ to $c_{ d - 1 }$ must be non-zero. The plane -equation is $\sum_{ 0 \le i < d } c_i x_i + c_d = 0$, where $x_0$ to -$x_{d-1}$ are Cartesian point coordinates. -For a particular $x$ the sign of $\sum_{ 0 \le i < d } c_i x_i + -c_d$ determines the position of a point $x$ with respect to the -hyperplane (on the hyperplane, on the negative side, or on the -positive side). - -There are two equality predicates for hyperplanes. The (weak) -equality predicate (|weak_equality|) declares two hyperplanes equal if -they consist of the same set of points, the strong equality predicate -(|operator==|) requires in addition that the negative halfspaces -agree. In other words, two hyperplanes are strongly equal if their -coefficient vectors are positive multiples of each other and they are -(weakly) equal if their coefficient vectors are multiples of each -other.}*/ - -const typename _LA::Vector& vector_rep() const { return ptr->v; } -_RT& entry(int i) const { return ptr->v[i]; } -void invert_rep() { ptr->invert(); } - -public: -/*{\Mtypes 4}*/ - -typedef _RT RT; -/*{\Mtypemember the ring type.}*/ -typedef Quotient<_RT> FT; -/*{\Mtypemember the field type.}*/ -typedef _LA LA; -/*{\Mtypemember the linear algebra layer.}*/ -typedef typename Tuple::const_iterator Coefficient_const_iterator; -/*{\Mtypemember a read-only iterator for the coefficients.}*/ - -/*{\Mcreation h 4}*/ - -/*{\Moptions nextwarning=no}*/ -HyperplaneHd(int d = 0) : Base( Tuple(d+1) ) {} -/*{\Mcreate introduces a variable |\Mvar| of type |\Mname| -initialized to some hyperplane in $d$ - dimensional space. }*/ - -template -HyperplaneHd(int d, InputIterator first, InputIterator last, RT D) - : Base( Tuple(d+1,first,last,D) ) {} -/*{\Mcreate introduces a variable |\Mvar| of type |\Mname| -initialized to the hyperplane with coefficients |set [first,last)| and -|D|. \precond |size [first,last) == d| and the value type of -InputIterator is |RT|.}*/ - -template -HyperplaneHd(int d, InputIterator first, InputIterator last) - : Base( Tuple(d+1,first,last) ) {} -/*{\Mcreate introduces a variable |\Mvar| of type |\Mname| -initialized to the hyperplane with coefficients |set [first,last)|. -\precond |size [first,last) == d+1| and the value type of -InputIterator is |RT|.}*/ - -template -HyperplaneHd(ForwardIterator first, ForwardIterator last, - const PointHd& o, - Oriented_side side = Oriented_side(0)) -/*{\Mcreate constructs some hyperplane that passes through the points -in |set [first,last)|. If |side| is |ON_POSITIVE_SIDE| or -|ON_NEGATIVE_SIDE| then |o| is on that side of the constructed -hyperplane. \precond A hyperplane with the stated properties must -exist. The value type of |ForwardIterator| is |PointHd|. }*/ - -@ We want to construct a hyperplane that passes through a set |P = set -[first,last)| of points in $d$-dimensional space and has a specified -point $o$ on a specified side. We simply have to find a vector $x$ -such that $P^T \cdot x = 0$ for every point in $P$. This amounts to -solving a homogeneous linear system. If the system has only a trivial -solution the task at hand is unsolvable and we report an error. So -assume that the system has a non-trivial solution. Let vectors $s_1, -\ldots, s_k$ span the solution space. if |side == ZERO| we may take -any $s_j$ as the normal vector of our hyperplane. if $|side| \neq 0$ -and the task at hand is solvable there must be a $j$ such that $o^T -\cdot s_j \neq 0$. We take $s_j$ as the normal vector of our -hyperplane and use |o| to normalize the hyperplane equation. -<>= - : Base( Tuple(o.dimension()+1) ) { - TUPLE_DIM_CHECK(first,last,hyperplane::construction); - CGAL_assertion_msg((first->dimension()==o.dimension()), - "hyperplane::construction: dimensions disagree."); - - int d = first->dimension(); // we are in $d$ - dimensional space - int m = std::distance(first,last); // |P| has $m$ points - typename LA::Matrix A(m,d + 1); - - for (int i = 0; i < m; i++) { /* define $i$-th equation */ - for (int j = 0; j <= d; j++) - A(i,j) = first->homogeneous(j); // $j$ - th coord of $i$-th point - ++first; - } - typename LA::Matrix spanning_vecs; // columns span solution - int dim = LA::homogeneous_linear_solver(A,spanning_vecs); - - if (dim == 0) - CGAL_assertion_msg(0,"HyperplaneHd::constructor: \ - set P is full dimensional."); - - if (side == ON_ORIENTED_BOUNDARY) { - ptr->v = spanning_vecs.column(0); - return; - } - - RT sum = 0; - int j; - for (j = 0; j < dim; j++) { - for (int i = 0; i <= d; i++) - sum += spanning_vecs(i,j)*o.homogeneous(i); - if (sum != 0) break; - } - - if (j == dim) - CGAL_assertion_msg(0,"HyperplaneHd::constructor: \ - cannot use o to determine side."); - - ptr->v = spanning_vecs.column(j); - if ( CGAL_NTS sign(sum) > 0 && side == ON_NEGATIVE_SIDE || - CGAL_NTS sign(sum) < 0 && side == ON_POSITIVE_SIDE) - invert_rep(); -} - -HyperplaneHd(const PointHd& p, const DirectionHd& dir) -/*{\Mcreate constructs the hyperplane with normal direction |dir| -that passes through $p$. The direction |dir| points into the positive -side. \precond |dir| is not the trivial direction.}*/ -@ Given a point |p| and a direction |dir| we want to construct a hyperplane -with normal direction |dir| and passing through |p|. We set the coefficient -vector $x = (|dir|_0, \ldots,|dir|_{d-1},D)$ for some unknown $D$ and then -use |p| to determine $D$ such that $p^T \cdot x = 0$. -Note that $D$ will be rational in general. -<>= - : Base( Tuple(p.dimension()+1) ) { - int d = p.dimension(); - CGAL_assertion_msg((dir.dimension() == d), "HyperplaneHd::constructor: \ - parameter dimensions disagree."); - CGAL_assertion_msg((dir.dimension() == d), "HyperplaneHd::constructor: \ - parameter dimensions disagree."); - - RT sum = 0; - for (int i = 0; i < d; i++) { - sum += dir.delta(i)*p.homogeneous(i); - entry(i) = dir.delta(i)*p.homogeneous(d); - } - entry(d) = -sum; -} - -HyperplaneHd(const RT& a, const RT& b, const RT& c) : - Base( Tuple(a,b,c) ) {} -/*{\Mcreate introduces a variable |\Mvar| of type |\Mname| in -$2$-dimensional space with equation $ax+by+c=0$. }*/ - -HyperplaneHd(int a, int b, int c) : - Base( Tuple(RT(a),RT(b),RT(c)) ) {} - -HyperplaneHd(const RT& a, const RT& b, const RT& c, const RT& d) : - Base( Tuple(a,b,c,d) ) {} -/*{\Mcreate introduces a variable |\Mvar| of type |\Mname| in -$3$-dimensional space with equation $ax+by+cz+d=0$. }*/ - -HyperplaneHd(int a, int b, int c, int d) : - Base( Tuple(RT(a),RT(b),RT(c),RT(d)) ) {} - -HyperplaneHd(const HyperplaneHd& h) : Base(h) {} -~HyperplaneHd() {} - -/*{\Moperations 4 2}*/ - -int dimension() const { return ptr->size()-1; } -/*{\Mop returns the dimension of |\Mvar|. }*/ - -RT operator[](int i) const -/*{\Marrop returns the $i$-th coefficient of |\Mvar|. - \precond $0 \leq i \leq d$.}*/ -{ CGAL_assertion_msg((0<=i && i<=(dimension())), "HyperplaneHd::op[]:\ - index out of range."); return entry(i); } - -RT coefficient(int i) const { return entry(i); } -/*{\Mop returns the $i$-th coefficient of |\Mvar|. - \precond $0 \leq i \leq d$.}*/ - -const typename LA::Vector& coefficient_vector() const -/*{\Xop returns the coefficient vector $(c_0,\ldots,c_d)$ of |\Mvar|. }*/ -{ return vector_rep(); } - -Coefficient_const_iterator coefficients_begin() const -/*{\Mop returns an iterator pointing to the first coefficient.}*/ -{ return ptr->begin(); } - -Coefficient_const_iterator coefficients_end() const -/*{\Mop returns an iterator pointing beyond the last coefficient.}*/ -{ return ptr->end(); } - -VectorHd orthogonal_vector() const; -/*{\Mop returns the orthogonal vector of |\Mvar|. It points from the -negative halfspace into the positive halfspace and its -homogeneous coordinates are $(c_0, \ldots, c_{d - 1},1)$. }*/ -@ Any multiple of $(c_0,\ldots,c_{d-1})$ is a normal vector. We want the -vector to point from the negative to the positive halfspace. Recall -that our hyperplane has the equation $c_d + \sum (c_i z_i) = 0$, where -the $z_i$ are Cartesian point coordinates. The point $z = -c_d\cdot -c/{\parallel c \parallel}$ is on the hyperplane, the point $z_n = (-1 --c_d)\cdot c/{\parallel c \parallel}$ is in the negative halfspace and -the point $z_p = (1 - c_d)\cdot c/{\parallel c \parallel}$ is in the -positive halfspace. Thus any positive multiple of $c$ is the desired -orthogonal vector. We take $(c_0,\ldots,c_{d-1},1)$. -<>= -template -VectorHd HyperplaneHd:: -orthogonal_vector() const -{ VectorHd res(*this); - res.copy_on_write(); - res.entry(dimension()) = 1; - return res; -} - -<>= -DirectionHd orthogonal_direction() const -/*{\Mop returns the orthogonal direction of |\Mvar|. It points from the -negative halfspace into the positive halfspace. }*/ -{ return orthogonal_vector().direction(); } - -RT value_at(const PointHd& p) const -/*{\Xop returns the value of |\Mvar| at the point |p|, i.e., -$\sum_{ 0 \le i \le d } h_i p_i$.\\ -Warning: this value depends on the particular representation -of |\Mvar| and |p|. }*/ -{ CGAL_assertion_msg((dimension()==p.dimension()),"HyperplaneHd::value_at:\ - dimensions disagree."); - return vector_rep()*p.vector_rep(); -} - -Oriented_side oriented_side(const PointHd& p) const -/*{\Mop returns the side of the hyperplane |\Mvar| containing $p$. }*/ -/*{\Mtext \setopdims{2cm}{2cm}}*/ -{ - CGAL_assertion_msg((dimension()==p.dimension()), - "HyperplaneHd::oriented_side: dimensions do not agree."); - return Oriented_side(CGAL_NTS sign(value_at(p))); -} - -bool has_on(const PointHd& p) const -/*{\Mop returns true iff point |p| lies on the hyperplane |\Mvar|. }*/ -{ return (oriented_side(p) == ON_ORIENTED_BOUNDARY); } - -bool has_on_boundary(const PointHd& p) const -/*{\Mop returns true iff point |p| lies on the boundary of -hyperplane |\Mvar|. }*/ -{ return (oriented_side(p) == ON_ORIENTED_BOUNDARY); } - -bool has_on_positive_side(const PointHd& p) const -/*{\Mop returns true iff point |p| lies on the positive side of -hyperplane |\Mvar|. }*/ -{ return (oriented_side(p) == ON_POSITIVE_SIDE); } - -bool has_on_negative_side(const PointHd& p) const -/*{\Mop returns true iff point |p| lies on the negative side of -hyperplane |\Mvar|. }*/ -{ return (oriented_side(p) == ON_NEGATIVE_SIDE); } - -/*{\Mtext \restoreopdims }*/ - -HyperplaneHd transform(const Aff_transformationHd& t) const -/*{\Mop returns $t(h)$.}*/ -{ typename LA::Vector res = - -(LA::transpose(t.inverse().matrix()) * vector_rep()); - return HyperplaneHd(dimension(),res.begin(),res.end()); } - -/*{\Mtext \headerline{Non-Member Functions}}*/ - -static Comparison_result weak_cmp( - const HyperplaneHd&, const HyperplaneHd&); - -@ Weak equality considers two hyperplanes equal if their coefficient -vectors are multiples of each other. We define the weak linear order -as the lexicographic order under weak equality. Let $i$ be minimal -such that either $h1_i$ or $h2_i$ is non-zero. We may assume that a -non-zero value is positive (since we consider weak equality). Thus if -exactly one of the vlaue is non-zero, we can decide the order right -there: The vector with the entry zero is smaller. If both entries are -non-zero, we compute scaling factors that make the $i$-th coefficients -equal and positive and proceed. -<>= -template -Comparison_result HyperplaneHd:: -weak_cmp(const HyperplaneHd& h1, - const HyperplaneHd& h2) -{ - CGAL_assertion_msg((h1.dimension()==h2.dimension()), - "HyperplaneHd::weak_cmp: dimensions disagree."); - if(h1.identical(h2)) return EQUAL; - - int i, d = h1.dimension(); - for (i = 0; i <= d && - h1.coefficient(i) == 0 && - h2.coefficient(i) == 0; i++); // no body - if (h1.coefficient(i) == 0) return SMALLER; - if (h2.coefficient(i) == 0) return LARGER; - - int s = CGAL_NTS sign(h1.coefficient(i)) * - CGAL_NTS sign(h2.coefficient(i)); - RT s1 = (RT)s * h2.coefficient(i); - RT s2 = (RT)s * h1.coefficient(i); - // |s1 * h1.coefficient(i)| is - // $\Labs{ |h1.coefficient(i)*h2.coefficient(i)| }$ - - Comparison_result c; - while (++i <= d) { - c = CGAL_NTS compare(s1 * h1.coefficient(i), - s2 * h2.coefficient(i)); - if (c != EQUAL) return c; - } - return EQUAL; -} - -<>= -static Comparison_result strong_cmp( - const HyperplaneHd&, const HyperplaneHd&); -@ Strong equality considers two hyperplanes equal if their coefficient -vectors are positive multiples of each other. We define the strong -linear order as the lexicographic order under strong equality. Let $i$ -be minimal such that either $h1_i$ or $h2_i$ is non-zero. If the -values have different signs we can decide the order right there: The -vector with the smaller entry is smaller. If the entries have the -same sign we compute positive scaling factors that make the $i$-th -coefficients equal and proceed. -<>= -template -Comparison_result HyperplaneHd:: -strong_cmp(const HyperplaneHd& h1, - const HyperplaneHd& h2) -{ - CGAL_assertion_msg((h1.dimension()==h2.dimension()), - "HyperplaneHd::strong_cmp: dimensions disagree."); - if (h1.identical(h2)) return EQUAL; - - int i; - int d = h1.dimension(); - for (i = 0; i <=d && - h1.coefficient(i)==0 && - h2.coefficient(i)==0; i++) ; // no body - int c1 = CGAL_NTS sign(h1.coefficient(i)); - int c2 = CGAL_NTS sign(h2.coefficient(i)); - if (c1 != c2) return CGAL_NTS compare(c1,c2); - RT s1 = (RT)CGAL_NTS sign(h2.coefficient(i)) * h2.coefficient(i); - RT s2 = (RT)CGAL_NTS sign(h1.coefficient(i)) * h1.coefficient(i); - - Comparison_result c; - while (++i <= d) { - c = CGAL_NTS compare(s1 * h1.coefficient(i), - s2 * h2.coefficient(i)); - if (c != EQUAL) return c; - } - return EQUAL; -} - -<>= - -bool operator==(const HyperplaneHd& h2) const -{ if (identical(h2)) return true; - if (dimension()!=h2.dimension()) return false; - return HyperplaneHd::strong_cmp(*this,h2) == EQUAL; -} - -bool operator!=(const HyperplaneHd& h2) const -{ return !operator==(h2); } - -friend std::istream& operator>> <> - (std::istream&, HyperplaneHd&); -friend std::ostream& operator<< <> - (std::ostream&, const HyperplaneHd&); - -}; // end of class HyperplaneHd - -template -bool weak_equality(const HyperplaneHd& h1, - const HyperplaneHd& h2) -/*{\Mfunc test for weak equality. }*/ -{ if (h1.identical(h2)) return true; - if (h1.dimension()!=h2.dimension()) return false; - return HyperplaneHd::weak_cmp(h1,h2) == EQUAL; -} - -<>= -template -std::istream& operator>>(std::istream&, HyperplaneHd&); -template -std::ostream& operator<<(std::ostream&, const HyperplaneHd&); - -<>= -template -std::istream& operator>>(std::istream& I, HyperplaneHd& h) -{ h.copy_on_write(); h.ptr->read(I); return I; } - -template -std::ostream& operator<<(std::ostream& O, const HyperplaneHd& h) -{ h.ptr->print(O,"HyperplaneHd"); return O; } - -template -inline CGAL::io_Operator io_tag(const HyperplaneHd&) -{ return CGAL::io_Operator(); } - -<>= -/*{\Mimplementation -Hyperplanes are implemented by arrays of integers as an item type. -All operations like creation, initialization, tests, vector -arithmetic, input and output on a hyperplane $h$ take time -$O(|h.dimension()|)$. coordinate access and |dimension()| take -constant time. The space requirement is $O(|h.dimension()|)$. }*/ - -//----------------------- end of file ---------------------------------- - - -@ \end{document} diff --git a/Packages/Kernel_d/noweb/Kernel_d-tests.lw b/Packages/Kernel_d/noweb/Kernel_d-tests.lw index 54a6052f741..1d514ba56ca 100644 --- a/Packages/Kernel_d/noweb/Kernel_d-tests.lw +++ b/Packages/Kernel_d/noweb/Kernel_d-tests.lw @@ -15,20 +15,33 @@ #ifdef CGAL_USE_LEDA #include -#include -typedef leda_integer RT; -typedef leda_real FT; +#include +typedef leda_integer RT_; +typedef leda_rational FT_; #else #ifdef CGAL_USE_GMP #include -typedef CGAL::Gmpz RT; -typedef double FT; +#include +typedef CGAL::Gmpz RT_; +typedef CGAL::Quotient FT_; #else -typedef double RT; -typedef double FT; +typedef double RT_; +typedef double FT_; #endif #endif +#ifdef _MSC_VER +typedef CGAL::Homogeneous_d HKernel; +typedef CGAL::Point_d HPNT; +typedef CGAL::Vector_d HVEC; +typedef CGAL::Cartesian_d CKernel; +typedef CGAL::Point_d CPNT; +typedef CGAL::Vector_d CVEC; +CGAL_DEFINE_ITERATOR_TRAITS_POINTER_SPEC(HPNT) +CGAL_DEFINE_ITERATOR_TRAITS_POINTER_SPEC(HVEC) +CGAL_DEFINE_ITERATOR_TRAITS_POINTER_SPEC(CPNT) +CGAL_DEFINE_ITERATOR_TRAITS_POINTER_SPEC(CVEC) +#endif int main() { SETDTHREAD(2); @@ -46,8 +59,9 @@ int main() } <>= -typedef CGAL::Homogeneous_d Kernel; -typedef Kernel::FT NT; +typedef CGAL::Homogeneous_d Kernel; +typedef Kernel::RT RT; +typedef Kernel::FT FT; typedef Kernel::LA LA; typedef CGAL::Point_d Point; typedef CGAL::Vector_d Vector; @@ -61,8 +75,9 @@ typedef LA::Vector IVector; bool DOIO=true; <>= -typedef CGAL::Cartesian_d Kernel; -typedef Kernel::FT NT; +typedef CGAL::Cartesian_d Kernel; +typedef Kernel::FT FT; +typedef Kernel::RT RT; typedef Kernel::LA LA; typedef CGAL::Point_d Point; typedef CGAL::Vector_d Vector; @@ -104,18 +119,20 @@ bool DOIO=false; CGAL_TEST(p4.dimension()!=Point(3).dimension()); // dimension() /* some input and access test */ - CGAL_TEST(p1.hx()==1 && p1.hy()==0 && p1.hw()!=0); // hx,hy,hw + CGAL_TEST(p1.hx()==RT(1) && p1.hy()==RT(0) && p1.hw()!=RT(0)); CGAL_TEST(p1.hx()==p1.homogeneous(0) && p1.hy()==p1.homogeneous(1) && p1.hw()==p1.homogeneous(2)); // hx,hy,hw - CGAL_TEST(p1.x()==NT(1) && p1.y()==NT(0)); // x(),y() + CGAL_TEST(p1.x()==FT(1) && p1.y()==FT(0)); // x(),y() CGAL_TEST(p1.x()==p1[0] && p1.y()==p1[1]); // x(),y() CGAL_TEST(p1.x()==p1.cartesian(0) && p1.y()==p1.cartesian(1)); // x(),y() - IVector iv3(p1.homogeneous_begin(),p1.homogeneous_end()); - CGAL_TEST(iv1==iv3); + Point::Homogeneous_const_iterator hcit; int i; + for (i=0, hcit = p1.homogeneous_begin(); + hcit != p1.homogeneous_end(); ++i, ++hcit) + CGAL_TEST(*hcit == iv1[i]); Point::Homogeneous_const_iterator hit; - Point::Cartesian_const_iterator cit; int i; + Point::Cartesian_const_iterator cit; for (i=0,hit=p1.homogeneous_begin(),cit=p1.cartesian_begin(); i0); + CGAL_TEST(h2.value_at(o)FT(0)); CGAL_TEST(h2.oriented_side(o)==CGAL::ON_NEGATIVE_SIDE); CGAL_TEST(h2.oriented_side(p3)==CGAL::ON_ORIENTED_BOUNDARY); CGAL_TEST(h2.oriented_side(p3+dir.vector())==CGAL::ON_POSITIVE_SIDE); @@ -516,7 +533,7 @@ components. s6 = Segment(Point(0,0),Point(10,10)); Point p3(10,0); - CGAL_TEST(s6.squared_length()==NT(200)); + CGAL_TEST(s6.squared_length()==FT(200)); CGAL_TEST(s6.has_on(Point(5,5))); CGAL_TEST(Segment(Point(1,1),Point(1,1)).is_degenerate()); CGAL_TEST(CGAL::weak_equality(s1,s1.opposite())); diff --git a/Packages/Kernel_d/noweb/Makefile b/Packages/Kernel_d/noweb/Makefile index 3babda9a957..1228b53d70f 100644 --- a/Packages/Kernel_d/noweb/Makefile +++ b/Packages/Kernel_d/noweb/Makefile @@ -1,4 +1,3 @@ -HYPERPLANE = HyperplaneHd.h HyperplaneHd.C AFFTRAFO = Aff_transformationHd.h Aff_transformationHd.C PREDS = INTERSECTIONOBJS = intersection_objectsHd.h intersection_objectsCd.h \ @@ -14,9 +13,6 @@ KERNELTESTDIR = ../test/Kernel_d/ tests : $(KERNELTESTS) cp $(KERNELTESTS) $(KERNELTESTDIR) -hyperplane : $(HYPERPLANE) - cp $(HYPERPLANE) $(KERNELSUB) - intobjs : $(INTERSECTIONOBJS) cp $(INTERSECTIONOBJS) $(KERNELSUB) @@ -38,9 +34,6 @@ function_objectsHd.h : function_objectsHd.lw function_objectsCd.h : function_objectsCd.lw notangle -R$@ $< > $@ -$(HYPERPLANE) : HyperplaneHd.lw - notangle -R$@ $< > $@ - $(AFFTRAFO) : Aff_transformationHd.lw notangle -R$@ $< > $@ diff --git a/Packages/Kernel_d/noweb/function_objectsCd.lw b/Packages/Kernel_d/noweb/function_objectsCd.lw index 9f90e5e5a84..e7fd6ecfe65 100644 --- a/Packages/Kernel_d/noweb/function_objectsCd.lw +++ b/Packages/Kernel_d/noweb/function_objectsCd.lw @@ -143,7 +143,7 @@ bool operator()(const Point_d& p, const Point_d& s, const Point_d& t, lnum_i = (p.cartesian(i) - s.cartesian(i)); lden_i = (t.cartesian(i) - s.cartesian(i)); if (lnum*lden_i != lnum_i*lden) return false; - if (lden_i != 0) { den = lden_i; num = lnum_i; } + if (lden_i != FT(0)) { den = lden_i; num = lnum_i; } } l = num/den; return true; } @@ -396,7 +396,7 @@ bool operator()(ForwardIterator first, ForwardIterator last, typename LA::Vector lambda; if ( LA::linear_solver(M,b,lambda,D) ) { for (int j = 0; j < k; j++) { - if (lambda[j] < 0) return false; + if (lambda[j] < FT(0)) return false; } return true; } @@ -501,8 +501,9 @@ lexicographically. template struct Compare_lexicographicallyCd { typedef typename R::Point_d Point_d; +typedef typename R::Point_d PointD; //MSVC hack Comparison_result operator()(const Point_d& p1, const Point_d& p2) -{ return Point_d::cmp(p1,p2); } +{ return PointD::cmp(p1,p2); } }; @ \section{Predicates on Vectors} diff --git a/Packages/Kernel_d/noweb/function_objectsHd.lw b/Packages/Kernel_d/noweb/function_objectsHd.lw index 10f7c5e8ea6..a8c9916673a 100644 --- a/Packages/Kernel_d/noweb/function_objectsHd.lw +++ b/Packages/Kernel_d/noweb/function_objectsHd.lw @@ -505,8 +505,9 @@ lexicographically. template struct Compare_lexicographicallyHd { typedef typename R::Point_d Point_d; -Comparison_result operator()(const Point_d& p1, const Point_d& p2) -{ return Point_d::cmp(p1,p2); } +typedef typename R::Point_d PointD; //MSVC hack +Comparison_result operator()(const Point_d& p1, const Point_d& p2) +{ return PointD::cmp(p1,p2); } }; @ \section{Predicates on Vectors} diff --git a/Packages/Kernel_d/test/Kernel_d/Linear_algebra-test.C b/Packages/Kernel_d/test/Kernel_d/Linear_algebra-test.C index 525fbdf930b..22a1eb73c28 100644 --- a/Packages/Kernel_d/test/Kernel_d/Linear_algebra-test.C +++ b/Packages/Kernel_d/test/Kernel_d/Linear_algebra-test.C @@ -20,8 +20,8 @@ typedef double RT; #endif #ifdef CGAL_USE_LEDA -#include -typedef leda_real FT; +#include +typedef leda_rational FT; #else #ifdef CGAL_USE_GMP #include @@ -368,7 +368,7 @@ int main(int argc, char* argv[]) b[i] = CGAL::default_random.get_int(-mat_dim,mat_dim); } - for (double f = 1.0; f > 0.0; f = f-=0.1) { + for (double f = 1.0; f > 0.0; f-=0.1) { Matrix E = C; for (i = 0; i< mat_dim; ++i) for (j = 0; j < mat_dim; ++j) diff --git a/Packages/Kernel_d/test/Kernel_d/interface-test.C b/Packages/Kernel_d/test/Kernel_d/interface-test.C index 07d50950153..930f9a785dd 100644 --- a/Packages/Kernel_d/test/Kernel_d/interface-test.C +++ b/Packages/Kernel_d/test/Kernel_d/interface-test.C @@ -14,28 +14,42 @@ #ifdef CGAL_USE_LEDA #include -#include -typedef leda_integer RT; -typedef leda_real FT; +#include +typedef leda_integer RT_; +typedef leda_rational FT_; #else #ifdef CGAL_USE_GMP #include -typedef CGAL::Gmpz RT; -typedef double FT; +#include +typedef CGAL::Gmpz RT_; +typedef CGAL::Quotient FT_; #else -typedef double RT; -typedef double FT; +typedef double RT_; +typedef double FT_; #endif #endif +#ifdef _MSC_VER +typedef CGAL::Homogeneous_d HKernel; +typedef CGAL::Point_d HPNT; +typedef CGAL::Vector_d HVEC; +typedef CGAL::Cartesian_d CKernel; +typedef CGAL::Point_d CPNT; +typedef CGAL::Vector_d CVEC; +CGAL_DEFINE_ITERATOR_TRAITS_POINTER_SPEC(HPNT) +CGAL_DEFINE_ITERATOR_TRAITS_POINTER_SPEC(HVEC) +CGAL_DEFINE_ITERATOR_TRAITS_POINTER_SPEC(CPNT) +CGAL_DEFINE_ITERATOR_TRAITS_POINTER_SPEC(CVEC) +#endif int main() { SETDTHREAD(2); CGAL::set_pretty_mode ( std::cerr ); CGAL_TEST_START; { // Homogeneous Kernel - typedef CGAL::Homogeneous_d Kernel; - typedef Kernel::FT NT; + typedef CGAL::Homogeneous_d Kernel; + typedef Kernel::RT RT; + typedef Kernel::FT FT; typedef Kernel::LA LA; typedef CGAL::Point_d Point; typedef CGAL::Vector_d Vector; @@ -64,18 +78,20 @@ int main() CGAL_TEST(p4.dimension()!=Point(3).dimension()); // dimension() /* some input and access test */ - CGAL_TEST(p1.hx()==1 && p1.hy()==0 && p1.hw()!=0); // hx,hy,hw + CGAL_TEST(p1.hx()==RT(1) && p1.hy()==RT(0) && p1.hw()!=RT(0)); CGAL_TEST(p1.hx()==p1.homogeneous(0) && p1.hy()==p1.homogeneous(1) && p1.hw()==p1.homogeneous(2)); // hx,hy,hw - CGAL_TEST(p1.x()==NT(1) && p1.y()==NT(0)); // x(),y() + CGAL_TEST(p1.x()==FT(1) && p1.y()==FT(0)); // x(),y() CGAL_TEST(p1.x()==p1[0] && p1.y()==p1[1]); // x(),y() CGAL_TEST(p1.x()==p1.cartesian(0) && p1.y()==p1.cartesian(1)); // x(),y() - IVector iv3(p1.homogeneous_begin(),p1.homogeneous_end()); - CGAL_TEST(iv1==iv3); + Point::Homogeneous_const_iterator hcit; int i; + for (i=0, hcit = p1.homogeneous_begin(); + hcit != p1.homogeneous_end(); ++i, ++hcit) + CGAL_TEST(*hcit == iv1[i]); Point::Homogeneous_const_iterator hit; - Point::Cartesian_const_iterator cit; int i; + Point::Cartesian_const_iterator cit; for (i=0,hit=p1.homogeneous_begin(),cit=p1.cartesian_begin(); i0); + CGAL_TEST(h2.value_at(o)FT(0)); CGAL_TEST(h2.oriented_side(o)==CGAL::ON_NEGATIVE_SIDE); CGAL_TEST(h2.oriented_side(p3)==CGAL::ON_ORIENTED_BOUNDARY); CGAL_TEST(h2.oriented_side(p3+dir.vector())==CGAL::ON_POSITIVE_SIDE); @@ -468,7 +484,7 @@ int main() s6 = Segment(Point(0,0),Point(10,10)); Point p3(10,0); - CGAL_TEST(s6.squared_length()==NT(200)); + CGAL_TEST(s6.squared_length()==FT(200)); CGAL_TEST(s6.has_on(Point(5,5))); CGAL_TEST(Segment(Point(1,1),Point(1,1)).is_degenerate()); CGAL_TEST(CGAL::weak_equality(s1,s1.opposite())); @@ -527,8 +543,9 @@ int main() } { // Cartesian Kernel - typedef CGAL::Cartesian_d Kernel; - typedef Kernel::FT NT; + typedef CGAL::Cartesian_d Kernel; + typedef Kernel::FT FT; + typedef Kernel::RT RT; typedef Kernel::LA LA; typedef CGAL::Point_d Point; typedef CGAL::Vector_d Vector; @@ -557,18 +574,20 @@ int main() CGAL_TEST(p4.dimension()!=Point(3).dimension()); // dimension() /* some input and access test */ - CGAL_TEST(p1.hx()==1 && p1.hy()==0 && p1.hw()!=0); // hx,hy,hw + CGAL_TEST(p1.hx()==RT(1) && p1.hy()==RT(0) && p1.hw()!=RT(0)); CGAL_TEST(p1.hx()==p1.homogeneous(0) && p1.hy()==p1.homogeneous(1) && p1.hw()==p1.homogeneous(2)); // hx,hy,hw - CGAL_TEST(p1.x()==NT(1) && p1.y()==NT(0)); // x(),y() + CGAL_TEST(p1.x()==FT(1) && p1.y()==FT(0)); // x(),y() CGAL_TEST(p1.x()==p1[0] && p1.y()==p1[1]); // x(),y() CGAL_TEST(p1.x()==p1.cartesian(0) && p1.y()==p1.cartesian(1)); // x(),y() - IVector iv3(p1.homogeneous_begin(),p1.homogeneous_end()); - CGAL_TEST(iv1==iv3); + Point::Homogeneous_const_iterator hcit; int i; + for (i=0, hcit = p1.homogeneous_begin(); + hcit != p1.homogeneous_end(); ++i, ++hcit) + CGAL_TEST(*hcit == iv1[i]); Point::Homogeneous_const_iterator hit; - Point::Cartesian_const_iterator cit; int i; + Point::Cartesian_const_iterator cit; for (i=0,hit=p1.homogeneous_begin(),cit=p1.cartesian_begin(); i0); + CGAL_TEST(h2.value_at(o)FT(0)); CGAL_TEST(h2.oriented_side(o)==CGAL::ON_NEGATIVE_SIDE); CGAL_TEST(h2.oriented_side(p3)==CGAL::ON_ORIENTED_BOUNDARY); CGAL_TEST(h2.oriented_side(p3+dir.vector())==CGAL::ON_POSITIVE_SIDE); @@ -961,7 +980,7 @@ int main() s6 = Segment(Point(0,0),Point(10,10)); Point p3(10,0); - CGAL_TEST(s6.squared_length()==NT(200)); + CGAL_TEST(s6.squared_length()==FT(200)); CGAL_TEST(s6.has_on(Point(5,5))); CGAL_TEST(Segment(Point(1,1),Point(1,1)).is_degenerate()); CGAL_TEST(CGAL::weak_equality(s1,s1.opposite()));