def test_DumpJsonToString(self) -> None:
     """ Since opencascade 7x, some objects can be serialized to json
     """
     # create a sphere with a radius of 10.
     sph = BRepPrimAPI_MakeSphere(10.).Shape()
     # compute the Bnd box for this sphere
     bnd_box = Bnd_Box()
     brepbndlib_Add(sph, bnd_box)
     # check the result
     corner_min = bnd_box.CornerMin()
     self.assertEqual([round(corner_min.X(), 3), round(corner_min.Y(), 3), round(corner_min.Z(), 3)],
                      [-10., -10., -10.])
     # check dump json export is working
     json_string = bnd_box.DumpJsonToString()
     # try to load the output string
     json_imported_dict = json.loads("{" + json_string + "}")
     self.assertTrue(len(json_imported_dict) > 0)  # at least one entry
 def test_DumpJsonToString(self):
     """ Since opencascade 7x, some objects can be serialized to json
     """
     # create a sphere with a radius of 10.
     sph = BRepPrimAPI_MakeSphere(10.).Shape()
     # compute the Bnd box for this sphere
     bnd_box = Bnd_Box()
     brepbndlib_Add(sph, bnd_box)
     # check the result
     corner_min = bnd_box.CornerMin()
     self.assertEqual([
         round(corner_min.X(), 3),
         round(corner_min.Y(), 3),
         round(corner_min.Z(), 3)
     ], [-10., -10., -10.])
     # check dump json is working
     json_string = bnd_box.DumpJsonToString()
     expected_output = '"Bnd_Box": {"CornerMin": [-10, -10, -10], "CornerMax": [10, 10, 10], "Gap": 1e-07, "Flags": 0}'
     self.assertEqual(json_string, expected_output)
Exemple #3
0
    def aabb(self, precision=0.0, optimal=False):
        """Compute the axis aligned bounding box of the surface.

        Parameters
        ----------
        precision : float, optional
        optimal : bool, optional

        Returns
        -------
        :class:`~compas.geometry.Box`

        """
        box = Bnd_Box()
        if optimal:
            add = BndLib_AddSurface_AddOptimal
        else:
            add = BndLib_AddSurface_Add
        add(GeomAdaptor_Surface(self.occ_surface), precision, box)
        return Box.from_diagonal(
            (Point.from_occ(box.CornerMin()), Point.from_occ(box.CornerMax())))