42cf5bc1 |
1 | // Copyright (c) 1991-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 | #ifndef _gp_XY_HeaderFile |
16 | #define _gp_XY_HeaderFile |
17 | |
18 | #include <Standard.hxx> |
19 | #include <Standard_DefineAlloc.hxx> |
20 | #include <Standard_Handle.hxx> |
21 | |
22 | #include <Standard_Real.hxx> |
23 | #include <Standard_Integer.hxx> |
24 | #include <Standard_Boolean.hxx> |
25 | class Standard_ConstructionError; |
26 | class Standard_OutOfRange; |
27 | class gp_Mat2d; |
28 | |
29 | |
30 | |
31 | //! This class describes a cartesian coordinate entity in 2D |
32 | //! space {X,Y}. This class is non persistent. This entity used |
33 | //! for algebraic calculation. An XY can be transformed with a |
34 | //! Trsf2d or a GTrsf2d from package gp. |
35 | //! It is used in vectorial computations or for holding this type |
36 | //! of information in data structures. |
37 | class gp_XY |
38 | { |
39 | public: |
40 | |
41 | DEFINE_STANDARD_ALLOC |
42 | |
43 | |
44 | //! Creates XY object with zero coordinates (0,0). |
45 | gp_XY(); |
46 | |
47 | //! a number pair defined by the XY coordinates |
48 | gp_XY(const Standard_Real X, const Standard_Real Y); |
49 | |
50 | |
51 | //! modifies the coordinate of range Index |
52 | //! Index = 1 => X is modified |
53 | //! Index = 2 => Y is modified |
54 | //! Raises OutOfRange if Index != {1, 2}. |
55 | void SetCoord (const Standard_Integer Index, const Standard_Real Xi); |
56 | |
57 | //! For this number pair, assigns |
58 | //! the values X and Y to its coordinates |
59 | void SetCoord (const Standard_Real X, const Standard_Real Y); |
60 | |
61 | //! Assigns the given value to the X coordinate of this number pair. |
62 | void SetX (const Standard_Real X); |
63 | |
64 | //! Assigns the given value to the Y coordinate of this number pair. |
65 | void SetY (const Standard_Real Y); |
66 | |
67 | |
68 | //! returns the coordinate of range Index : |
69 | //! Index = 1 => X is returned |
70 | //! Index = 2 => Y is returned |
71 | //! Raises OutOfRange if Index != {1, 2}. |
72 | Standard_Real Coord (const Standard_Integer Index) const; |
73 | |
74 | Standard_Real& ChangeCoord (const Standard_Integer theIndex); |
75 | |
76 | //! For this number pair, returns its coordinates X and Y. |
77 | void Coord (Standard_Real& X, Standard_Real& Y) const; |
78 | |
79 | //! Returns the X coordinate of this number pair. |
80 | Standard_Real X() const; |
81 | |
82 | //! Returns the Y coordinate of this number pair. |
83 | Standard_Real Y() const; |
84 | |
85 | //! Computes Sqrt (X*X + Y*Y) where X and Y are the two coordinates of this number pair. |
86 | Standard_Real Modulus() const; |
87 | |
88 | //! Computes X*X + Y*Y where X and Y are the two coordinates of this number pair. |
89 | Standard_Real SquareModulus() const; |
90 | |
91 | |
92 | //! Returns true if the coordinates of this number pair are |
93 | //! equal to the respective coordinates of the number pair |
94 | //! Other, within the specified tolerance Tolerance. I.e.: |
95 | //! abs(<me>.X() - Other.X()) <= Tolerance and |
96 | //! abs(<me>.Y() - Other.Y()) <= Tolerance and |
97 | //! computations |
98 | Standard_EXPORT Standard_Boolean IsEqual (const gp_XY& Other, const Standard_Real Tolerance) const; |
99 | |
100 | //! Computes the sum of this number pair and number pair Other |
101 | //! <me>.X() = <me>.X() + Other.X() |
102 | //! <me>.Y() = <me>.Y() + Other.Y() |
103 | void Add (const gp_XY& Other); |
104 | void operator += (const gp_XY& Other) |
105 | { |
106 | Add(Other); |
107 | } |
108 | |
109 | //! Computes the sum of this number pair and number pair Other |
110 | //! new.X() = <me>.X() + Other.X() |
111 | //! new.Y() = <me>.Y() + Other.Y() |
112 | gp_XY Added (const gp_XY& Other) const; |
113 | gp_XY operator + (const gp_XY& Other) const |
114 | { |
115 | return Added(Other); |
116 | } |
117 | |
118 | |
119 | //! Real D = <me>.X() * Other.Y() - <me>.Y() * Other.X() |
120 | Standard_Real Crossed (const gp_XY& Right) const; |
121 | Standard_Real operator ^ (const gp_XY& Right) const |
122 | { |
123 | return Crossed(Right); |
124 | } |
125 | |
126 | |
127 | //! computes the magnitude of the cross product between <me> and |
128 | //! Right. Returns || <me> ^ Right || |
129 | Standard_Real CrossMagnitude (const gp_XY& Right) const; |
130 | |
131 | |
132 | //! computes the square magnitude of the cross product between <me> and |
133 | //! Right. Returns || <me> ^ Right ||**2 |
134 | Standard_Real CrossSquareMagnitude (const gp_XY& Right) const; |
135 | |
136 | //! divides <me> by a real. |
137 | void Divide (const Standard_Real Scalar); |
138 | void operator /= (const Standard_Real Scalar) |
139 | { |
140 | Divide(Scalar); |
141 | } |
142 | |
143 | //! Divides <me> by a real. |
144 | gp_XY Divided (const Standard_Real Scalar) const; |
145 | gp_XY operator / (const Standard_Real Scalar) const |
146 | { |
147 | return Divided(Scalar); |
148 | } |
149 | |
150 | //! Computes the scalar product between <me> and Other |
151 | Standard_Real Dot (const gp_XY& Other) const; |
152 | Standard_Real operator * (const gp_XY& Other) const |
153 | { |
154 | return Dot(Other); |
155 | } |
156 | |
157 | |
158 | //! <me>.X() = <me>.X() * Scalar; |
159 | //! <me>.Y() = <me>.Y() * Scalar; |
160 | void Multiply (const Standard_Real Scalar); |
161 | void operator *= (const Standard_Real Scalar) |
162 | { |
163 | Multiply(Scalar); |
164 | } |
165 | |
166 | |
167 | //! <me>.X() = <me>.X() * Other.X(); |
168 | //! <me>.Y() = <me>.Y() * Other.Y(); |
169 | void Multiply (const gp_XY& Other); |
170 | void operator *= (const gp_XY& Other) |
171 | { |
172 | Multiply(Other); |
173 | } |
174 | |
175 | //! <me> = Matrix * <me> |
176 | void Multiply (const gp_Mat2d& Matrix); |
177 | void operator *= (const gp_Mat2d& Matrix) |
178 | { |
179 | Multiply(Matrix); |
180 | } |
181 | |
182 | |
183 | //! New.X() = <me>.X() * Scalar; |
184 | //! New.Y() = <me>.Y() * Scalar; |
185 | gp_XY Multiplied (const Standard_Real Scalar) const; |
186 | gp_XY operator * (const Standard_Real Scalar) const |
187 | { |
188 | return Multiplied(Scalar); |
189 | } |
190 | |
191 | |
192 | //! new.X() = <me>.X() * Other.X(); |
193 | //! new.Y() = <me>.Y() * Other.Y(); |
194 | gp_XY Multiplied (const gp_XY& Other) const; |
195 | |
196 | //! New = Matrix * <me> |
197 | gp_XY Multiplied (const gp_Mat2d& Matrix) const; |
198 | gp_XY operator * (const gp_Mat2d& Matrix) const |
199 | { |
200 | return Multiplied(Matrix); |
201 | } |
202 | |
203 | |
204 | //! <me>.X() = <me>.X()/ <me>.Modulus() |
205 | //! <me>.Y() = <me>.Y()/ <me>.Modulus() |
206 | //! Raises ConstructionError if <me>.Modulus() <= Resolution from gp |
207 | void Normalize(); |
208 | |
209 | |
210 | //! New.X() = <me>.X()/ <me>.Modulus() |
211 | //! New.Y() = <me>.Y()/ <me>.Modulus() |
212 | //! Raises ConstructionError if <me>.Modulus() <= Resolution from gp |
213 | gp_XY Normalized() const; |
214 | |
215 | |
216 | //! <me>.X() = -<me>.X() |
217 | //! <me>.Y() = -<me>.Y() |
218 | void Reverse(); |
219 | |
220 | |
221 | //! New.X() = -<me>.X() |
222 | //! New.Y() = -<me>.Y() |
223 | gp_XY Reversed() const; |
224 | gp_XY operator -() const |
225 | { |
226 | return Reversed(); |
227 | } |
228 | |
229 | |
230 | //! Computes the following linear combination and |
231 | //! assigns the result to this number pair: |
232 | //! A1 * XY1 + A2 * XY2 |
233 | void SetLinearForm (const Standard_Real A1, const gp_XY& XY1, const Standard_Real A2, const gp_XY& XY2); |
234 | |
235 | |
236 | //! -- Computes the following linear combination and |
237 | //! assigns the result to this number pair: |
238 | //! A1 * XY1 + A2 * XY2 + XY3 |
239 | void SetLinearForm (const Standard_Real A1, const gp_XY& XY1, const Standard_Real A2, const gp_XY& XY2, const gp_XY& XY3); |
240 | |
241 | |
242 | //! Computes the following linear combination and |
243 | //! assigns the result to this number pair: |
244 | //! A1 * XY1 + XY2 |
245 | void SetLinearForm (const Standard_Real A1, const gp_XY& XY1, const gp_XY& XY2); |
246 | |
247 | |
248 | //! Computes the following linear combination and |
249 | //! assigns the result to this number pair: |
250 | //! XY1 + XY2 |
251 | void SetLinearForm (const gp_XY& XY1, const gp_XY& XY2); |
252 | |
253 | |
254 | //! <me>.X() = <me>.X() - Other.X() |
255 | //! <me>.Y() = <me>.Y() - Other.Y() |
256 | void Subtract (const gp_XY& Right); |
257 | void operator -= (const gp_XY& Right) |
258 | { |
259 | Subtract(Right); |
260 | } |
261 | |
262 | |
263 | //! new.X() = <me>.X() - Other.X() |
264 | //! new.Y() = <me>.Y() - Other.Y() |
265 | gp_XY Subtracted (const gp_XY& Right) const; |
266 | gp_XY operator - (const gp_XY& Right) const |
267 | { |
268 | return Subtracted(Right); |
269 | } |
270 | |
271 | |
272 | |
273 | |
274 | protected: |
275 | |
276 | |
277 | |
278 | |
279 | |
280 | private: |
281 | |
282 | |
283 | |
284 | Standard_Real x; |
285 | Standard_Real y; |
286 | |
287 | |
288 | }; |
289 | |
290 | |
291 | #include <gp_XY.lxx> |
292 | |
293 | |
294 | |
295 | |
296 | |
297 | #endif // _gp_XY_HeaderFile |