OpenLexocad  27.1
Vec2d.h
Go to the documentation of this file.
1 //
3 // Copyright(C) 2013-2016 OpenCascade [www.opencascade.org]
4 //
5 // This library is free software; you can redistribute it and / or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street,
18 // Fifth Floor, Boston, MA 02110 - 1301 USA
19 //
21 
22 #pragma once
23 
24 #include <Geom/Pnt2d.h>
25 #include <Geom/XY.h>
26 
27 namespace Geom
28 {
29 class Ax2d;
30 class Dir2d;
31 class Trsf2d;
32 
34 class LX_GEOM_EXPORT Vec2d
35 {
36 public:
38  Vec2d();
40  Vec2d(const Dir2d& V);
42  Vec2d(const XY& Coord);
44  Vec2d(const double Xv, const double Yv);
45 
48  Vec2d(const Pnt2d& P1, const Pnt2d& P2);
49  void add(const Vec2d& Other);
51  Vec2d added(const Vec2d& Other) const;
56  double angle(const Vec2d& Other) const;
60  double coord(const int Index) const;
62  void coord(double& Xv, double& Yv) const;
64  double crossed(const Vec2d& Right) const;
67  double crossMagnitude(const Vec2d& Right) const;
68 
71  double crossSquareMagnitude(const Vec2d& Right) const;
72 
73  void divide(const double Scalar);
75  Vec2d divided(const double Scalar) const;
77  double dot(const Vec2d& Other) const;
81  bool isEqual(const Vec2d& Other, const double LinearTolerance, const double AngularTolerance) const;
82 
84  bool isNormal(const Vec2d& Other, const double AngularTolerance) const;
85 
87  bool isOpposite(const Vec2d& Other, const double AngularTolerance) const;
88 
92  bool isParallel(const Vec2d& Other, const double AngularTolerance) const;
93 
95  double magnitude() const;
97  double squareMagnitude() const;
98 
99  void operator+=(const Vec2d& Other) { add(Other); }
100  Vec2d operator+(const Vec2d& Other) const { return added(Other); }
101  void operator-=(const Vec2d& Right) { subtract(Right); }
102  Vec2d operator-() const { return reversed(); }
103 
104  Vec2d operator-(const Vec2d& Right) const { return subtracted(Right); }
105 
106  void operator*=(const double Scalar) { multiply(Scalar); }
107  double operator*(const Vec2d& Other) const { return dot(Other); }
108 
109  Vec2d operator*(const double Scalar) const { return multiplied(Scalar); }
110 
111  void operator/=(const double Scalar) { divide(Scalar); }
112  Vec2d operator/(const double Scalar) const { return divided(Scalar); }
113  double operator^(const Vec2d& Right) const { return crossed(Right); }
114 
115  void multiply(const double Scalar);
119  Vec2d multiplied(const double Scalar) const;
120  void mirror(const Vec2d& V);
121 
122  void mirror(const Ax2d& A1);
123 
127  Vec2d mirrored(const Ax2d& A1) const;
128 
135  Vec2d mirrored(const Vec2d& V) const;
136 
137  void normalize();
141  Vec2d normalized() const;
142 
143  void reverse();
145  Vec2d reversed() const;
146  void rotate(const double Ang);
147 
150  Vec2d rotated(const double Ang) const;
151 
152  void scale(const double S);
154  Vec2d scaled(const double S) const;
155 
160  void setCoord(const int Index, const double Xi);
163  void setCoord(const double Xv, const double Yv);
166  void setLinearForm(const double A1, const Vec2d& V1, const double A2, const Vec2d& V2, const Vec2d& V3);
167 
169  void setLinearForm(const double A1, const Vec2d& V1, const double A2, const Vec2d& V2);
170 
172  void setLinearForm(const double A1, const Vec2d& V1, const Vec2d& V2);
173 
178  void setLinearForm(const Vec2d& Left, const Vec2d& Right);
179 
181  void setX(const double X);
183  void setXY(const XY& Coord);
184 
186  void setY(const double Y);
187  void subtract(const Vec2d& Right);
189  Vec2d subtracted(const Vec2d& Right) const;
190  void transform(const Trsf2d& T);
192  Vec2d transformed(const Trsf2d& T) const;
193 
195  double x() const;
197  const XY& xy() const;
198 
200  double y() const;
201 
202 protected:
203 private:
204  XY _coord;
205 };
206 } // namespace Geom
Definition: Variant.h:60
X
Definition: Globals.h:29
Definition: XY.h:33
Vec2d operator-() const
Definition: Vec2d.h:102
void operator-=(const Vec2d &Right)
Definition: Vec2d.h:101
Vector3f & operator *=(Vector3f &rclVect, const Matrix4D &rclMtrx)
Definition: Matrix.h:351
void operator/=(const double Scalar)
Definition: Vec2d.h:111
Definition: Ax2d.h:48
Vec2d operator-(const Vec2d &Right) const
Definition: Vec2d.h:104
Definition: Dir2d.h:38
void transform(Container container, OutputIt out, BinaryFunction function)
Definition: Algorithms.h:29
Y
Definition: Globals.h:29
Defines a non-persistent vector in 2D space.
Definition: Vec2d.h:34
Definition: Trsf2d.h:46
double operator^(const Vec2d &Right) const
Definition: Vec2d.h:113
Vec2d operator+(const Vec2d &Other) const
Definition: Vec2d.h:100
Vec2d operator/(const double Scalar) const
Definition: Vec2d.h:112
void operator+=(const Vec2d &Other)
Definition: Vec2d.h:99
Defines a non-persistent 2D cartesian point.
Definition: Pnt2d.h:33
DualNumber operator *(DualNumber a, DualNumber b)
Definition: DualNumber.h:71