// Copyright (c) 2000,2001 // Utrecht University (The Netherlands), // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), // and Tel-Aviv University (Israel). All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $URL: https://github.com/CGAL/cgal/blob/v5.2/Kernel_d/include/CGAL/Kernel_d/Aff_transformationCd.h $ // $Id: Aff_transformationCd.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Michael Seel #ifndef CGAL_AFF_TRANSFORMATIONCD_H #define CGAL_AFF_TRANSFORMATIONCD_H #include #include #include #include namespace CGAL { template class Aff_transformationCd; template class Aff_transformationCd_rep; template class Aff_transformationCd_rep { friend class Aff_transformationCd; typedef typename LA::Matrix Matrix; Matrix M_; public: Aff_transformationCd_rep(int d) : M_(d+1) {} Aff_transformationCd_rep(const Matrix& M_init) : M_(M_init) {} ~Aff_transformationCd_rep() {} }; template class Aff_transformationCd : public Handle_for< Aff_transformationCd_rep<_FT,_LA> > { typedef Aff_transformationCd_rep<_FT,_LA> Rep; typedef Handle_for Base; typedef Aff_transformationCd<_FT,_LA> Self; using Base::ptr; public: typedef _FT RT; typedef _FT FT; typedef _LA LA; typedef typename _LA::Matrix Matrix; typedef typename _LA::Vector Vector; Aff_transformationCd(int d = 0) : Base( Rep(d) ) {} Aff_transformationCd(int d, Identity_transformation) : Base( Rep(d) ) { for (int i = 0; i <= d; ++i) ptr()->M_(i,i) = FT(1); } Aff_transformationCd(const Matrix& M) : Base( Rep(M) ) { CGAL_assertion_msg((M.row_dimension()==M.column_dimension()), "Aff_transformationCd:: initialization matrix not quadratic."); int d = M.row_dimension(),i; for (i=0; i Aff_transformationCd(Scaling, Forward_iterator start, Forward_iterator end) : Base( Rep(static_cast(std::distance(start,end))-1) ) /*{\Mcreate introduces the transformation of $d$-space specified by a diagonal matrix with entries |set [start,end)| on the diagonal (a scaling of the space). \precond |set [start,end)| is a vector of dimension $d+1$.}*/ { int i=0; while (start != end) { ptr()->M_(i,i) = *start++;++i; } } Aff_transformationCd(Translation, const VectorCd& v) : Base( Rep(v.dimension()) ) { int d = v.dimension(); for (int i = 0; i < d; ++i) { ptr()->M_(i,i) = FT(1); ptr()->M_(i,d) = v.cartesian(i); } ptr()->M_(d,d) = FT(1); } Aff_transformationCd(int d, Scaling, const RT& num, const RT& den) : Base( Rep(d) ) { Matrix& M = ptr()->M_; for (int i = 0; i < d; ++i) M(i,i) = num/den; M(d,d) = FT(1); } Aff_transformationCd(int d, Rotation, const RT& sin_num, const RT& cos_num, const RT& den, int e1 = 0, int e2 = 1) : Base( Rep(d) ) { CGAL_assertion_msg((sin_num*sin_num + cos_num*cos_num == den*den), "planar_rotation: rotation parameters disobey precondition."); CGAL_assertion_msg((0<=e1 && e1<=e2 && e2M_; for (int i=0; i& dir, const RT& eps_num, const RT& eps_den, int e1 = 0, int e2 = 1) : Base( Rep(d) ) { CGAL_assertion(dir.dimension()==2); Matrix& M = ptr()->M_; for (int i=0; iM_.row_dimension()-1; } const Matrix& matrix() const { return ptr()->M_; } bool is_odd() const { return LA::sign_of_determinant(matrix())<0; } Vector operator()(const Vector& v) const { CGAL_assertion(matrix().row_dimension()-1==v.dimension()); const Matrix& M = ptr()->M_; int i,j,d(v.dimension()); Vector res(d); for (i=0; iM_; int i,j,d(v.dimension()); Vector res(d); for (i=0; i inverse() const { Aff_transformationCd Inv; RT D; Vector dummy; if ( !LA::inverse(matrix(),Inv.ptr()->M_,D,dummy) ) CGAL_error_msg("Aff_transformationCd::inverse: not invertible."); if ( D < FT(0) ) Inv.ptr()->M_ = -Inv.ptr()->M_; return Inv; } Aff_transformationCd operator*(const Aff_transformationCd& s) const { CGAL_assertion_msg((dimension()==s.dimension()), "Aff_transformationCd::operator*: dimensions disagree."); return Aff_transformationCd(matrix()*s.matrix()); } bool operator==(const Aff_transformationCd& a1) const { if ( this->identical(a1) ) return true; return ( matrix() == a1.matrix() ); } bool operator!=(const Aff_transformationCd& a1) const { return !operator==(a1); } }; // Aff_transformationCd template std::ostream& operator<<( std::ostream& os, const Aff_transformationCd& t) { os << t.matrix(); return os; } template std::istream& operator>>( std::istream& is, Aff_transformationCd& t) { typename LA::Matrix M(t.dimension()); is >> M; t = Aff_transformationCd(M); return is; } } //namespace CGAL #endif // CGAL_AFF_TRANSFORMATIONCD_H