0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / Graphic3d / Graphic3d_Vector.cxx
CommitLineData
b311480e 1// Created by: NW,JPB,CAL
2// Copyright (c) 1991-1999 Matra Datavision
3// Copyright (c) 1999-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
7fd59977 21// Modified 27/12/98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
22
7fd59977 23
24//-Version
25
26//-Design Declaration des variables specifiques aux vecteurs
27
28//-Warning Un vecteur est defini par ses composantes ou par
29// deux points
30// Il peut etre normalise
31
32//-References
33
34//-Language C++ 2.0
35
36//-Declarations
37
38// for the class
39#include <Graphic3d_Vector.ixx>
40
41#include <Standard_Boolean.hxx>
42
43//-Aliases
44
45//-Global data definitions
46
47#define Graphic3d_Vector_MyEpsilon 0.000001
48
49// -- les coordonnees du vecteur
50// MyX : Standard_ShortReal;
51// MyY : Standard_ShortReal;
52// MyZ : Standard_ShortReal;
53
54// -- la norme du vecteur
55// MyNorme : Standard_ShortReal;
56
57//-Constructors
58
59Graphic3d_Vector::Graphic3d_Vector ():
60MyX (Standard_ShortReal (1.0)),
61MyY (Standard_ShortReal (1.0)),
62MyZ (Standard_ShortReal (1.0)),
63MyNorme (Standard_ShortReal (1.0)) {
64}
65
66Graphic3d_Vector::Graphic3d_Vector (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ):
67MyX (Standard_ShortReal (AX)),
68MyY (Standard_ShortReal (AY)),
69MyZ (Standard_ShortReal (AZ)),
70MyNorme (Standard_ShortReal (Graphic3d_Vector::NormeOf (AX, AY, AZ))) {
71}
72
73Graphic3d_Vector::Graphic3d_Vector (const Graphic3d_Vertex& APoint1, const Graphic3d_Vertex& APoint2) {
74
b8ddfc2f 75 MyX = APoint2.X() - APoint1.X();
76 MyY = APoint2.Y() - APoint1.Y();
77 MyZ = APoint2.Z() - APoint1.Z();
7fd59977 78
b8ddfc2f 79 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (MyX, MyY, MyZ));
7fd59977 80
81}
82
83//-Destructors
84
85//-Methods, in order
86
87void Graphic3d_Vector::Coord (Standard_Real& AX, Standard_Real& AY, Standard_Real& AZ) const {
88
89 AX = Standard_Real (MyX);
90 AY = Standard_Real (MyY);
91 AZ = Standard_Real (MyZ);
92
93}
94
95Standard_Real Graphic3d_Vector::X () const {
96
97 return Standard_Real (MyX);
98
99}
100
101Standard_Real Graphic3d_Vector::Y () const {
102
103 return Standard_Real (MyY);
104
105}
106
107Standard_Real Graphic3d_Vector::Z () const {
108
109 return Standard_Real (MyZ);
110
111}
112
113void Graphic3d_Vector::Normalize () {
114
115 if (Abs (MyNorme) <= RealEpsilon ())
116 Graphic3d_VectorError::Raise ("The norm is null");
117
118 if (!IsNormalized()) // CQO CTS40181
119 {
120 MyX = MyX / MyNorme;
121 MyY = MyY / MyNorme;
122 MyZ = MyZ / MyNorme;
123 }
124
125 MyNorme = Standard_ShortReal (1.0);
126
127}
128
129void Graphic3d_Vector::SetCoord (const Standard_Real Xnew, const Standard_Real Ynew, const Standard_Real Znew) {
130
131 MyX = Standard_ShortReal (Xnew);
132 MyY = Standard_ShortReal (Ynew);
133 MyZ = Standard_ShortReal (Znew);
134
135 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
136
137}
138
139void Graphic3d_Vector::SetXCoord (const Standard_Real Xnew) {
140
141 MyX = Standard_ShortReal (Xnew);
142
143 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
144
145}
146
147void Graphic3d_Vector::SetYCoord (const Standard_Real Ynew) {
148
149 MyY = Standard_ShortReal (Ynew);
150
151 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
152
153}
154
155void Graphic3d_Vector::SetZCoord (const Standard_Real Znew) {
156
157 MyZ = Standard_ShortReal (Znew);
158
159 MyNorme = Standard_ShortReal (Graphic3d_Vector::NormeOf (Standard_Real (MyX), Standard_Real (MyY), Standard_Real (MyZ)));
160
161}
162
163Standard_Boolean Graphic3d_Vector::LengthZero () const {
164
165 return (Abs (Standard_Real (MyNorme)) <= RealEpsilon ());
166
167}
168
169Standard_Boolean Graphic3d_Vector::IsNormalized () const {
170
171 return (Abs (Standard_Real (MyNorme) - 1.0) <=
172 Graphic3d_Vector_MyEpsilon);
173
174}
175
176Standard_Boolean Graphic3d_Vector::IsParallel (const Graphic3d_Vector& AV1, const Graphic3d_Vector& AV2) {
177
ef8ca55b 178 Standard_Real aDif1 = 0, aDif2 = 0, aDif3 = 0;
7fd59977 179
ef8ca55b
D
180 aDif1 = AV1.X () * AV2.Y () - AV1.Y () * AV2.X ();
181 aDif2 = AV1.X () * AV2.Z () - AV1.Z () * AV2.X ();
182 aDif3 = AV1.Y () * AV2.Z () - AV1.Z () * AV2.Y ();
7fd59977 183
ef8ca55b
D
184 return ( (Abs (aDif1) <= Graphic3d_Vector_MyEpsilon) &&
185 (Abs (aDif2) <= Graphic3d_Vector_MyEpsilon) &&
186 (Abs (aDif3) <= Graphic3d_Vector_MyEpsilon) );
7fd59977 187}
188
189Standard_Real Graphic3d_Vector::NormeOf (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ) {
190
191 return (Sqrt (AX*AX+AY*AY+AZ*AZ));
192
193}
194
195Standard_Real Graphic3d_Vector::NormeOf (const Graphic3d_Vector& AVector) {
196
197Standard_Real X, Y, Z;
198
199 AVector.Coord(X, Y, Z);
200 return (Graphic3d_Vector::NormeOf (X, Y, Z));
201
202}