2010-04-29 22:29:35 -07:00
|
|
|
from baker import get_phis, get_phis_3D
|
|
|
|
from baker.tools import smblog
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
TOL = 1e-8
|
2010-03-20 16:10:02 -07:00
|
|
|
|
|
|
|
def contains(X, R):
|
2010-03-20 19:09:46 -07:00
|
|
|
"""
|
|
|
|
tests if X (point) is in R (a simplex,
|
|
|
|
represented by a list of n-degree coordinates)
|
2010-04-29 22:29:35 -07:00
|
|
|
|
|
|
|
it now correctly checks for 2/3-D points
|
2010-03-20 19:09:46 -07:00
|
|
|
"""
|
2010-04-29 22:29:35 -07:00
|
|
|
if len(X) == 2:
|
|
|
|
phis = get_phis(X, R)
|
|
|
|
elif len(X) == 3:
|
|
|
|
phis = get_phis_3D(X, R)
|
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
r = True
|
|
|
|
if [i for i in phis if i < 0.0 - TOL]:
|
|
|
|
r = False
|
|
|
|
return r
|
2010-03-20 16:10:02 -07:00
|
|
|
|
|
|
|
|
2010-03-18 22:32:24 -07:00
|
|
|
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)
|
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
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])
|
2010-03-18 22:32:24 -07:00
|
|
|
|
|
|
|
def __str__(self):
|
2010-10-22 15:10:58 -07:00
|
|
|
neighbors = [str(i.name) for i in self.neighbors]
|
|
|
|
return '<face %s: verts: %s neighbors: [%s]>' %\
|
2010-03-18 22:32:24 -07:00
|
|
|
(
|
|
|
|
self.name,
|
|
|
|
self.verts,
|
|
|
|
", ".join(neighbors)
|
|
|
|
)
|
2010-10-22 15:10:58 -07:00
|
|
|
|
|
|
|
__repr__ = __str__
|