Example #1
0
 def test_project(self):
     box = BoundingBox()
     box.vertices = [vec3(2), vec3(-1)]
     normal = vec3(1)
     min_box, max_box = CollisionSystem.project(box, normal)
     self.assertEqual(-1, min_box)
     self.assertEqual(2, max_box)
Example #2
0
    def test_collides_example(self):
        vertices = [
            vec3(1.0, -1.0, -1.0), vec3(1.0, -1.0, 1.0),
            vec3(-1.0, -1.0, 1.0), vec3(-1.0, -1.0, -1.0),
            vec3(1.0, 1.0, -0.999999), vec3(0.999999, 1.0, 1.000001),
            vec3(-1.0, 1.0, 1.0), vec3(-1.0, 1.0, -1.0)
        ]
        normals = [
            vec3(1.0, -1.0, -2.0), vec3(2.0, -2.0, 1.0),
            vec3(-2.0, -1.0, 2.0), vec3(-1.0, -2.0, -1.0),
            vec3(2.0, 1.0, -1.0), vec3(1.0, 2.0, 2.0),
            vec3(-1.0, 1.0, 1.0), vec3(-2.0, 2.0, -2.0)
        ]
        box = BoundingBox()
        box.vertices = vertices
        box.normals = normals
        matrix = identity()
        translate(matrix, vec3(0, 0, 25))

        other = BoundingBox()
        other.vertices = vertices
        other.normals = normals
        other_matrix = identity()
        translate(other_matrix, vec3(5, 0, 25))

        collides = CollisionSystem.collides(box, matrix, other, other_matrix)
        self.assertFalse(collides)
Example #3
0
    def test_not_collides_simple_position(self):
        box = BoundingBox()
        box.vertices = self.vertices
        box.normals = self.normals

        other = BoundingBox()
        other.vertices = self.vertices
        other.normals = self.normals

        matrix = identity()
        translate(matrix, vec3(3))
        collides = CollisionSystem.collides(box, matrix, other, identity())
        self.assertFalse(collides)
Example #4
0
    def test_collides_simple(self):
        box = BoundingBox()
        box.vertices = self.vertices
        box.normals = self.normals

        other = BoundingBox()
        other.vertices = self.vertices
        other.normals = self.normals

        matrix = identity()
        collides = CollisionSystem.collides(box, matrix, other, matrix)

        self.assertTrue(collides)
Example #5
0
    def __init__(self, reader, ms_level):
        self.reader = reader
        self.cursor = reader.cursor
        self.ms_level = ms_level

        self.first_run_slice_bb = None
        self.curr_scan_slices = None

        self.r_header_by_id = self.get_run_slice_header_by_id()

        self.cursor.execute(RunSliceIterator.sql_query, (self.ms_level, ))

        self.first_run_slice_bb = BoundingBox._make(self.cursor.fetchone())
Example #6
0
    def _init_iter(self):
        if self.first_run_slice_bb is None:
            raise StopIteration
        self.curr_scan_slices = bb_to_scan_slices(
            bytes(self.first_run_slice_bb.data), self.first_run_slice_bb.run_slice_id, self.reader.struct_by_scan_id)

        while 1:
            row = self.cursor.fetchone()
            if row is None:
                self.first_run_slice_bb = None
                break
            bb = BoundingBox._make(row)
            if bb.run_slice_id == self.first_run_slice_bb.run_slice_id:
                self.curr_scan_slices += bb_to_scan_slices(
                    bytes(bb.data), bb.run_slice_id, self.reader.struct_by_scan_id)
            else:
                self.first_run_slice_bb = bb
                break
Example #7
0
    def test_collides_example2(self):
        box = BoundingBox()
        box.vertices = [vec3(1.0, -1.0, -1.0), vec3(1.0, -1.0, 1.0), vec3(-1.0, -1.0, 1.0), vec3(-1.0, -1.0, -1.0),
                        vec3(1.0, 1.0, -0.999999), vec3(0.999999, 1.0, 1.000001), vec3(-1.0, 1.0, 1.0),
                        vec3(-1.0, 1.0, -1.0)]
        box.normals = [vec3(1.0, -1.0, -2.0), vec3(2.0, -2.0, 1.0), vec3(-2.0, -1.0, 2.0), vec3(-1.0, -2.0, -1.0),
                       vec3(2.0, 1.0, -1.0), vec3(1.0, 2.0, 2.0), vec3(-1.0, 1.0, 1.0), vec3(-2.0, 2.0, -2.0)]
        box_model_matrix = mat4()
        box_model_matrix.numbers = [[1.0, 0.0, 0.0, 2.500000000000009], [0.0, 1.0, 0.0, 0.0],
                                    [0.0, 0.0, 1.0, 1.5308084989341933e-16],
                                    [0.0, 0.0, 0.0, 1.0]]

        other = BoundingBox()
        other.vertices = [
            vec3(1.0, -1.0, -1.0), vec3(1.0, -1.0, 1.0), vec3(-1.0, -1.0, 1.0), vec3(-1.0, -1.0, -1.0),
            vec3(1.0, 1.0, -0.999999), vec3(0.999999, 1.0, 1.000001), vec3(-1.0, 1.0, 1.0), vec3(-1.0, 1.0, -1.0)]
        other.normals = [vec3(1.0, -1.0, -2.0), vec3(2.0, -2.0, 1.0), vec3(-2.0, -1.0, 2.0), vec3(-1.0, -2.0, -1.0),
                         vec3(2.0, 1.0, -1.0), vec3(1.0, 2.0, 2.0), vec3(-1.0, 1.0, 1.0), vec3(-2.0, 2.0, -2.0)]
        other_model_matrix = mat4()
        other_model_matrix.numbers = [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0],
                                      [0.0, 0.0, 0.0, 1.0]]

        collides = CollisionSystem.collides(box, box_model_matrix, other, other_model_matrix)
        self.assertFalse(collides)
Example #8
0
from matplotlib import pyplot as plt
import numpy
from model import GridCell, BoundingBox, hexagonal_earth_grid

GridCell.grid = hexagonal_earth_grid(BoundingBox(s=-1, n=1, w=-1, e=1),
                                     450000000)
c = GridCell.random_cell()