Esempio n. 1
0
    def covers_tile(self, tile: Tile):
        d = self.radius
        c = self.rect.x + d, self.rect.y + d  # configuration of the middle of the circle
        # get vertices from rectangle
        v0, v1, v2, v3 = [tile.get_vertex(i) for i in range(4)]

        return distance(c, v0) < d and distance(c, v1) < d and distance(
            c, v2) < d and distance(c, v3) < d
Esempio n. 2
0
    def collides_rectangle(self, rect):
        d = self.radius
        c = self.rect.x + d, self.rect.y + d  # configuration of the middle of the circle
        # get vertices from rectangle
        v0, v1, v2, v3 = [rect.get_vertex(i) for i in range(4)]

        # check if c is in the rectangle
        if v0[0] < c[0] < v1[0] and v3[1] < c[1] < v0[1]:
            return True

        # check if the circle overlaps the rectangle
        if v0[0] < c[0] < v1[0] and (v3[1] - d < c[1] < v3[1] or
                                     v0[1] < c[1] < v0[1] + d):  # top / bottom
            return True
        if v3[1] < c[1] < v0[1] and (v0[0] - d < c[0] < v0[0] or
                                     v1[0] < c[0] < v1[0] + d):  # left / right
            return True

        # check distances to the corners
        if distance(c, v0) < d or distance(c, v1) < d or distance(
                c, v2) < d or distance(c, v3) < d:
            return True

        return False
Esempio n. 3
0

### check "interpolateFunction"
# TODO some documentation missing

### check "distance"
points = np.array([(1,1,1),(2,2,2),(3,3,3)])
find = [(0,0,0),(1,2,1),(1.1,2.1,2.1),(2,2,2),(10,10,10)]
dists = [(1.73205 ,3.46410 ,5.19615),
         (1.0     ,1.41421 ,3.0     ),
         (1.55885 ,0.91104 ,2.28692 ),
         (1.73205 ,0.0     ,1.73205 ),
         (15.58846,13.85641,12.12436)]

for i,f in enumerate(find):
  dist = mathUtils.distance(points,f)
  checkArray('distance %s' %str(f),dist,dists[i],1e-5)


### check "numpyNearestMatch"
findIn = np.array([(1,1,1),(2,2,2),(3,3,3)])
find =    [(0,0,0),(1,2,1),(1,2,2),(2,2,2),(10,10,10)]
idcs    = [   0   ,   0   ,   1   ,   1   ,    2     ]
correct = [(1,1,1),(1,1,1),(2,2,2),(2,2,2),( 3, 3, 3)]
for i,f in enumerate(find):
  idx,ary = mathUtils.numpyNearestMatch(findIn,f)
  checkAnswer('numpyNearersMatch %s' %str(f),idx,idcs[i],1e-5)
  checkArray('numpyNearersMatch %s' %str(f),ary,correct[i],1e-5)

### check float comparison
#moderate order of magnitude