def test_mesh_for_duplicate_points_no_spot(self):
        for params in testutils.BINARY_SYSTEM_PARAMS.values():
            s = prepare_binary_system(params)
            # reducing runtime of the test
            s.primary.discretization_factor = up.radians(7)
            s.init()
            components_distance = s.orbit.orbital_motion(phase=0.0)[0][0]

            orbital_position_container = OrbitalPositionContainer(
                primary=StarContainer.from_properties_container(
                    s.primary.to_properties_container()),
                secondary=StarContainer.from_properties_container(
                    s.secondary.to_properties_container()),
                position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
                **s.properties_serializer())

            orbital_position_container.build_mesh(
                components_distance=components_distance)

            for component in ['primary', 'secondary']:
                component_instance = getattr(orbital_position_container,
                                             component)
                distance = round(
                    find_nearest_dist_3d(list(component_instance.points)), 10)

                if distance < 1e-10:
                    bad_points = []
                    for i, point in enumerate(component_instance.points):
                        for j, xx in enumerate(component_instance.points[i +
                                                                         1:]):
                            dist = np.linalg.norm(point - xx)
                            if dist <= 1e-10:
                                print(f'Match: {point}, {i}, {j}')
                                bad_points.append(point)
                self.assertFalse(distance < 1e-10)
 def test_build_mesh_detached_with_overlapped_like_umbra():
     s = testutils.prepare_binary_system(
         testutils.BINARY_SYSTEM_PARAMS['detached'],
         spots_primary=list(reversed(testutils.SPOTS_OVERLAPPED)))
     s.primary.discretization_factor = up.radians(5)
     s.secondary.discretization_factor = up.radians(5)
     orbital_position_container = OrbitalPositionContainer(
         primary=StarContainer.from_properties_container(
             s.primary.to_properties_container()),
         secondary=StarContainer.from_properties_container(
             s.secondary.to_properties_container()),
         position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
         **s.properties_serializer())
     orbital_position_container.build_mesh(components_distance=1.0)
 def test_build_mesh_detached_with_overlapped_spots(self):
     s = testutils.prepare_binary_system(
         testutils.BINARY_SYSTEM_PARAMS['detached'],
         spots_primary=testutils.SPOTS_OVERLAPPED)
     s.primary.discretization_factor = up.radians(5)
     s.secondary.discretization_factor = up.radians(5)
     orbital_position_container = OrbitalPositionContainer(
         primary=StarContainer.from_properties_container(
             s.primary.to_properties_container()),
         secondary=StarContainer.from_properties_container(
             s.secondary.to_properties_container()),
         position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
         **s.properties_serializer())
     with self.assertRaises(Exception) as context:
         orbital_position_container.build_mesh(components_distance=1.0)
     self.assertTrue(
         "Please, specify spots wisely" in str(context.exception))
    def generator_test_mesh(key, d, length):
        s = prepare_binary_system(testutils.BINARY_SYSTEM_PARAMS[key])
        s.primary.discretization_factor = d
        s.secondary.discretization_factor = d

        orbital_position_container = OrbitalPositionContainer(
            primary=StarContainer.from_properties_container(
                s.primary.to_properties_container()),
            secondary=StarContainer.from_properties_container(
                s.secondary.to_properties_container()),
            position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
            **s.properties_serializer())
        orbital_position_container.build_mesh(components_distance=1.0)

        obtained_primary = np.round(orbital_position_container.primary.points,
                                    4)
        obtained_secondary = np.round(
            orbital_position_container.secondary.points, 4)
        assert_array_equal([len(obtained_primary),
                            len(obtained_secondary)], length)
    def test_make_sure_spots_are_not_overwriten_in_star_instance(self):
        s = testutils.prepare_binary_system(
            testutils.BINARY_SYSTEM_PARAMS["detached"],
            spots_primary=testutils.SPOTS_META["primary"],
            spots_secondary=testutils.SPOTS_META["secondary"])
        s.primary.discretization_factor = up.radians(10)
        s.secondary.discretization_factor = up.radians(10)

        orbital_position_container = OrbitalPositionContainer(
            primary=StarContainer.from_properties_container(
                s.primary.to_properties_container()),
            secondary=StarContainer.from_properties_container(
                s.secondary.to_properties_container()),
            position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
            **s.properties_serializer())
        orbital_position_container.build_mesh(components_distance=1.0)
        self.assertTrue(is_empty(s.primary.spots[0].points))
        self.assertTrue(is_empty(s.secondary.spots[0].points))

        self.assertTrue(is_empty(s.primary.spots[0].faces))
        self.assertTrue(is_empty(s.secondary.spots[0].faces))
    def generator_test_mesh(self, key, d):
        s = testutils.prepare_binary_system(
            testutils.BINARY_SYSTEM_PARAMS[key],
            spots_primary=testutils.SPOTS_META["primary"],
            spots_secondary=testutils.SPOTS_META["secondary"])
        s.primary.discretization_factor = d
        s.secondary.discretization_factor = d
        orbital_position_container = OrbitalPositionContainer(
            primary=StarContainer.from_properties_container(
                s.primary.to_properties_container()),
            secondary=StarContainer.from_properties_container(
                s.secondary.to_properties_container()),
            position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
            **s.properties_serializer())
        orbital_position_container.build_mesh(components_distance=1.0)

        self.assertTrue(
            len(orbital_position_container.primary.spots) == 1
            and len(orbital_position_container.secondary.spots) == 1)
        self.assertTrue(
            not is_empty(orbital_position_container.primary.spots[0].points))
        self.assertTrue(
            not is_empty(orbital_position_container.secondary.spots[0].points))