Repository: FreeCAD/FreeCAD
File: src/Mod/BIM/ArchComponent.py (Python)

Code before:
        if face.Surface.TypeId == "Part::GeomCylinder":
            angle = face.Surface.Axis.getAngle(FreeCAD.Vector(0, 0, 1))
            return self.isZeroAngle(angle)
        elif face.Surface.TypeId == "Part::GeomSurfaceOfExtrusion":
            angle = face.Surface.Direction.getAngle(FreeCAD.Vector(0, 0, 1))
            return self.isZeroAngle(angle)
        elif face.Surface.TypeId == "Part::GeomPlane":
            projectedArea = 0  # dummy value, isRightAngle check is sufficient here
        elif face.findPlane() is not None:
            projectedArea = 0  # dummy value, idem
        else:
            try:
                wires = findWires(project(face, FreeCAD.Vector(0, 0, 1))[0].Edges)
                if len(wires) == 1 and not wires[0].isClosed():
                    projectedArea = 0
                else:
                    projectedArea = Face(wires).Area
            except OCCError:
                FreeCAD.Console.PrintWarning(
                    translate("Arch", f"Could not project face from {self.obj.Label}\n")
                )
                return False

        try:
            angle = face.normalAt(0, 0).getAngle(FreeCAD.Vector(0, 0, 1))
            return self.isRightAngle(angle) and projectedArea < 0.0001
        except OCCError:
            FreeCAD.Console.PrintWarning(
                translate(
                    "Arch",
                    f"Could not determine if a face from {self.obj.Label}"
                    " is vertical: normalAt() failed\n",
                )
            )
            return False

    def isFaceHorizontal(self, face):
        """Determine if a face is horizontal.

        A face is considered horizontal if its normal vector is parallel to the Z-axis.
        """
        from Part import OCCError

        try:
            angle = face.normalAt(0, 0).getAngle(FreeCAD.Vector(0, 0, 1))
            return not self.isRightAngle(angle)
        except OCCError:
            FreeCAD.Console.PrintWarning(
                translate(
                    "Arch",
                    f"Could not determine if a face from {self.obj.Label}"

Review comment (refactor):
I find the previous `isProjectedAreaZero` helper more idiomatic, but this is just a personal preference. What I really wanted to mention here since I recently learnt about it, is that we could use `Part.Precision.confusion()` instead of a magic number.

Code after:
            angle = face.Surface.Axis.getAngle(FreeCAD.Vector(0, 0, 1))
            return self.isZeroAngle(angle)
        elif face.Surface.TypeId == "Part::GeomSurfaceOfExtrusion":
            angle = face.Surface.Direction.getAngle(FreeCAD.Vector(0, 0, 1))
            return self.isZeroAngle(angle)
        elif face.Surface.TypeId == "Part::GeomPlane":
            projectedArea = 0  # dummy value, isRightAngle check is sufficient here
        elif face.findPlane() is not None:
            projectedArea = 0  # dummy value, idem
        else:
            try:
                edges = TechDraw.project(face, FreeCAD.Vector(0, 0, 1))[0].Edges
                wires = DraftGeomUtils.findWires(edges)
                if len(wires) == 1 and not wires[0].isClosed():
                    projectedArea = 0
                else:
                    projectedArea = Part.Face(wires).Area
            except Part.OCCError:
                FreeCAD.Console.PrintWarning(
                    translate("Arch", f"Could not project face from {self.obj.Label}\n")
                )
                return False

        try:
            angle = face.normalAt(0, 0).getAngle(FreeCAD.Vector(0, 0, 1))
            return self.isRightAngle(angle) and projectedArea < 0.0001
        except Part.OCCError:
            FreeCAD.Console.PrintWarning(
                translate(
                    "Arch",
                    f"Could not determine if a face from {self.obj.Label}"
                    " is vertical: normalAt() failed\n",
                )
            )
            return False

    def isRightAngle(self, angle):
        """Check if the angle is close to 90 degrees."""
        return math.isclose(angle, math.pi / 2, abs_tol=0.0005)

    def isZeroAngle(self, angle):
        """Check if the angle is close to 0 or 180 degrees."""
        if math.isclose(angle, 0, abs_tol=0.0005):
            return True
        return math.isclose(angle, math.pi, abs_tol=0.0005)

    def compute(self):
        """Compute the vertical area, horizontal area, and perimeter length.

        This method performs the following steps:
        1. Identifies the object's vertical and horizontal faces.