b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | // Modif JCV 08/01/91 modifs suite a la deuxieme revue de projet |
16 | // et introduction des classes XY, Mat2d. |
17 | // Modif DPF 23/06/93 Ajout fonction Coord pour genericite 2d 3d |
18 | |
19 | #include <gp_Vec2d.hxx> |
20 | #include <gp_Ax2d.hxx> |
21 | #include <gp_Trsf2d.hxx> |
22 | |
23 | inline gp_Pnt2d::gp_Pnt2d (const gp_XY& Coordinates) : coord (Coordinates) |
24 | { } |
25 | |
26 | inline gp_Pnt2d::gp_Pnt2d (const Standard_Real Xp, |
27 | const Standard_Real Yp) : coord (Xp, Yp) |
28 | { } |
29 | |
30 | inline gp_Pnt2d::gp_Pnt2d() { } |
31 | |
32 | inline Standard_Real gp_Pnt2d::Coord(const Standard_Integer Index) const { return coord.Coord(Index); } |
33 | |
34 | inline void gp_Pnt2d::SetX (const Standard_Real X) |
35 | { coord.SetX (X); } |
36 | |
37 | inline void gp_Pnt2d::SetY (const Standard_Real Y) |
38 | { coord.SetY (Y); } |
39 | |
40 | inline void gp_Pnt2d::SetXY (const gp_XY& Coordinates) |
41 | { coord = Coordinates; } |
42 | |
43 | inline void gp_Pnt2d::SetCoord (const Standard_Real Xp, |
44 | const Standard_Real Yp) |
45 | { coord.SetCoord (Xp, Yp);} |
46 | |
47 | inline void gp_Pnt2d::SetCoord (const Standard_Integer Index, |
48 | const Standard_Real Xi) |
49 | { coord.SetCoord (Index, Xi); } |
50 | |
51 | inline void gp_Pnt2d::Coord (Standard_Real& Xp, |
52 | Standard_Real& Yp) const |
53 | { coord.Coord (Xp, Yp); } |
54 | |
55 | inline Standard_Real gp_Pnt2d::X() const |
56 | { return coord.X(); } |
57 | |
58 | inline Standard_Real gp_Pnt2d::Y() const |
59 | { return coord.Y(); } |
60 | |
61 | inline const gp_XY& gp_Pnt2d::XY () const |
62 | { return coord; } |
63 | |
64 | inline const gp_XY& gp_Pnt2d::Coord () const |
65 | { return coord; } |
66 | |
67 | inline gp_XY& gp_Pnt2d::ChangeCoord () |
68 | { return coord; } |
69 | |
70 | inline Standard_Boolean gp_Pnt2d::IsEqual |
71 | (const gp_Pnt2d& Other, |
72 | const Standard_Real LinearTolerance) const |
73 | { return Distance (Other) <= LinearTolerance; } |
74 | |
75 | inline Standard_Real gp_Pnt2d::Distance (const gp_Pnt2d& Other) const |
76 | { |
77 | const gp_XY& XY = Other.coord; |
78 | Standard_Real X = coord.X() - XY.X(); |
79 | Standard_Real Y = coord.Y() - XY.Y(); |
80 | return sqrt (X * X + Y * Y); |
81 | } |
82 | |
83 | inline Standard_Real gp_Pnt2d::SquareDistance (const gp_Pnt2d& Other) const |
84 | { |
85 | const gp_XY& XY = Other.coord; |
86 | Standard_Real X = coord.X() - XY.X(); |
87 | Standard_Real Y = coord.Y() - XY.Y(); |
88 | return (X * X + Y * Y); |
89 | } |
90 | |
91 | inline void gp_Pnt2d::Rotate (const gp_Pnt2d& P, |
92 | const Standard_Real Ang) |
93 | { |
94 | gp_Trsf2d T; |
95 | T.SetRotation (P, Ang); |
96 | T.Transforms (coord); |
97 | } |
98 | |
99 | inline gp_Pnt2d gp_Pnt2d::Rotated (const gp_Pnt2d& P, |
100 | const Standard_Real Ang) const |
101 | { |
102 | gp_Pnt2d Pres = *this; |
103 | Pres.Rotate (P, Ang); |
104 | return Pres; |
105 | } |
106 | |
107 | inline void gp_Pnt2d::Scale (const gp_Pnt2d& P, |
108 | const Standard_Real S) |
109 | { |
110 | gp_XY XY = P.coord; |
111 | XY.Multiply (1.0 - S); |
112 | coord.Multiply (S); |
113 | coord.Add (XY); |
114 | } |
115 | |
116 | inline gp_Pnt2d gp_Pnt2d::Scaled (const gp_Pnt2d& P, |
117 | const Standard_Real S) const |
118 | { |
119 | gp_Pnt2d Pres = *this; |
120 | Pres.Scale (P, S); |
121 | return Pres; |
122 | } |
123 | |
124 | inline gp_Pnt2d gp_Pnt2d::Transformed (const gp_Trsf2d& T) const |
125 | { |
126 | gp_Pnt2d Pres = *this; |
127 | Pres.Transform (T); |
128 | return Pres; |
129 | } |
130 | |
131 | inline void gp_Pnt2d::Translate (const gp_Vec2d& V) |
132 | { coord.Add (V.XY()); } |
133 | |
134 | inline gp_Pnt2d gp_Pnt2d::Translated (const gp_Vec2d& V) const |
135 | { |
136 | gp_Pnt2d P = *this; |
137 | P.coord.Add (V.XY ()); |
138 | return P; |
139 | } |
140 | |
141 | inline void gp_Pnt2d::Translate (const gp_Pnt2d& P1, |
142 | const gp_Pnt2d& P2) |
143 | { |
144 | coord.Add (P2.coord); |
145 | coord.Subtract (P1.coord); |
146 | } |
147 | |
148 | inline gp_Pnt2d gp_Pnt2d::Translated (const gp_Pnt2d& P1, |
149 | const gp_Pnt2d& P2) const |
150 | { |
151 | gp_Pnt2d P = *this; |
152 | P.Translate (P1, P2); |
153 | return P; |
154 | } |
155 | |