Skip to content

Commit 897b6d4

Browse files
code-monetWhiteMagic
authored andcommitted
When enforcing symmetry, add a point at the origin if currently it's an even number of points
1 parent 19b03d3 commit 897b6d4

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

gremlin/spline.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ def _enforce_symmetry(self) -> None:
177177
p2.x = -p1.x
178178
p2.y = -p1.y
179179

180-
if count % 2 != 0:
180+
if count % 2: # Odd number of points.
181181
self.points[int(count / 2)] = Point2D(0.0, 0.0)
182+
else:
183+
self.points.insert(int(count / 2), Point2D(0.0, 0.0))
182184

183185
def _default_points(self) -> CoordinateList:
184186
return [(-1.0, -1.0), (1.0, 1.0)]
@@ -254,8 +256,11 @@ def _enforce_symmetry(self) -> None:
254256
p2.x = -p1.x
255257
p2.y = -p1.y
256258

257-
if count % 2 != 0:
259+
if count % 2: # Odd number of points.
258260
self.points[int(count / 2)] = Point2D(0.0, 0.0)
261+
else:
262+
self.points.insert(int(count / 2), Point2D(0.0, 0.0))
263+
self.z.insert(int(count / 2), 0.0)
259264

260265
def fit(self) -> None:
261266
"""Computes the second derivatives for the control points."""
@@ -408,8 +413,15 @@ def _enforce_symmetry(self) -> None:
408413
if cp1.handle_right is not None:
409414
cp2.handle_left = cp2.center - (cp1.handle_right - cp1.center)
410415

411-
if count % 2 != 0:
416+
if count % 2: # Odd number of points.
412417
self._control_points[int(count / 2)].center = Point2D(0.0, 0.0)
418+
else:
419+
self._control_points.insert(
420+
int(count / 2),
421+
CubicBezierSpline.ControlPoint(
422+
Point2D(0, 0), Point2D(-0.05, 0), Point2D(+0.05, 0)
423+
),
424+
)
413425

414426
def _default_points(self) -> CoordinateList:
415427
return [(-1.0, -1.0), (-0.95, -0.95), (0.95, 0.95), (1.0, 1.0)]

test/integration/action_plugins/test_response_curve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ def test_cubic_spline_asymmetric(
374374
(1, 1.0),
375375
(0.75, 0.58125),
376376
(0.5, 0.2),
377-
(0.25, 0.1048),
377+
(0.25, 0.1),
378378
(0, 0.0),
379-
(-0.25, -0.1048),
379+
(-0.25, -0.1),
380380
(-0.5, -0.2),
381381
(-0.75, -0.58125),
382382
(-1, -1.0),

0 commit comments

Comments
 (0)