1 // File: GEOMAlgo_SurfaceTools.cxx
2 // Created: Thu Jan 27 11:05:16 2005
3 // Author: Peter KURNEV
7 #include <GEOMAlgo_SurfaceTools.ixx>
12 #include <gp_Cylinder.hxx>
13 #include <gp_Sphere.hxx>
21 #include <GeomAbs_SurfaceType.hxx>
22 #include <GeomAdaptor_Surface.hxx>
25 //=======================================================================
28 //=======================================================================
29 Standard_Integer GEOMAlgo_SurfaceTools::GetState(const gp_Pnt& aP,
30 const GeomAdaptor_Surface& aGAS,
31 const Standard_Real aTol,
34 Standard_Integer iErr;
35 Standard_Real aDp, aR;
36 GeomAbs_SurfaceType aType;
42 aState=TopAbs_UNKNOWN;
49 aDp=GEOMAlgo_SurfaceTools::Distance(aP, aPln);
52 case GeomAbs_Cylinder:
55 aDp=GEOMAlgo_SurfaceTools::Distance(aP, aCyl);
61 aDp=GEOMAlgo_SurfaceTools::Distance(aP, aSph);
65 iErr=1; // unprocessed surface type
74 else if (aDp<aR-aTol) {
81 //=======================================================================
84 //=======================================================================
85 Standard_Integer GEOMAlgo_SurfaceTools::GetState(const gp_Pnt& aP,
86 const Handle(Geom_Surface)& aSurf,
87 const Standard_Real aTol,
90 Standard_Integer iErr;
91 GeomAdaptor_Surface aGAS;
93 aState=TopAbs_UNKNOWN;
96 iErr=GEOMAlgo_SurfaceTools::GetState(aP, aGAS, aTol, aState);
100 //=======================================================================
101 //function : ReverseState
103 //=======================================================================
104 TopAbs_State GEOMAlgo_SurfaceTools::ReverseState(const TopAbs_State aState)
106 TopAbs_State aRSt=aState;
121 //=======================================================================
122 //function : Distance
124 //=======================================================================
125 Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP,
126 const gp_Sphere& aSph)
130 const gp_Pnt& aLoc=aSph.Location();
131 aD=aLoc.Distance(aP);
135 //=======================================================================
136 //function : Distance
138 //=======================================================================
139 Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP,
140 const gp_Cylinder& aCyl)
144 const gp_Ax1& aAxis=aCyl.Axis();
146 aD=aLin.Distance(aP);
150 //=======================================================================
151 //function : Distance
153 //=======================================================================
154 Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP,
159 const gp_Ax3& aPos=aPL.Position();
160 const gp_Pnt& aLoc=aPos.Location ();
161 const gp_Dir& aDir=aPos.Direction();
163 aD= (aDir.X() * (aP.X() - aLoc.X()) +
164 aDir.Y() * (aP.Y() - aLoc.Y()) +
165 aDir.Z() * (aP.Z() - aLoc.Z()));
168 //=======================================================================
169 //function : IsCoaxial
171 //=======================================================================
172 Standard_Boolean GEOMAlgo_SurfaceTools::IsCoaxial(const gp_Pnt& aP1,
174 const gp_Cylinder& aCyl,
175 const Standard_Real aTol)
177 Standard_Boolean bRet=Standard_False;
180 gp_Vec aV12(aP1, aP2);
183 const gp_Ax1& aAxis=aCyl.Axis();
184 const gp_Dir& aDAxis=aAxis.Direction();
186 aSM=fabs(aD12*aDAxis);
187 if (fabs(1.-aSM) > aTol) {
193 //=======================================================================
194 //function : IsAnalytic
196 //=======================================================================
197 Standard_Boolean GEOMAlgo_SurfaceTools::IsAnalytic(const Handle(Geom_Surface)& aSurf)
199 Standard_Boolean bRet;
200 GeomAbs_SurfaceType aType;
201 GeomAdaptor_Surface aGAS;
204 aType=aGAS.GetType();
205 bRet=(aType==GeomAbs_Plane ||
206 aType==GeomAbs_Cylinder ||
207 aType==GeomAbs_Sphere);
210 //=======================================================================
211 //function : IsConformState
213 //=======================================================================
214 Standard_Boolean GEOMAlgo_SurfaceTools::IsConformState(const TopAbs_State aST1,
215 const GEOMAlgo_State aST2)
217 Standard_Boolean bRet=Standard_False;
221 if (aST1==TopAbs_IN) {
225 case GEOMAlgo_ST_OUT:
226 if (aST1==TopAbs_OUT) {
231 if (aST1==TopAbs_ON) {
235 case GEOMAlgo_ST_ONIN:
236 if (aST1==TopAbs_ON || aST1==TopAbs_IN) {
240 case GEOMAlgo_ST_ONOUT:
241 if (aST1==TopAbs_ON || aST1==TopAbs_OUT) {