0027860: Visualization - clean up Transformation Persistence API
[occt.git] / src / Graphic3d / Graphic3d_Vector.cxx
CommitLineData
b311480e 1// Created by: NW,JPB,CAL
2// Copyright (c) 1991-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16// Modified 27/12/98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
7fd59977 17//-Version
7fd59977 18//-Design Declaration des variables specifiques aux vecteurs
7fd59977 19//-Warning Un vecteur est defini par ses composantes ou par
20// deux points
21// Il peut etre normalise
7fd59977 22//-References
7fd59977 23//-Language C++ 2.0
7fd59977 24//-Declarations
7fd59977 25// for the class
7fd59977 26
42cf5bc1 27#include <Graphic3d_Vector.hxx>
28#include <Graphic3d_VectorError.hxx>
7fd59977 29#include <Standard_Boolean.hxx>
30
31//-Aliases
7fd59977 32//-Global data definitions
7fd59977 33#define Graphic3d_Vector_MyEpsilon 0.000001
34
35// -- les coordonnees du vecteur
36// MyX : Standard_ShortReal;
37// MyY : Standard_ShortReal;
38// MyZ : Standard_ShortReal;
39
40// -- la norme du vecteur
41// MyNorme : Standard_ShortReal;
42
43//-Constructors
44
45Graphic3d_Vector::Graphic3d_Vector ():
46MyX (Standard_ShortReal (1.0)),
47MyY (Standard_ShortReal (1.0)),
48MyZ (Standard_ShortReal (1.0)),
49MyNorme (Standard_ShortReal (1.0)) {
50}
51
52Graphic3d_Vector::Graphic3d_Vector (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ):
53MyX (Standard_ShortReal (AX)),
54MyY (Standard_ShortReal (AY)),
55MyZ (Standard_ShortReal (AZ)),
56MyNorme (Standard_ShortReal (Graphic3d_Vector::NormeOf (AX, AY, AZ))) {
57}
58
59Graphic3d_Vector::Graphic3d_Vector (const Graphic3d_Vertex& APoint1, const Graphic3d_Vertex& APoint2) {
60
b8ddfc2f 61 MyX = APoint2.X() - APoint1.X();
62 MyY = APoint2.Y() - APoint1.Y();
63 MyZ = APoint2.Z() - APoint1.Z();
7fd59977 64
b8ddfc2f 65 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (MyX, MyY, MyZ));
7fd59977 66
67}
68
69//-Destructors
70
71//-Methods, in order
72
73void Graphic3d_Vector::Coord (Standard_Real& AX, Standard_Real& AY, Standard_Real& AZ) const {
74
75 AX = Standard_Real (MyX);
76 AY = Standard_Real (MyY);
77 AZ = Standard_Real (MyZ);
78
79}
80
81Standard_Real Graphic3d_Vector::X () const {
82
83 return Standard_Real (MyX);
84
85}
86
87Standard_Real Graphic3d_Vector::Y () const {
88
89 return Standard_Real (MyY);
90
91}
92
93Standard_Real Graphic3d_Vector::Z () const {
94
95 return Standard_Real (MyZ);
96
97}
98
99void Graphic3d_Vector::Normalize () {
100
101 if (Abs (MyNorme) <= RealEpsilon ())
102 Graphic3d_VectorError::Raise ("The norm is null");
103
104 if (!IsNormalized()) // CQO CTS40181
105 {
106 MyX = MyX / MyNorme;
107 MyY = MyY / MyNorme;
108 MyZ = MyZ / MyNorme;
109 }
110
111 MyNorme = Standard_ShortReal (1.0);
112
113}
114
115void Graphic3d_Vector::SetCoord (const Standard_Real Xnew, const Standard_Real Ynew, const Standard_Real Znew) {
116
117 MyX = Standard_ShortReal (Xnew);
118 MyY = Standard_ShortReal (Ynew);
119 MyZ = Standard_ShortReal (Znew);
120
121 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
122
123}
124
125void Graphic3d_Vector::SetXCoord (const Standard_Real Xnew) {
126
127 MyX = Standard_ShortReal (Xnew);
128
129 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
130
131}
132
133void Graphic3d_Vector::SetYCoord (const Standard_Real Ynew) {
134
135 MyY = Standard_ShortReal (Ynew);
136
137 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
138
139}
140
141void Graphic3d_Vector::SetZCoord (const Standard_Real Znew) {
142
143 MyZ = Standard_ShortReal (Znew);
144
145 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
146
147}
148
149Standard_Boolean Graphic3d_Vector::LengthZero () const {
150
151 return (Abs (Standard_Real (MyNorme)) <= RealEpsilon ());
152
153}
154
155Standard_Boolean Graphic3d_Vector::IsNormalized () const {
156
157 return (Abs (Standard_Real (MyNorme) - 1.0) <=
158 Graphic3d_Vector_MyEpsilon);
159
160}
161
162Standard_Boolean Graphic3d_Vector::IsParallel (const Graphic3d_Vector& AV1, const Graphic3d_Vector& AV2) {
163
ef8ca55b 164 Standard_Real aDif1 = 0, aDif2 = 0, aDif3 = 0;
7fd59977 165
ef8ca55b
D
166 aDif1 = AV1.X () * AV2.Y () - AV1.Y () * AV2.X ();
167 aDif2 = AV1.X () * AV2.Z () - AV1.Z () * AV2.X ();
168 aDif3 = AV1.Y () * AV2.Z () - AV1.Z () * AV2.Y ();
7fd59977 169
ef8ca55b
D
170 return ( (Abs (aDif1) <= Graphic3d_Vector_MyEpsilon) &&
171 (Abs (aDif2) <= Graphic3d_Vector_MyEpsilon) &&
172 (Abs (aDif3) <= Graphic3d_Vector_MyEpsilon) );
7fd59977 173}
174
175Standard_Real Graphic3d_Vector::NormeOf (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ) {
176
177 return (Sqrt (AX*AX+AY*AY+AZ*AZ));
178
179}
180
181Standard_Real Graphic3d_Vector::NormeOf (const Graphic3d_Vector& AVector) {
182
183Standard_Real X, Y, Z;
184
185 AVector.Coord(X, Y, Z);
186 return (Graphic3d_Vector::NormeOf (X, Y, Z));
187
188}