Ejemplo n.º 1
0
def test_check_geometry_parameter():
    """Test the check_geometry_parameter function of the validation module.
    """
    valid_params = [
        2.0,
        -2.5,
        3,
        0,
        350
    ]
    expect_type_errors = [
        "test",
        "3.4",
        "3",
        (1, 2),
        [1, 2]
    ]
    expect_value_errors = [
        float("nan"),
        float("inf"),
        float("-inf")
    ]
    for param in valid_params:
        assert isinstance(validation.check_geometry_parameter(param), float)
    for param in expect_type_errors:
        with pytest.raises(TypeError):
            validation.check_geometry_parameter(param)
    for param in expect_value_errors:
        with pytest.raises(ValueError):
            validation.check_geometry_parameter(param)
Ejemplo n.º 2
0
    def __init__(self, center_x, center_y, radius):
        """Circle2D constructor

        Args:
            center_x (float): The x coordinate of the circle center point
            center_y (float): The y coordinate of the circle center point
            radius (float): The radius of the circle
        """
        self.center_x = check_geometry_parameter(center_x)
        self.center_y = check_geometry_parameter(center_y)
        self.radius = check_radius(radius)
Ejemplo n.º 3
0
    def __init__(self, center_x, center_y, center_z, radius):
        """Sphere constructor

        Args:
            center_x (float): The x coordinate of the sphere center point
            center_y (float): The y coordinate of the sphere center point
            center_z (float): The z coordinate of the sphere center point
            radius (float): The radius of the sphere
        """
        self.center_x = check_geometry_parameter(center_x)
        self.center_y = check_geometry_parameter(center_y)
        self.center_z = check_geometry_parameter(center_z)
        self.radius = check_radius(radius)
def scale_vector(vec, scale):
    """Multiply each vector element with the scale factor.

    Args:
        vec (tuple (float, float, float)): The vector that shall be scaled
        scale (float): The scale factor

    Returns:
        tuple (float, float, float): The scaled vector
    """
    checked_vec = check_vector(vec)
    checked_scale = check_geometry_parameter(scale)
    return tuple([checked_scale * vec_elem for vec_elem in checked_vec])
def get_as_rotation_quaternion(axis, angle):
    """Convert an axis and an angle into a rotation quaternion.

    Args:
        axis (tuple (float, float, float)): A vector representing a rotation axis
        angle (float): The rotation angle (radiant) for a right-handed rotation

    Returns:
        tuple (float, float, float, float): The rotation quaternion defined as
          q = (w, qx, qy, qz)
    """
    checked_axis = normalize_vector(check_direction_vector(axis))
    checked_angle = check_geometry_parameter(angle)
    omega = 0.5 * checked_angle
    return (math.cos(omega), ) + tuple(
        [math.sin(omega) * vec_elem for vec_elem in checked_axis])
Ejemplo n.º 6
0
    def __init__(self, normal_vec, d_origin, ref_point, radius):
        """Plane constructor

        Args:
            normal_vec (tuple (float, float, float)): The normal vector of the plane
            d_origin (float): The smallest distance of the plane from the origin
            ref_point (tuple (float, float, float)): The center point
              for the plane point creation radius
            radius (float): The plane point creation radius
        """
        n_vec = check_direction_vector(normal_vec)
        self.normal_vec = normalize_vector(n_vec)
        self.d_origin = check_geometry_parameter(d_origin)
        self.radius = check_radius(radius)
        self.ref_point = check_vector(ref_point)
        if not math.isclose(calc_dot_product(self.normal_vec, self.ref_point) -
                            self.d_origin,
                            0.0,
                            abs_tol=0.000001):
            raise ValueError(
                """Invalid reference point. Expected the reference point
              to lie on the plane""")