-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathcommon.py
More file actions
30 lines (24 loc) · 798 Bytes
/
common.py
File metadata and controls
30 lines (24 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Contains utilities common to all meshing methods"""
import settings
class Edge:
def __init__(self, v1, v2):
self.v1 = v1
self.v2 = v2
def swap(self, swap=True):
if swap:
return Edge(self.v2, self.v1)
else:
return Edge(self.v1, self.v2)
def adapt(v0, v1):
"""v0 and v1 are numbers of opposite sign. This returns how far you need to interpolate from v0 to v1 to get to 0."""
assert (v1 > 0) != (v0 > 0), "v0 and v1 do not have opposite sign"
if settings.ADAPTIVE:
return (0 - v0) / (v1 - v0) * settings.CELL_SIZE
else:
return 0.5 * settings.CELL_SIZE
def frange(start, stop, step=1):
"""Like range, but works for floats"""
v = start
while v < stop:
yield v
v += step