56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
from baker import get_phis
|
|
|
|
TOL = 1e-8
|
|
|
|
def contains(X, R):
|
|
"""
|
|
tests if X (point) is in R (a simplex,
|
|
represented by a list of n-degree coordinates)
|
|
"""
|
|
phis = get_phis(X, R)
|
|
r = True
|
|
if [i for i in phis if i < 0.0 - TOL]:
|
|
r = False
|
|
return r
|
|
|
|
|
|
class face(object):
|
|
def __init__(self, name):
|
|
self.name = name
|
|
self.verts = []
|
|
self.neighbors = []
|
|
|
|
def add_vert(self, v):
|
|
"""
|
|
v should be an index into grid.points
|
|
"""
|
|
self.verts.append(v)
|
|
|
|
def add_neighbor(self, n):
|
|
"""
|
|
reference to another face object
|
|
"""
|
|
self.neighbors.append(n)
|
|
|
|
def contains(self, X, G):
|
|
"""
|
|
X = point of interest
|
|
G = corrensponding grid object (G.points)
|
|
because of the way i'm storing things,
|
|
a face simply stores indicies, and so one
|
|
must pass in a reference to the grid object
|
|
containing real points.
|
|
|
|
this simply calls grid.simplex.contains
|
|
"""
|
|
return contains(X, [G.points[i] for i in self.verts])
|
|
|
|
def __str__(self):
|
|
neighbors = [i.name for i in self.neighbors]
|
|
return '%s: verts: %s neighbors: [%s]' %\
|
|
(
|
|
self.name,
|
|
self.verts,
|
|
", ".join(neighbors)
|
|
)
|