diff options
Diffstat (limited to 'szilagyi/nomogram.py')
-rw-r--r-- | szilagyi/nomogram.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/szilagyi/nomogram.py b/szilagyi/nomogram.py index 55276ae..8c567d7 100644 --- a/szilagyi/nomogram.py +++ b/szilagyi/nomogram.py @@ -6,7 +6,7 @@ from . import _dataset def look_downwards(data, x, start): for i in range(start, 0, -1): - if data[i - 1][0] < x: + if data[i - 1].x < x: break else: raise IndexError @@ -15,7 +15,7 @@ def look_downwards(data, x, start): def look_upwards(data, x, start): for i in range(start, len(data)): - if data[i + 1][0] > x: + if data[i + 1].x > x: break else: raise IndexError @@ -23,10 +23,10 @@ def look_upwards(data, x, start): def find_segment(data, x): - width = data[-1][0] - data[0][0] - relative = x - data[0][0] + width = data[-1].x - data[0].x + relative = x - data[0].x candidate = math.floor(relative / width * len(data)) - look = look_downwards if data[candidate][0] > x else look_upwards # May raise IndexError + look = look_downwards if data[candidate].x > x else look_upwards # May raise IndexError candidate = look(data, x, candidate) return candidate, candidate + 1 @@ -35,20 +35,20 @@ def find_boundary_curves(swis, x, y): segments = deque() for index, data in swis: i, j = find_segment(data, x) - if data[i][1] > y and data[j][1] > y: + if data[i].y > y and data[j].y > y: segments.append((index, data, i, j)) break - if data[i][1] < y and data[j][1] < y: + if data[i].y < y and data[j].y < y: if segments: segments.popleft() segments.append((index, data, i, j)) if len(segments) == 3: middle = segments[1][1] - run = middle[j][0] - middle[i][0] + run = middle[j].x - middle[i].x if run == 0: raise RuntimeError # tidy up dataset - slope = (middle[j][1] - middle[i][1]) / run - intercept = middle[j][1] - slope * middle[j][0] + slope = (middle[j].y - middle[i].y) / run + intercept = middle[j].y - slope * middle[j].x value = slope * x + intercept if value == y: raise RuntimeError # Exactly on point; SWI == index |