0024704: Visualization - inherit OpenGl_Structure from Graphic3d_CStructure
[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)
17
7fd59977 18
19//-Version
20
21//-Design Declaration des variables specifiques aux vecteurs
22
23//-Warning Un vecteur est defini par ses composantes ou par
24// deux points
25// Il peut etre normalise
26
27//-References
28
29//-Language C++ 2.0
30
31//-Declarations
32
33// for the class
34#include <Graphic3d_Vector.ixx>
35
36#include <Standard_Boolean.hxx>
37
38//-Aliases
39
40//-Global data definitions
41
42#define Graphic3d_Vector_MyEpsilon 0.000001
43
44// -- les coordonnees du vecteur
45// MyX : Standard_ShortReal;
46// MyY : Standard_ShortReal;
47// MyZ : Standard_ShortReal;
48
49// -- la norme du vecteur
50// MyNorme : Standard_ShortReal;
51
52//-Constructors
53
54Graphic3d_Vector::Graphic3d_Vector ():
55MyX (Standard_ShortReal (1.0)),
56MyY (Standard_ShortReal (1.0)),
57MyZ (Standard_ShortReal (1.0)),
58MyNorme (Standard_ShortReal (1.0)) {
59}
60
61Graphic3d_Vector::Graphic3d_Vector (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ):
62MyX (Standard_ShortReal (AX)),
63MyY (Standard_ShortReal (AY)),
64MyZ (Standard_ShortReal (AZ)),
65MyNorme (Standard_ShortReal (Graphic3d_Vector::NormeOf (AX, AY, AZ))) {
66}
67
68Graphic3d_Vector::Graphic3d_Vector (const Graphic3d_Vertex& APoint1, const Graphic3d_Vertex& APoint2) {
69
b8ddfc2f 70 MyX = APoint2.X() - APoint1.X();
71 MyY = APoint2.Y() - APoint1.Y();
72 MyZ = APoint2.Z() - APoint1.Z();
7fd59977 73
b8ddfc2f 74 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (MyX, MyY, MyZ));
7fd59977 75
76}
77
78//-Destructors
79
80//-Methods, in order
81
82void Graphic3d_Vector::Coord (Standard_Real& AX, Standard_Real& AY, Standard_Real& AZ) const {
83
84 AX = Standard_Real (MyX);
85 AY = Standard_Real (MyY);
86 AZ = Standard_Real (MyZ);
87
88}
89
90Standard_Real Graphic3d_Vector::X () const {
91
92 return Standard_Real (MyX);
93
94}
95
96Standard_Real Graphic3d_Vector::Y () const {
97
98 return Standard_Real (MyY);
99
100}
101
102Standard_Real Graphic3d_Vector::Z () const {
103
104 return Standard_Real (MyZ);
105
106}
107
108void Graphic3d_Vector::Normalize () {
109
110 if (Abs (MyNorme) <= RealEpsilon ())
111 Graphic3d_VectorError::Raise ("The norm is null");
112
113 if (!IsNormalized()) // CQO CTS40181
114 {
115 MyX = MyX / MyNorme;
116 MyY = MyY / MyNorme;
117 MyZ = MyZ / MyNorme;
118 }
119
120 MyNorme = Standard_ShortReal (1.0);
121
122}
123
124void Graphic3d_Vector::SetCoord (const Standard_Real Xnew, const Standard_Real Ynew, const Standard_Real Znew) {
125
126 MyX = Standard_ShortReal (Xnew);
127 MyY = Standard_ShortReal (Ynew);
128 MyZ = Standard_ShortReal (Znew);
129
130 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
131
132}
133
134void Graphic3d_Vector::SetXCoord (const Standard_Real Xnew) {
135
136 MyX = Standard_ShortReal (Xnew);
137
138 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
139
140}
141
142void Graphic3d_Vector::SetYCoord (const Standard_Real Ynew) {
143
144 MyY = Standard_ShortReal (Ynew);
145
146 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
147
148}
149
150void Graphic3d_Vector::SetZCoord (const Standard_Real Znew) {
151
152 MyZ = Standard_ShortReal (Znew);
153
154 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
155
156}
157
158Standard_Boolean Graphic3d_Vector::LengthZero () const {
159
160 return (Abs (Standard_Real (MyNorme)) <= RealEpsilon ());
161
162}
163
164Standard_Boolean Graphic3d_Vector::IsNormalized () const {
165
166 return (Abs (Standard_Real (MyNorme) - 1.0) <=
167 Graphic3d_Vector_MyEpsilon);
168
169}
170
171Standard_Boolean Graphic3d_Vector::IsParallel (const Graphic3d_Vector& AV1, const Graphic3d_Vector& AV2) {
172
ef8ca55b 173 Standard_Real aDif1 = 0, aDif2 = 0, aDif3 = 0;
7fd59977 174
ef8ca55b
D
175 aDif1 = AV1.X () * AV2.Y () - AV1.Y () * AV2.X ();
176 aDif2 = AV1.X () * AV2.Z () - AV1.Z () * AV2.X ();
177 aDif3 = AV1.Y () * AV2.Z () - AV1.Z () * AV2.Y ();
7fd59977 178
ef8ca55b
D
179 return ( (Abs (aDif1) <= Graphic3d_Vector_MyEpsilon) &&
180 (Abs (aDif2) <= Graphic3d_Vector_MyEpsilon) &&
181 (Abs (aDif3) <= Graphic3d_Vector_MyEpsilon) );
7fd59977 182}
183
184Standard_Real Graphic3d_Vector::NormeOf (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ) {
185
186 return (Sqrt (AX*AX+AY*AY+AZ*AZ));
187
188}
189
190Standard_Real Graphic3d_Vector::NormeOf (const Graphic3d_Vector& AVector) {
191
192Standard_Real X, Y, Z;
193
194 AVector.Coord(X, Y, Z);
195 return (Graphic3d_Vector::NormeOf (X, Y, Z));
196
197}