+//=======================================================================
+//function : GetDirection
+//purpose :
+//=======================================================================
+static void GetDirection(const TopoDS_Edge& theEdge,
+ const TopoDS_Face& theFace,
+ Standard_Real& theTol,
+ gp_Pnt2d& thePnt,
+ gp_Vec2d& theDir)
+{
+ Standard_Real aFirst, aLast;
+ Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface (theEdge, theFace, aFirst, aLast);
+
+ TopAbs_Orientation anOr = theEdge.Orientation();
+ TopoDS_Vertex aVtx;
+ if (anOr == TopAbs_FORWARD)
+ {
+ aVtx = TopExp::FirstVertex (theEdge);
+ aC2d->D0 (aFirst, thePnt);
+ }
+ else
+ {
+ aVtx = TopExp::LastVertex (theEdge);
+ aC2d->D0 (aLast, thePnt);
+ }
+
+ BRepAdaptor_Surface aSurf (theFace, Standard_False);
+ theTol = BRep_Tool::Tolerance (aVtx);
+ Standard_Real aTol = Max (aSurf.UResolution (theTol), aSurf.VResolution (theTol));
+ aTol = Min (aTol, (aLast - aFirst)*0.1);
+
+ gp_Pnt2d aP2d;
+
+ if (anOr == TopAbs_FORWARD)
+ {
+ aFirst += aTol;
+ aC2d->D0 (aFirst, aP2d);
+ }
+ else
+ {
+ aLast -= aTol;
+ aC2d->D0 (aLast, aP2d);
+ }
+ theDir = gp_Vec2d (thePnt, aP2d);
+}