1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2016, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2002-2016 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
 
 
 
#ifndef OD_GEVEC2D_H
#define OD_GEVEC2D_H /*!DOM*/
 
#include "Ge/GeGbl.h"
#include "Ge/GeTol.h"
 
#include "TD_PackPush.h"
 
class OdGeMatrix2d;
 
/** \details
    This class represents vectors in 2D space. 
 
    \remarks
    OdGeVector2d may be viewed as an array[2] of doubles.
 
    Library: TD_Ge
 
    <group OdGe_Classes>
 
    \sa
    <link ge_BasicTypes.html, Working with Basic Geometry Types>
*/
class GE_TOOLKIT_EXPORT OdGeVector2d
{
public:
  /** \param source [in]  Object to be cloned.
    \param xx [in]  X-coordinate.
    \param yy [in]  Y-coordinate.
    
    \remarks
    If called with no arguments, constructs a zero-length vector.
  */
  OdGeVector2d () : x (0.0), y (0.0) {}
  OdGeVector2d (
    double xx, 
    double yy) : x (xx), y (yy) {}
 
  GE_STATIC_EXPORT static const OdGeVector2d kIdentity; // Additive identity vector.
  GE_STATIC_EXPORT static const OdGeVector2d kXAxis;    // X-Axis vector.
  GE_STATIC_EXPORT static const OdGeVector2d kYAxis;    // Y-Axis vector.
 
  friend GE_TOOLKIT_EXPORT OdGeVector2d operator* (
    const OdGeMatrix2d& xfm, 
    const OdGeVector2d& vect);
    
 
  /** \details
    Sets this vector to the product matrix * vect  scale * vect, and returns
    a reference to this vector. 
    
    \param matrix [in]  Any 2D matrix 
    \param vect [in]  Any 2D vector 
    \param scale [in]  Scale factor.
  */
  OdGeVector2d& setToProduct (
    const OdGeMatrix2d& matrix, 
    const OdGeVector2d& vect)
  {
    *this = matrix * vect;
    return *this;
  }
 
  OdGeVector2d& setToProduct (
    const OdGeVector2d& vect, 
    double scale);
      
  /** \details
    Applies the 2D transformation matrix to this vector,
    and returns a reference to this vector.
 
    \param xfm [in]  2D transformation matrix.
  */
  OdGeVector2d& transformBy (
    const OdGeMatrix2d& xfm)  { return *this = xfm * *this;}
    
  /** \details
    Rotates this vector the specified angle, and returns
    a reference to this vector. 
 
    \param angle [in]  Rotation angle.
  */
  OdGeVector2d& rotateBy (
    double angle);
    
  /** \details
    Mirrors this vector about the specified 2D line
    and returns a reference to this vector.
 
    \param line [in]  Mirror Line.
  */
  OdGeVector2d& mirror (
    const OdGeVector2d& line);
 
  OdGeVector2d operator* (
    double scale) const;
  friend GE_TOOLKIT_EXPORT OdGeVector2d operator* (
    double scale, const OdGeVector2d& vector);
 
  OdGeVector2d& operator*= (
    double scale);
    
  OdGeVector2d  operator/ (
    double scale) const;
  OdGeVector2d& operator/= (double scale);
 
  OdGeVector2d operator+ (
    const OdGeVector2d& vect) const;
  OdGeVector2d& operator+= (
    const OdGeVector2d& vect);
  OdGeVector2d operator- (
    const OdGeVector2d& vect) const;
  OdGeVector2d& operator-= (
    const OdGeVector2d& vect);
    
  /** \details
    Sets this vector to vector1 + vector1, and returns a reference to this vector.
    
    \param vector1 [in]  Any 2D vector.
    \param vector2 [in]  Any 2D vector.
  */
    OdGeVector2d& setToSum (
    const OdGeVector2d& vector1, 
    const OdGeVector2d& vector2);
    
  OdGeVector2d operator- () const;
  
  /** \details
    Negates this vector (-x, -y), and returns a reference to this vector.
  */
  OdGeVector2d& negate ();
 
  /** \details
    Returns the vector perpendicular to this one (-y, x).
  */
  OdGeVector2d perpVector () const;
 
  /** \details
    Returns the angle between this vector and the X-axis
    
    \remarks
    Returns a value in the range [0.0 .. Oda2PI].
  */
  double angle () const;
 
  /** \details
    Returns the smallest angle to the specified vector.
    
    \param vect [in]  Any 2D vector.
    
    \remarks
    Returns a value in the range [0.0 .. Oda2PI].
    
    This function is commutative:
    
        a.angleTo (b) == b.angleTo (a)
  */
  double angleTo (
    const OdGeVector2d& vect) const;
 
  /** \details
    Returns the angle from this vector to the specified vector in the counterclockwise direction.
    
    \param vect [in]  Any 2D vector.
    
    \remarks
    Returns a value in the range [0.0 .. Oda2PI].
  */
  double angleToCCW (
    const OdGeVector2d& vect) const
  {
    return crossProduct (vect) > 0.0 ? angleTo(vect) : -angleTo(vect);
  }
    
  /** \details
    Returns the unit vector codirectional with this vector.
    
    \param tol [in]  Geometric tolerance.
        
    \remarks
    If the length() <= tol, this vector is returned.
  */
  OdGeVector2d normal (
    const OdGeTol& tol = OdGeContext::gTol) const;
    
  /** \details
    Sets this vector to the unit vector codirectional with this vector,
    and returns a reference to this vector
    
    \param tol [in]  Geometric tolerance.
    \param status [out]  Receives the status of normalization.
 
    \remarks
    If this.length() <= tol, this vector is unchanged, and kThis is returned in status.
 
    Possible values for status are as follows:
 
    @untitled table
    kOk 
    k0This
  */
  OdGeVector2d& normalize (
    const OdGeTol& tol = OdGeContext::gTol);
  OdGeVector2d& normalize (
    const OdGeTol& tol, 
    OdGeError& status);
    
  /** \details
    Sets this vector to the unit vector codirectional with this vector,
    and returns the length prior to normalization.
 
    \param tol [in]  Geometric tolerance.
 
    \remarks
    If this.length() <= tol, this vector is unchanged and zero length is returned.
  */
   double normalizeGetLength (double tol = 1.e-300);
 
  /** \details
    Returns the length of this vector.
  */
        double length () const;
  
  /** \details
    Returns the square of the length of this vector.
  */
        double lengthSqrd () const;
  
  /** \details
    Returns true if and only if the length of this vector is 1.0 within the specified tolerance.
 
    \param tol [in]  Geometric tolerance.
  */
        bool isUnitLength (
    const OdGeTol& tol = OdGeContext::gTol) const;
 
  /** \details
    Returns true if and only if the length of this vector is 0.0 within the specified tolerance.
 
    \param tol [in]  Geometric tolerance.
  */
        bool isZeroLength (
    const OdGeTol& tol = OdGeContext::gTol) const;
 
  /** \details
    Returns true if and only if the specified vector is parallel to this vector within the specified tolerance.
 
    \param vect [in]  Any 2D vector.
    \param tol [in]  Geometric tolerance.
    \param status [out]  Receives the status of test.
 
    \remarks
    If the length of either vector is < tol, kThis is returned in status.
 
    Possible values for status are as follows:
 
    @untitled table
    kOk
    k0This
    k0Arg1
  */
        bool isParallelTo (
    const OdGeVector2d& vect,
    const OdGeTol& tol = OdGeContext::gTol) const;
    
  bool isParallelTo (
    const OdGeVector2d& vect, 
    const OdGeTol& tol,
    OdGeError& status) const;
    
  /** \details
    Returns true if and only if the specified vector is codirectional to this vector within the specified tolerance.
 
    \param vect [in]  Any 2D vector.
    \param tol [in]  Geometric tolerance.
    \param status [out]  Receives the status of test.
 
    \remarks
    If the length of either vector is < tol, kThis is returned in status.
 
    Possible values for status are as follows:
 
    @untitled table
    kOk       
    k0This    
    k0Arg1    
  */
        bool isCodirectionalTo (
    const OdGeVector2d& vect,
    const OdGeTol& tol=OdGeContext::gTol) const;
  bool isCodirectionalTo (
    const OdGeVector2d& vect, 
    const OdGeTol& tol,
    OdGeError& status) const;
    
  /** \details
    Returns true if and only if the specified vector is perpendicular to this vector within the specified tolerance.
 
    \param vect [in]  Any 2D vector.
    \param tol [in]  Geometric tolerance.
    \param status [out]  Receives the status of test.
 
    \remarks
    If the length of either vector is < tol, kThis is returned in status.
 
    Possible values for status are as follows:
 
    @untitled table
    kOk       
    k0This    
    k0Arg1    
  */
        bool isPerpendicularTo (
    const OdGeVector2d& vect,
    const OdGeTol& tol = OdGeContext::gTol) const;
  bool isPerpendicularTo (
    const OdGeVector2d& vect, 
    const OdGeTol& tol,
    OdGeError& status) const;
    
  /** \details
    Returns the dot product of this vector and the specified vector.
    
    \param vect [in]  Any 2D vector.
  */
  double dotProduct (
    const OdGeVector2d& vect) const;
 
  /** \details
    Returns the z value of the cross product of this vector with
    the specified vector.
    
    \param vect [in]  Any 2D vector.
  */
  double  crossProduct (
    const OdGeVector2d& vect) const
  {
    return x * vect.y - y * vect.x;
  }
 
  bool operator== (
    const OdGeVector2d& vect) const;
  bool operator!= (
    const OdGeVector2d& vect) const;
    
  /** \details
    Returns true if and only if vector is identical to this vector,
    within the specified tolerance.
 
    \param vect [in]  Any 2D vector.
    \param tol [in]  Geometric tolerance.
  */
  bool isEqualTo (
    const OdGeVector2d& vect,
    const OdGeTol& tol = OdGeContext::gTol) const;
 
  /** \param i [in]  Index of coordinate.
 
    \remarks
    Returns or references the ith coordinate of this vector.
 
    * 0 returns or references the X-coordinate.
    * 1 returns or references the Y-coordinate.
  */
  double operator[] (
    unsigned int i) const;
  double& operator[] (
    unsigned int i) ;
  
  /** \details
    Sets this vector to the specified X and Y coordinates, 
    and returns a reference to this vector.
 
    \param xx [in]  X-coordinate.
    \param yy [in]  Y-coordinate.
  */
  OdGeVector2d& set (
    double xx, 
    double yy)
  {
    x = xx;
    y = yy;
    return *this;
  }    
 
  /** \remarks
    Returns the equivalent 2D tranformation matrix.
  */
  operator OdGeMatrix2d () const;
 
  double x; // X-coordinate.
  double y; // Y-coordinate.
};
 
 
#include "TD_PackPop.h"
 
#endif