refactor get_altitudes()

This commit is contained in:
Laura Klünder 2017-11-18 13:53:40 +01:00
parent 9b66a2b4e5
commit 7575605aae

View file

@ -149,17 +149,8 @@ class AltitudeArea(LevelGeometryMixin, models.Model):
if self.altitude2 is None:
return np.full((points.shape[0], ), fill_value=float(self.altitude))
a_to_p = points - np.array(self.point1)
a_to_b = np.array(self.point2) - np.array(self.point1)
atb2 = (a_to_b**2).sum()
atp_dot_atb = a_to_p[:, 0] * a_to_b[0] + a_to_p[:, 1] * a_to_b[1]
distances = atp_dot_atb / atb2
distances = distances.clip(0, 1)
slope = np.array(self.point2) - np.array(self.point1)
distances = np.sum(((points - np.array(self.point1)) * slope), axis=1) / (slope ** 2).sum().clip(0, 1)
return self.altitude + distances*(self.altitude2-self.altitude)
@classmethod