Skip to content

Commit c26ae25

Browse files
author
dslosky-usgs
authored
Merge pull request #17 from dslosky-usgs/updates
Fix intersection and add test for intersection
2 parents 9bcf071 + 62f34d2 commit c26ae25

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# Versions should comply with PEP440. For a discussion on single-sourcing
3030
# the version across setup.py and the project code, see
3131
# https://packaging.python.org/en/latest/single_source_version.html
32-
version='0.0a4',
32+
version='0.0a5',
3333

3434
description='Potential impact calculation for well defined facilities due to an input earthquake hazard',
3535
long_description=long_description,

shakecastaebm/performance_point.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def get_intersection(seg1, seg2, x, y):
5454
(dy2 * dx1 - dx2 * dy1))
5555

5656
if (s >= 0 and s <= 1 and t >= 0 and t <= 1):
57-
x_val = abs(round(seg1[0][x] + t * dx1 * 1000) / 1000)
58-
y_val = abs(round(seg1[0][y] + t * dy1 * 1000) / 1000)
57+
x_val = abs(round((seg1[0][x] + t * dx1) * 1000) / 1000)
58+
y_val = abs(round((seg1[0][y] + t * dy1) * 1000) / 1000)
5959
return {x: x_val, y: y_val}
6060
else:
6161
return False

shakecastaebm/tests/performance_point.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,33 @@ def test_performancePoint(self):
2121
self.assertTrue('acc' in pp.keys())
2222
self.assertTrue('period' in pp.keys())
2323

24+
def test_intersection(self):
25+
capacity = [
26+
{'disp': 1, 'acc': .1},
27+
{'disp': 2, 'acc': 1}
28+
]
29+
demand = [
30+
{'disp': 1, 'acc': 1},
31+
{'disp': 2, 'acc': .1}
32+
]
33+
34+
pp = get_performance_point(capacity, demand)[0]
35+
36+
# slopes for the intersection with the demand
37+
dem_slope1 = ((demand[0]['acc'] - pp['acc']) /
38+
(demand[0]['disp'] - pp['disp']))
39+
dem_slope2 = ((demand[1]['acc'] - pp['acc']) /
40+
(demand[1]['disp'] - pp['disp']))
41+
42+
# slopes for intersection with capacity
43+
cap_slope1 = ((capacity[0]['acc'] - pp['acc']) /
44+
(capacity[0]['disp'] - pp['disp']))
45+
cap_slope2 = ((capacity[1]['acc'] - pp['acc']) /
46+
(capacity[1]['disp'] - pp['disp']))
47+
48+
self.assertAlmostEqual(dem_slope1, dem_slope2)
49+
self.assertAlmostEqual(cap_slope1, cap_slope2)
50+
2451

2552
if __name__ == '__main__':
26-
unittest.main()
53+
unittest.main()

0 commit comments

Comments
 (0)