# Path: tracer/spatial_geometry.py
# def generate_transform(axis, angle, translation):
#     """Generates a transformation matrix                                                      
#     Arguments: axis - a 3-component 1D array giving the unit vector to rotate about          
#     angle - angle of rotation counter clockwise in radians about the given axis in the 
#     parent frame                         
#     translation - a 3-component column vector giving the translation along the coordinates
#     of the parent object/assembly
#     """  
#     rot = general_axis_rotation(axis, angle)
#     return N.vstack((N.hstack((rot, translation)), N.r_[[0,0,0,1]]))
# 
# def rotx(ang):
#     """Generate a homogenous trransform for ang radians around the x axis"""
#     s = sin(ang); c = cos(ang)
#     return N.array([
#         [1., 0, 0, 0],
#         [0, c,-s, 0],
#         [0, s, c, 0],
#         [0, 0, 0, 1]
#     ])


import unittest
import numpy as N
from tracer.spatial_geometry import generate_transform, rotx
from tracer.boundary_shape import *


class TestInBounds(unittest.TestCase):
    def setUp(self):
        self.points = N.array([
            [0.,0.,0.],
            [1.,1.,1.],
            [2.,2.,2.]])
    
    def test_sphere(self):
        """Sphere bounding volume"""
        sphere = BoundarySphere(radius=2.)
        N.testing.assert_array_equal(sphere.in_bounds(self.points), [True, True, False])
    
    def test_cylinder(self):
        """Cylinder bounding volume"""
        cyl = BoundaryCylinder(diameter=3.)
        N.testing.assert_array_equal(cyl.in_bounds(self.points), [True, True, False])
    
    def test_plane(self):
        """Translated plane section of a volume"""
        plane = BoundaryPlane(rotation=rotx(-N.pi/6)[:3,:3], location=N.r_[0., 1., 0.])
        N.testing.assert_array_equal(plane.in_bounds(self.points), [False, True, True])

class TestSphereBoundingRect(unittest.TestCase):
    def setUp(self):
        # Create some surfaces to intersect with spheres.
        self.at_origin_xy = N.eye(4)
        self.at_origin_yz = generate_transform(N.r_[0, 1, 0], N.pi/2, \
            N.c_[[0,0,0]])

# Path: tracer/spatial_geometry.py
# def generate_transform(axis, angle, translation):
#     """Generates a transformation matrix                                                      
#     Arguments: axis - a 3-component 1D array giving the unit vector to rotate about          
#     angle - angle of rotation counter clockwise in radians about the given axis in the 
#     parent frame                         
#     translation - a 3-component column vector giving the translation along the coordinates
#     of the parent object/assembly
#     """  
#     rot = general_axis_rotation(axis, angle)
#     return N.vstack((N.hstack((rot, translation)), N.r_[[0,0,0,1]]))
# 
# def rotx(ang):
#     """Generate a homogenous trransform for ang radians around the x axis"""
#     s = sin(ang); c = cos(ang)
#     return N.array([
#         [1., 0, 0, 0],
#         [0, c,-s, 0],
#         [0, s, c, 0],
#         [0, 0, 0, 1]
#     ])


# Path: tests/test_boundary_surface.py
import unittest
import numpy as N
from tracer.spatial_geometry import generate_transform, rotx
from tracer.boundary_shape import *



class TestInBounds(unittest.TestCase):
    def setUp(self):
        self.points = N.array([
            [0.,0.,0.],
            [1.,1.,1.],
            [2.,2.,2.]])
    
    def test_sphere(self):
        """Sphere bounding volume"""
        sphere = BoundarySphere(radius=2.)
        N.testing.assert_array_equal(sphere.in_bounds(self.points), [True, True, False])
    
    def test_cylinder(self):
        """Cylinder bounding volume"""
        cyl = BoundaryCylinder(diameter=3.)
        N.testing.assert_array_equal(cyl.in_bounds(self.points), [True, True, False])
    
    def test_plane(self):
        """Translated plane section of a volume"""
        plane = BoundaryPlane(rotation=rotx(-N.pi/6)[:3,:3], location=N.r_[0., 1., 0.])
        N.testing.assert_array_equal(plane.in_bounds(self.points), [False, True, True])

class TestSphereBoundingRect(unittest.TestCase):
    def setUp(self):
        # Create some surfaces to intersect with spheres.
        self.at_origin_xy = N.eye(4)
        self.at_origin_yz = generate_transform(N.r_[0, 1, 0], N.pi/2, \
            N.c_[[0,0,0]])

        self.at_origin_slant = generate_transform(N.r_[0, 1, 0], N.pi/4, \