b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | // JCV 30/08/90 Modif passage version C++ 2.0 sur Sun |
20 | // JCV 06/12/90 Modif introduction des classes XYZ Mat dans le package gp |
21 | // Modif DPF 23/06/93 Ajout fonction Coord pour genericite 2d 3d |
22 | |
23 | #include <gp_Trsf.hxx> |
24 | #include <gp_Vec.hxx> |
25 | |
26 | inline gp_Pnt::gp_Pnt() { } |
27 | |
28 | inline gp_Pnt::gp_Pnt (const gp_XYZ& Coordinates) : coord (Coordinates) |
29 | { } |
30 | |
31 | inline gp_Pnt::gp_Pnt (const Standard_Real Xp, |
32 | const Standard_Real Yp, |
33 | const Standard_Real Zp) : coord(Xp, Yp,Zp) |
34 | { } |
35 | |
36 | inline void gp_Pnt::SetCoord (const Standard_Integer Index, |
37 | const Standard_Real Xi) |
38 | { coord.SetCoord (Index, Xi); } |
39 | |
40 | inline void gp_Pnt::SetCoord (const Standard_Real Xp, |
41 | const Standard_Real Yp, |
42 | const Standard_Real Zp) { |
43 | coord.SetCoord (Xp, Yp, Zp); |
44 | } |
45 | |
46 | inline void gp_Pnt::SetX (const Standard_Real X) |
47 | { coord.SetX (X); } |
48 | |
49 | inline void gp_Pnt::SetY (const Standard_Real Y) |
50 | { coord.SetY (Y); } |
51 | |
52 | inline void gp_Pnt::SetZ (const Standard_Real Z) |
53 | { coord.SetZ (Z); } |
54 | |
55 | inline void gp_Pnt::SetXYZ (const gp_XYZ& Coordinates) |
56 | { coord = Coordinates; } |
57 | |
58 | inline Standard_Real gp_Pnt::Coord (const Standard_Integer Index) const |
59 | { return coord.Coord(Index); } |
60 | |
61 | inline void gp_Pnt::Coord (Standard_Real& Xp, |
62 | Standard_Real& Yp, |
63 | Standard_Real& Zp) const { |
64 | coord.Coord (Xp, Yp, Zp); |
65 | } |
66 | |
67 | inline Standard_Real gp_Pnt::X() const |
68 | { return coord.X(); } |
69 | |
70 | inline Standard_Real gp_Pnt::Y() const |
71 | { return coord.Y(); } |
72 | |
73 | inline Standard_Real gp_Pnt::Z() const |
74 | { return coord.Z(); } |
75 | |
76 | inline const gp_XYZ& gp_Pnt::XYZ () const |
77 | { return coord; } |
78 | |
79 | inline const gp_XYZ& gp_Pnt::Coord () const |
80 | { return coord; } |
81 | |
82 | inline gp_XYZ& gp_Pnt::ChangeCoord () |
83 | { return coord; } |
84 | |
85 | inline void gp_Pnt::BaryCenter(const Standard_Real A, |
86 | const gp_Pnt& P, |
87 | const Standard_Real B) |
88 | { |
89 | coord.SetLinearForm(A,coord,B,P.coord); |
90 | coord.Divide(A + B); |
91 | } |
92 | |
93 | inline Standard_Boolean gp_Pnt::IsEqual |
94 | (const gp_Pnt& Other, |
95 | const Standard_Real LinearTolerance) const |
96 | { return Distance (Other) <= LinearTolerance; } |
97 | |
98 | inline Standard_Real gp_Pnt::Distance (const gp_Pnt& Other) const |
99 | { |
100 | Standard_Real d=0,dd; |
101 | const gp_XYZ& XYZ = Other.coord; |
102 | dd = coord.X(); dd -= XYZ.X(); dd *= dd; d += dd; |
103 | dd = coord.Y(); dd -= XYZ.Y(); dd *= dd; d += dd; |
104 | dd = coord.Z(); dd -= XYZ.Z(); dd *= dd; d += dd; |
105 | return(sqrt(d)); |
106 | } |
107 | |
108 | inline Standard_Real gp_Pnt::SquareDistance (const gp_Pnt& Other) const |
109 | { |
110 | Standard_Real d=0,dd; |
111 | const gp_XYZ& XYZ = Other.coord; |
112 | dd = coord.X(); dd -= XYZ.X(); dd *= dd; d += dd; |
113 | dd = coord.Y(); dd -= XYZ.Y(); dd *= dd; d += dd; |
114 | dd = coord.Z(); dd -= XYZ.Z(); dd *= dd; d += dd; |
115 | return(d); |
116 | } |
117 | |
118 | inline void gp_Pnt::Rotate (const gp_Ax1& A1, |
119 | const Standard_Real Ang) |
120 | { |
121 | gp_Trsf T; |
122 | T.SetRotation (A1, Ang); |
123 | T.Transforms (coord); |
124 | } |
125 | |
126 | inline gp_Pnt gp_Pnt::Rotated (const gp_Ax1& A1, |
127 | const Standard_Real Ang) const |
128 | { |
129 | gp_Pnt P = *this; |
130 | P.Rotate (A1, Ang); |
131 | return P; |
132 | } |
133 | |
134 | inline void gp_Pnt::Scale (const gp_Pnt& P, |
135 | const Standard_Real S) |
136 | { |
137 | gp_XYZ XYZ = P.coord; |
138 | XYZ.Multiply (1.0 - S); |
139 | coord.Multiply (S); |
140 | coord.Add (XYZ); |
141 | } |
142 | |
143 | inline gp_Pnt gp_Pnt::Scaled (const gp_Pnt& P, |
144 | const Standard_Real S) const |
145 | { |
146 | gp_Pnt Pres = *this; |
147 | Pres.Scale (P, S); |
148 | return Pres; |
149 | } |
150 | |
151 | inline gp_Pnt gp_Pnt::Transformed (const gp_Trsf& T) const |
152 | { |
153 | gp_Pnt P = *this; |
154 | P.Transform (T); |
155 | return P; |
156 | } |
157 | |
158 | inline void gp_Pnt::Translate (const gp_Vec& V) |
159 | { coord.Add (V.XYZ()); } |
160 | |
161 | inline gp_Pnt gp_Pnt::Translated (const gp_Vec& V) const |
162 | { |
163 | gp_Pnt P = *this; |
164 | P.coord.Add (V.XYZ()); |
165 | return P; |
166 | } |
167 | |
168 | inline void gp_Pnt::Translate (const gp_Pnt& P1, |
169 | const gp_Pnt& P2) |
170 | { |
171 | coord.Add (P2.coord); |
172 | coord.Subtract (P1.coord); |
173 | } |
174 | |
175 | inline gp_Pnt gp_Pnt::Translated (const gp_Pnt& P1, |
176 | const gp_Pnt& P2) const |
177 | { |
178 | gp_Pnt P = *this; |
179 | P.Translate (P1 , P2); |
180 | return P; |
181 | } |
182 | |