+static Handle(Geom_Surface) baseSurface(const TopoDS_Face& theFace)
+{
+ Handle(Geom_Surface) aSurf = BRep_Tool::Surface(theFace);
+ while (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
+ Handle(Geom_RectangularTrimmedSurface) rts =
+ Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
+ aSurf = rts->BasisSurface();
+ }
+ return aSurf;
+}
+
+bool GeomAPI_Face::isSameGeometry(const std::shared_ptr<GeomAPI_Shape> theShape) const
+{
+ if (!theShape->isFace())
+ return false;
+ if (isSame(theShape))
+ return true;
+
+ GeomFacePtr anOther = theShape->face();
+ if (isPlanar() && anOther->isPlanar()) {
+ GeomPlanePtr anOwnPlane = getPlane();
+ GeomPlanePtr anOtherPlane = anOther->getPlane();
+ return anOwnPlane->isCoincident(anOtherPlane);
+ }
+
+ TopoDS_Face anOwnFace = TopoDS::Face(impl<TopoDS_Shape>());
+ TopoDS_Face anOtherFace = TopoDS::Face(theShape->impl<TopoDS_Shape>());
+
+ Handle(Geom_Surface) anOwnSurf = baseSurface(anOwnFace);
+ Handle(Geom_Surface) anOtherSurf = baseSurface(anOtherFace);
+
+ // case of two elementary surfaces
+ if (anOwnSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) &&
+ anOtherSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
+ {
+ Handle(GeomAdaptor_HSurface) aGA1 = new GeomAdaptor_HSurface(anOwnSurf);
+ Handle(GeomAdaptor_HSurface) aGA2 = new GeomAdaptor_HSurface(anOtherSurf);
+
+ Handle(BRepTopAdaptor_TopolTool) aTT1 = new BRepTopAdaptor_TopolTool();
+ Handle(BRepTopAdaptor_TopolTool) aTT2 = new BRepTopAdaptor_TopolTool();
+
+ try {
+ IntPatch_ImpImpIntersection anIIInt(aGA1, aTT1, aGA2, aTT2,
+ Precision::Confusion(),
+ Precision::Confusion());
+ if (!anIIInt.IsDone() || anIIInt.IsEmpty())
+ return false;
+
+ return anIIInt.TangentFaces();
+ }
+ catch (Standard_Failure const&) {
+ return false;
+ }
+ }
+
+ // case of two cylindrical surfaces, at least one of which is a swept surface
+ // swept surfaces: SurfaceOfLinearExtrusion, SurfaceOfRevolution
+ if ((anOwnSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
+ anOwnSurf->IsKind(STANDARD_TYPE(Geom_SweptSurface))) &&
+ (anOtherSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
+ anOtherSurf->IsKind(STANDARD_TYPE(Geom_SweptSurface))))
+ {
+ GeomCylinderPtr anOwnCyl = getCylinder();
+ GeomCylinderPtr anOtherCyl = anOther->getCylinder();
+ if (anOwnCyl && anOtherCyl)
+ return anOwnCyl->isCoincident(anOtherCyl);
+
+ // compare two swept surfaces of the same type
+ if ((anOwnSurf->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) &&
+ anOtherSurf->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) ||
+ (anOwnSurf->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution)) &&
+ anOtherSurf->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution)))) {
+ Handle(Geom_SweptSurface) anOwnSwept = Handle(Geom_SweptSurface)::DownCast(anOwnSurf);
+ Handle(Geom_SweptSurface) anOtherSwept = Handle(Geom_SweptSurface)::DownCast(anOtherSurf);
+
+ const gp_Dir& anOwnDir = anOwnSwept->Direction();
+ const gp_Dir& anOtherDir = anOtherSwept->Direction();
+
+ if (anOwnDir.IsParallel(anOtherDir, Precision::Angular())) {
+ Handle(Geom_Curve) anOwnCurve = anOwnSwept->BasisCurve();
+ Handle(Geom_Curve) anOtherCurve = anOtherSwept->BasisCurve();
+ GeomAPI_ExtremaCurveCurve anExtrema(anOwnCurve, anOtherCurve);
+ return anExtrema.Extrema().IsParallel() &&
+ anExtrema.TotalLowerDistance() < Precision::Confusion();
+ }
+ }
+ }
+
+ return false;
+}
+
+bool GeomAPI_Face::isCylindrical() const