1 // File: BRepExtrema_Poly.cxx
2 // Created: Fri Sep 8 11:03:14 1995
3 // Author: Christophe MARION
5 #include <BRepExtrema_Poly.hxx>
7 #include <BRep_Tool.hxx>
8 #include <TopoDS_Face.hxx>
10 #include <TopExp_Explorer.hxx>
11 #include <Precision.hxx>
12 #include <Poly_Triangulation.hxx>
13 #include <TColgp_Array1OfPnt.hxx>
15 //=======================================================================
18 //=======================================================================
20 Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, const TopoDS_Shape& S2,
21 gp_Pnt& P1, gp_Pnt& P2, Standard_Real& dist)
23 dist = Precision::Infinite();
26 Handle(Poly_Triangulation) Tr;
27 TopExp_Explorer exFace;
29 Standard_Integer nbn1 = 0;
30 for (exFace.Init(S1, TopAbs_FACE);
34 const TopoDS_Face& F = TopoDS::Face(exFace.Current());
35 Tr = BRep_Tool::Triangulation(F,L);
37 nbn1 += Tr->NbNodes();
39 if (nbn1 == 0) return Standard_False;
41 Standard_Integer nbn2 = 0;
42 for (exFace.Init(S2, TopAbs_FACE);
46 const TopoDS_Face& F = TopoDS::Face(exFace.Current());
47 Tr = BRep_Tool::Triangulation(F,L);
49 nbn2 += Tr->NbNodes();
51 if (nbn2 == 0) return Standard_False;
55 TColgp_Array1OfPnt TP1(1,nbn1);
58 for (exFace.Init(S1, TopAbs_FACE);
62 const TopoDS_Face& F = TopoDS::Face(exFace.Current());
63 Tr = BRep_Tool::Triangulation(F,L);
66 const TColgp_Array1OfPnt& Nod = Tr->Nodes();
68 for (i = 1; i <= n; i++)
71 TP1.SetValue(nbn1,Nod(i).Transformed(L));
76 TColgp_Array1OfPnt TP2(1,nbn2);
79 for (exFace.Init(S2, TopAbs_FACE);
83 const TopoDS_Face& F = TopoDS::Face(exFace.Current());
84 Tr = BRep_Tool::Triangulation(F,L);
87 const TColgp_Array1OfPnt& Nod = Tr->Nodes();
89 for (i = 1; i <= n; i++)
92 TP2.SetValue(nbn2,Nod(i).Transformed(L));
97 Standard_Integer i1,i2;
98 for (i1 = 1; i1 <= nbn1; i1++)
100 const gp_Pnt& PP1 = TP1(i1);
101 for (i2 = 1; i2 <= nbn2; i2++)
103 const gp_Pnt& PP2 = TP2(i2);
104 const Standard_Real dCur = PP1.Distance(PP2);
113 return Standard_True;