summaryrefslogtreecommitdiff
path: root/inc/gp_XY.lxx
blob: 275f90cfe31bb3ac3923ea9239ace06679097b08 (plain)
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
// File gp_XY.lxx, JCV 05/01/91
// LPA et JCV 07/92 

#include <Standard_OutOfRange.hxx>
#include <Standard_ConstructionError.hxx>
#include <gp.hxx>
#include <gp_Mat2d.hxx>

inline gp_XY::gp_XY () : x(0.), y(0.) { } 

inline gp_XY::gp_XY (const Standard_Real X,
		     const Standard_Real Y) :  x (X),  y (Y) { }

inline void gp_XY::SetCoord (const Standard_Integer i,
			     const Standard_Real X)
{
  Standard_OutOfRange_Raise_if( i < 1 || i > 2,NULL);
  (&x)[i-1] = X;
}

inline void gp_XY::SetCoord (const Standard_Real X,
			     const Standard_Real Y)
{ x = X;  y = Y; }

inline void gp_XY::SetX (const Standard_Real X)
{ x = X; }

inline void gp_XY::SetY (const Standard_Real Y)
{ y = Y; }

inline Standard_Real gp_XY::Coord (const Standard_Integer i) const
{
  Standard_OutOfRange_Raise_if( i < 1 || i > 2,NULL);
  return (&x)[i-1];
}

inline void gp_XY::Coord (Standard_Real& X,
			  Standard_Real& Y) const
{ X = x;  Y = y; }

inline Standard_Real gp_XY::X () const
{ return x; }

inline Standard_Real gp_XY::Y () const
{ return y; }

inline Standard_Real gp_XY::Modulus () const
{ 
  return sqrt (x * x + y * y);
}

inline Standard_Real gp_XY::SquareModulus () const
{
  return x * x + y * y;
}

inline void gp_XY::Add (const gp_XY& Other) {
  x += Other.x;
  y += Other.y;
}

inline gp_XY gp_XY::Added (const gp_XY& Other) const {
  return gp_XY(x + Other.X(),y + Other.Y());
}

inline Standard_Real gp_XY::Crossed (const gp_XY& Right) const {
  return x * Right.y - y * Right.x;
}

inline Standard_Real gp_XY::CrossMagnitude (const gp_XY& Right) const
{
  Standard_Real val = x * Right.y - y * Right.x;
  if (val < 0) val = - val;
  return val;
}

inline Standard_Real gp_XY::CrossSquareMagnitude (const gp_XY& Right) const {
  Standard_Real Zresult =  x * Right.y - y * Right.x;
  return Zresult * Zresult;
}

inline void gp_XY::Divide (const Standard_Real Scalar)
{
  x /= Scalar;
  y /= Scalar;
}

inline gp_XY gp_XY::Divided (const Standard_Real Scalar) const {
  return gp_XY(x / Scalar,y / Scalar);
}

inline Standard_Real gp_XY::Dot (const gp_XY& Other) const
{
  return x * Other.x + y * Other.y;
}

inline void gp_XY::Multiply (const Standard_Real Scalar)
{
  x *= Scalar;
  y *= Scalar;
}

inline void gp_XY::Multiply (const gp_XY& Other)
{
  x *= Other.x;
  y *= Other.y;
}

inline void gp_XY::Multiply (const gp_Mat2d& Matrix)
{
  Standard_Real Xresult = Matrix.matrix[0][0] * x + Matrix.matrix[0][1] * y;
  y                     = Matrix.matrix[1][0] * x + Matrix.matrix[1][1] * y;
  x                     = Xresult;
}

inline gp_XY gp_XY::Multiplied (const Standard_Real Scalar) const {
  return gp_XY(x * Scalar,y * Scalar);
}

inline gp_XY gp_XY::Multiplied (const gp_XY& Other) const {
  return(gp_XY(x * Other.X(),y * Other.Y()));
}

inline gp_XY gp_XY::Multiplied (const gp_Mat2d& Matrix) const
{
  return gp_XY (Matrix.matrix[0][0] * x + Matrix.matrix[0][1] * y,
		Matrix.matrix[1][0] * x + Matrix.matrix[1][1] * y);
}

inline void gp_XY::Normalize ()
{
  Standard_Real D = Modulus();
  Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
  x = x / D;   y = y / D;
}

inline gp_XY gp_XY::Normalized () const
{
  Standard_Real D = Modulus();
  Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
  return gp_XY (x / D, y / D);
}

inline void gp_XY::Reverse ()
{  x = - x;    y = - y;  }

inline gp_XY gp_XY::Reversed () const
{
  gp_XY Coord2D = *this;
  Coord2D.Reverse();
  return Coord2D;
}

inline void gp_XY::SetLinearForm (const Standard_Real L,
				  const gp_XY& Left,
				  const Standard_Real R,
				  const gp_XY& Right) {
  x = L * Left.x + R * Right.x;
  y = L * Left.y + R * Right.y;
}

inline void gp_XY::SetLinearForm (const Standard_Real L,
				  const gp_XY& Left,
				  const gp_XY& Right) {
  x = L * Left.x + Right.x;
  y = L * Left.y + Right.y;
}

inline void gp_XY::SetLinearForm (const gp_XY& Left,
				  const gp_XY& Right) {
  x = Left.x + Right.x;
  y = Left.y + Right.y;
}

inline void gp_XY::SetLinearForm (const Standard_Real A1,
				  const gp_XY& XY1,
				  const Standard_Real A2,
				  const gp_XY& XY2,
				  const gp_XY& XY3) {
  x = A1 * XY1.x + A2 * XY2.x + XY3.x;
  y = A1 * XY1.y + A2 * XY2.y + XY3.y;
}

inline void gp_XY::Subtract (const gp_XY& Right)
{
  x -= Right.x;
  y -= Right.y;
}

inline gp_XY gp_XY::Subtracted (const gp_XY& Right) const
{
  gp_XY Coord2D = *this;
  Coord2D.Subtract(Right);
  return Coord2D;
}

inline gp_XY operator* (const gp_Mat2d& Matrix,
			const gp_XY& Coord1) {
  return Coord1.Multiplied(Matrix);
}

inline gp_XY operator* (const Standard_Real Scalar,
			const gp_XY& Coord1) {
  return Coord1.Multiplied(Scalar);
}