diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index f02815ae6e..f538576ff6 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -107,6 +107,7 @@ # include # include # include +# include # include # include # include @@ -4189,6 +4190,27 @@ bool TopoShape::isInfinite() const } } +bool TopoShape::isPlanar(double tol) const +{ + if (_Shape.IsNull() || _Shape.ShapeType() != TopAbs_FACE) { + return false; + } + + BRepAdaptor_Surface adapt(TopoDS::Face(_Shape)); + if (adapt.GetType() == GeomAbs_Plane) { + return true; + } + + TopLoc_Location loc; + Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(_Shape), loc); + if (surf.IsNull()) { + return false; + } + + GeomLib_IsPlanarSurface check(surf, tol); + return check.IsPlanar(); +} + bool TopoShape::isCoplanar(const TopoShape &other, double tol) const { if(isNull() || other.isNull()) return false; diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 91b8e9bc5e..bf608f6159 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -228,6 +228,8 @@ public: bool findPlane(gp_Pln &pln, double tol=-1) const; /// Returns true if the expansion of the shape is infinite, false otherwise bool isInfinite() const; + /// Checks whether the shape is a planar face + bool isPlanar(double tol = 1.0e-7) const; //@} /** @name Boolean operation*/