Skip to content

Commit af0f34e

Browse files
authored
Merge pull request #68 from mfisher87/more-formatting-rules
Fix main branch actions failures, other pre-commit tweaks
2 parents 6b35100 + ea93bc2 commit af0f34e

8 files changed

+87
-88
lines changed

.git-blame-ignore-revs

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Applied `ruff` and `black` (gh-64)
22
1fec42d0baf90e00d510efd76cb6006fa0c70dc4
3+
4+
# Applied `pre-commit` `end-of-file-fixer`
5+
e9104b3616899f54257bb38959d6e1c0acc70f6a

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,3 @@ coverage.xml
5454

5555
# Sphinx documentation
5656
docs/_build/
57-

.pre-commit-config.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ repos:
44
hooks:
55
- id: "check-added-large-files"
66
- id: "check-vcs-permalinks"
7-
- id: "no-commit-to-branch"
8-
# TODO: Apply this fixer and add an entry to .git-blame-ignore-revs
9-
# - id: "end-of-file-fixer"
7+
- id: "end-of-file-fixer"
108

119
- repo: "https://github.com/charliermarsh/ruff-pre-commit"
1210
rev: "v0.0.269"

viscm/bezierbuilder.py viscm/bezierbuilder/__init__.py

+27-81
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,36 @@
1-
# BézierBuilder
2-
#
3-
# Copyright (c) 2013, Juan Luis Cano Rodríguez <juanlu001@gmail.com>
4-
# All rights reserved.
5-
#
6-
# Redistribution and use in source and binary forms, with or without modification,
7-
# are permitted provided that the following conditions are met:
8-
#
9-
# * Redistributions of source code must retain the above copyright notice,
10-
# this list of conditions and the following disclaimer.
11-
# * Redistributions in binary form must reproduce the above copyright notice,
12-
# this list of conditions and the following disclaimer in the documentation
13-
# and/or other materials provided with the distribution.
14-
#
15-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16-
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17-
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18-
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
19-
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20-
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21-
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22-
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23-
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24-
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25-
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26-
271
"""BézierBuilder, an interactive Bézier curve explorer.
282
29-
Just run it with
30-
31-
$ python bezier_builder.py
32-
3+
Copyright (c) 2013, Juan Luis Cano Rodríguez <juanlu001@gmail.com>
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification,
7+
are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
19+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3326
"""
3427

35-
from math import factorial
36-
3728
import numpy as np
3829
from matplotlib.backends.qt_compat import QtCore
3930
from matplotlib.lines import Line2D
4031

41-
from .minimvc import Trigger
32+
from viscm.bezierbuilder.curve import curve_method
33+
from viscm.minimvc import Trigger
4234

4335

4436
class ControlPointModel:
@@ -193,7 +185,7 @@ def compute_arc_length(xp, yp, method, t=None, grid=256):
193185

194186
class SingleBezierCurveModel:
195187
def __init__(self, control_point_model, method="CatmulClark"):
196-
self.method = eval(method)
188+
self.method = curve_method[method]
197189
self.control_point_model = control_point_model
198190
x, y = self.get_bezier_points()
199191
self.bezier_curve = Line2D(x, y)
@@ -215,7 +207,7 @@ def _refresh(self):
215207

216208
class TwoBezierCurveModel:
217209
def __init__(self, control_point_model, method="CatmulClark"):
218-
self.method = eval(method)
210+
self.method = curve_method[method]
219211
self.control_point_model = control_point_model
220212
x, y = self.get_bezier_points()
221213
self.bezier_curve = Line2D(x, y)
@@ -286,49 +278,3 @@ def _refresh(self):
286278
x, y = self.bezier_curve_model.get_bezier_points()
287279
self.bezier_curve.set_data(x, y)
288280
self.canvas.draw()
289-
290-
291-
# We used to use scipy.special.binom here,
292-
# but reimplementing it ourself lets us avoid pulling in a dependency
293-
# scipy just for that one function.
294-
def binom(n, k):
295-
return factorial(n) * 1.0 / (factorial(k) * factorial(n - k))
296-
297-
298-
def Bernstein(n, k):
299-
"""Bernstein polynomial."""
300-
coeff = binom(n, k)
301-
302-
def _bpoly(x):
303-
return coeff * x**k * (1 - x) ** (n - k)
304-
305-
return _bpoly
306-
307-
308-
def Bezier(points, at):
309-
"""Build Bézier curve from points.
310-
Deprecated. CatmulClark builds nicer splines
311-
"""
312-
at = np.asarray(at)
313-
at_flat = at.ravel()
314-
N = len(points)
315-
curve = np.zeros((at_flat.shape[0], 2))
316-
for ii in range(N):
317-
curve += np.outer(Bernstein(N - 1, ii)(at_flat), points[ii])
318-
return curve.reshape((*at.shape, 2))
319-
320-
321-
def CatmulClark(points, at):
322-
points = np.asarray(points)
323-
324-
while len(points) < len(at):
325-
new_p = np.zeros((2 * len(points), 2))
326-
new_p[0] = points[0]
327-
new_p[-1] = points[-1]
328-
new_p[1:-2:2] = 3 / 4.0 * points[:-1] + 1 / 4.0 * points[1:]
329-
new_p[2:-1:2] = 1 / 4.0 * points[:-1] + 3 / 4.0 * points[1:]
330-
points = new_p
331-
xp, yp = zip(*points)
332-
xp = np.interp(at, np.linspace(0, 1, len(xp)), xp)
333-
yp = np.interp(at, np.linspace(0, 1, len(yp)), yp)
334-
return np.asarray(list(zip(xp, yp)))

viscm/bezierbuilder/curve.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import warnings
2+
3+
import numpy as np
4+
from scipy.special import binom
5+
6+
7+
def Bernstein(n, k):
8+
"""Bernstein polynomial."""
9+
coeff = binom(n, k)
10+
11+
def _bpoly(x):
12+
return coeff * x**k * (1 - x) ** (n - k)
13+
14+
return _bpoly
15+
16+
17+
def Bezier(points, at):
18+
"""Build Bézier curve from points."""
19+
warnings.warn(
20+
message="Deprecated. CatmulClark builds nicer splines.",
21+
category=FutureWarning,
22+
stacklevel=1,
23+
)
24+
25+
at = np.asarray(at)
26+
at_flat = at.ravel()
27+
N = len(points)
28+
curve = np.zeros((at_flat.shape[0], 2))
29+
for ii in range(N):
30+
curve += np.outer(Bernstein(N - 1, ii)(at_flat), points[ii])
31+
return curve.reshape((*at.shape, 2))
32+
33+
34+
def CatmulClark(points, at):
35+
points = np.asarray(points)
36+
37+
while len(points) < len(at):
38+
new_p = np.zeros((2 * len(points), 2))
39+
new_p[0] = points[0]
40+
new_p[-1] = points[-1]
41+
new_p[1:-2:2] = 3 / 4.0 * points[:-1] + 1 / 4.0 * points[1:]
42+
new_p[2:-1:2] = 1 / 4.0 * points[:-1] + 3 / 4.0 * points[1:]
43+
points = new_p
44+
xp, yp = zip(*points)
45+
xp = np.interp(at, np.linspace(0, 1, len(xp)), xp)
46+
yp = np.interp(at, np.linspace(0, 1, len(yp)), yp)
47+
return np.asarray(list(zip(xp, yp)))
48+
49+
50+
curve_method = {
51+
"Bezier": Bezier,
52+
"CatmulClark": CatmulClark,
53+
}

viscm/examples/sample_diverging.jscm

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
"domain": "continuous",
3838
"content-type": "application/vnd.matplotlib.colormap-v1+json",
3939
"license": "http://creativecommons.org/publicdomain/zero/1.0/"
40-
}
40+
}

viscm/examples/sample_diverging_continuous.jscm

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"colorspace": "sRGB",
3535
"name": "sample_diverging_continuous",
3636
"domain": "continuous"
37-
}
37+
}

viscm/examples/sample_linear.jscm

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
"cmtype": "linear"
3636
}
3737
}
38-
}
38+
}

0 commit comments

Comments
 (0)