Skip to content

Commit

Permalink
Merge pull request #17 from dslosky-usgs/updates
Browse files Browse the repository at this point in the history
Fix intersection and add test for intersection
  • Loading branch information
dslosky-usgs authored Sep 10, 2018
2 parents 9bcf071 + 62f34d2 commit c26ae25
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.0a4',
version='0.0a5',

description='Potential impact calculation for well defined facilities due to an input earthquake hazard',
long_description=long_description,
Expand Down
4 changes: 2 additions & 2 deletions shakecastaebm/performance_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def get_intersection(seg1, seg2, x, y):
(dy2 * dx1 - dx2 * dy1))

if (s >= 0 and s <= 1 and t >= 0 and t <= 1):
x_val = abs(round(seg1[0][x] + t * dx1 * 1000) / 1000)
y_val = abs(round(seg1[0][y] + t * dy1 * 1000) / 1000)
x_val = abs(round((seg1[0][x] + t * dx1) * 1000) / 1000)
y_val = abs(round((seg1[0][y] + t * dy1) * 1000) / 1000)
return {x: x_val, y: y_val}
else:
return False
Expand Down
29 changes: 28 additions & 1 deletion shakecastaebm/tests/performance_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ def test_performancePoint(self):
self.assertTrue('acc' in pp.keys())
self.assertTrue('period' in pp.keys())

def test_intersection(self):
capacity = [
{'disp': 1, 'acc': .1},
{'disp': 2, 'acc': 1}
]
demand = [
{'disp': 1, 'acc': 1},
{'disp': 2, 'acc': .1}
]

pp = get_performance_point(capacity, demand)[0]

# slopes for the intersection with the demand
dem_slope1 = ((demand[0]['acc'] - pp['acc']) /
(demand[0]['disp'] - pp['disp']))
dem_slope2 = ((demand[1]['acc'] - pp['acc']) /
(demand[1]['disp'] - pp['disp']))

# slopes for intersection with capacity
cap_slope1 = ((capacity[0]['acc'] - pp['acc']) /
(capacity[0]['disp'] - pp['disp']))
cap_slope2 = ((capacity[1]['acc'] - pp['acc']) /
(capacity[1]['disp'] - pp['disp']))

self.assertAlmostEqual(dem_slope1, dem_slope2)
self.assertAlmostEqual(cap_slope1, cap_slope2)


if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit c26ae25

Please sign in to comment.