Skip to content

Commit

Permalink
Fixes typo in integral
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiaMarcucci committed Oct 5, 2024
1 parent e2088d1 commit 768c351
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pybezier/bezier_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def derivative(self) -> Self:
return BezierCurve(points, self.initial_time, self.final_time)

def integral(self, initial_condition : np.ndarray | None = None) -> Self:
points = self.points * self.duration / self.degree
points = self.points * self.duration / (self.degree + 1)
points = np.vstack([np.zeros(self.dimension), points])
points = np.cumsum(points, axis=0)
if initial_condition is not None:
Expand Down
12 changes: 7 additions & 5 deletions tests/test_bezier_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ def test_integral(self):
initial_conditions = [None, np.ones(self.curve.dimension)]
for initial_condition in initial_conditions:
integral = self.curve.integral(initial_condition)
value = 0 if initial_condition is None else initial_condition
np.testing.assert_array_almost_equal(integral(self.initial_time), value)
time_step = 1e-6
value = integral(self.initial_time)
target_value = 0 if initial_condition is None else initial_condition
np.testing.assert_array_almost_equal(value, target_value)
time_step = 1e-3
for time in np.linspace(self.initial_time, self.final_time - time_step):
numerical_integral = integral(time) + time_step * self.curve(time)
np.testing.assert_array_almost_equal(integral(time + time_step), numerical_integral)
value = self.curve(time + time_step / 2)
target_value = (integral(time + time_step) - integral(time)) / time_step
np.testing.assert_array_almost_equal(value, target_value)

def test_domain_split(self):
split_time = (self.initial_time + self.final_time) / 2
Expand Down
12 changes: 7 additions & 5 deletions tests/test_composite_bezier_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ def test_integral(self):
initial_conditions = [None, np.ones(self.composite_curve.dimension)]
for initial_condition in initial_conditions:
integral = self.composite_curve.integral(initial_condition)
value = 0 if initial_condition is None else initial_condition
np.testing.assert_array_almost_equal(integral(self.initial_time), value)
time_step = 1e-6
value = integral(self.initial_time)
target_value = 0 if initial_condition is None else initial_condition
np.testing.assert_array_almost_equal(value, target_value)
time_step = 1e-3
for time in np.linspace(self.initial_time, self.final_time - time_step):
numerical_integral = integral(time) + time_step * self.composite_curve(time)
np.testing.assert_array_almost_equal(integral(time + time_step), numerical_integral)
value = self.composite_curve(time + time_step / 2)
target_value = (integral(time + time_step) - integral(time)) / time_step
np.testing.assert_array_almost_equal(value, target_value)

def test_knot_points(self):
for i, point in enumerate(self.composite_curve.knot_points()):
Expand Down

0 comments on commit 768c351

Please sign in to comment.