1// Copyright (c) 1995-1999 Matra Datavision 2// Copyright (c) 1999-2014 OPEN CASCADE SAS 3// 4// This file is part of Open CASCADE Technology software library. 5// 6// This library is free software; you can redistribute it and/or modify it under 7// the terms of the GNU Lesser General Public License version 2.1 as published 8// by the Free Software Foundation, with special exception defined in the file 9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 10// distribution for complete text of the license and disclaimer of any warranty. 11// 12// Alternatively, this file may be used under the terms of Open CASCADE 13// commercial license or contractual agreement. 14 15// Modif JCV 04/10/90 ajout des methodes Form Scale IsNegative 16// Modif JCV 10/12/90 ajout de la methode Translationpart 17 18 19#include <Standard_OutOfRange.hxx> 20#include <gp_Trsf2d.hxx> 21#include <gp_Vec.hxx> 22#include <gp_Pnt.hxx> 23 24inline gp_Trsf::gp_Trsf () : 25scale(1.0), 26shape(gp_Identity), 27matrix(1,0,0, 0,1,0, 0,0,1), 28loc(0.0, 0.0, 0.0) 29{} 30 31inline void gp_Trsf::SetMirror (const gp_Pnt& P) 32{ 33 shape = gp_PntMirror; 34 scale = -1.0; 35 loc = P.XYZ(); 36 matrix.SetIdentity (); 37 loc.Multiply(2.0); 38} 39 40inline void gp_Trsf::SetTranslation (const gp_Vec& V) 41{ 42 shape = gp_Translation; 43 scale = 1.; 44 matrix.SetIdentity (); 45 loc = V.XYZ(); 46} 47 48inline void gp_Trsf::SetTranslation(const gp_Pnt& P1, 49 const gp_Pnt& P2) 50{ 51 shape = gp_Translation; 52 scale = 1.0; 53 matrix.SetIdentity (); 54 loc = (P2.XYZ()).Subtracted (P1.XYZ()); 55} 56 57inline void gp_Trsf::SetForm(const gp_TrsfForm P) 58{ 59 shape = P; 60} 61 62inline Standard_Boolean gp_Trsf::IsNegative() const 63{ return (scale < 0.0); } 64 65inline const gp_XYZ& gp_Trsf::TranslationPart () const 66{ return loc; } 67 68inline const gp_Mat& gp_Trsf::HVectorialPart () const 69{ return matrix; } 70 71inline Standard_Real gp_Trsf::Value (const Standard_Integer Row, 72 const Standard_Integer Col) const 73{ 74 Standard_OutOfRange_Raise_if 75 (Row < 1 || Row > 3 || Col < 1 || Col > 4, " "); 76 if (Col < 4) return scale * matrix.Value (Row, Col); 77 else return loc.Coord (Row); 78} 79 80inline gp_TrsfForm gp_Trsf::Form () const 81{ return shape; } 82 83inline Standard_Real gp_Trsf::ScaleFactor () const 84{ return scale; } 85 86inline gp_Trsf gp_Trsf::Inverted() const 87{ 88 gp_Trsf T = *this; 89 T.Invert(); 90 return T; 91} 92 93inline gp_Trsf gp_Trsf::Multiplied (const gp_Trsf& T) const 94{ 95 gp_Trsf Tresult(*this); 96 Tresult.Multiply(T); 97 return Tresult; 98} 99 100inline gp_Trsf gp_Trsf::Powered (const Standard_Integer N) const 101{ 102 gp_Trsf T = *this; 103 T.Power (N); 104 return T; 105} 106 107inline void gp_Trsf::Transforms (Standard_Real& X, 108 Standard_Real& Y, 109 Standard_Real& Z) const 110{ 111 gp_XYZ Triplet (X, Y, Z); 112 Triplet.Multiply (matrix); 113 if (scale != 1.0) Triplet.Multiply (scale); 114 Triplet.Add(loc); 115 X = Triplet.X(); 116 Y = Triplet.Y(); 117 Z = Triplet.Z(); 118} 119 120inline void gp_Trsf::Transforms (gp_XYZ& Coord) const 121{ 122 Coord.Multiply (matrix); 123 if (scale != 1.0) Coord.Multiply (scale); 124 Coord.Add(loc); 125} 126 127