Skip to content

Commit

Permalink
Set line-length to 88
Browse files Browse the repository at this point in the history
  • Loading branch information
janbridley committed May 28, 2024
1 parent 162a8fd commit 4e419c1
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 217 deletions.
4 changes: 1 addition & 3 deletions doc/gallery/cuboid.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,5 @@
PIL.Image.fromarray(out[:], mode="RGBA").save("cuboid.png")

if len(sys.argv) > 1 and sys.argv[1] == "hires":
out = fresnel.pathtrace(
scene, samples=256, light_samples=16, w=1380, h=1380
)
out = fresnel.pathtrace(scene, samples=256, light_samples=16, w=1380, h=1380)
PIL.Image.fromarray(out[:], mode="RGBA").save("cuboid-hires.png")
12 changes: 3 additions & 9 deletions doc/gallery/gumballs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
"#ecb642",
"#8a9441",
]
cmap = LinearSegmentedColormap.from_list(
name="gumball", colors=colors, N=len(colors)
)
cmap = LinearSegmentedColormap.from_list(name="gumball", colors=colors, N=len(colors))

rng = np.random.default_rng(123)

Expand Down Expand Up @@ -63,9 +61,7 @@
scene.camera.focus_on = (0, 0, 5.6)
scene.lights = fresnel.light.lightbox()
scene.lights.append(
fresnel.light.Light(
direction=(0.3, -0.3, 1), color=(0.5, 0.5, 0.5), theta=np.pi
)
fresnel.light.Light(direction=(0.3, -0.3, 1), color=(0.5, 0.5, 0.5), theta=np.pi)
)

if "CI" in os.environ:
Expand All @@ -78,7 +74,5 @@
PIL.Image.fromarray(out[:], mode="RGBA").save("gumballs.png")

if len(sys.argv) > 1 and sys.argv[1] == "hires":
out = fresnel.pathtrace(
scene, w=1500, h=1500, samples=256, light_samples=64
)
out = fresnel.pathtrace(scene, w=1500, h=1500, samples=256, light_samples=64)
PIL.Image.fromarray(out[:], mode="RGBA").save("gumballs-hires.png")
4 changes: 1 addition & 3 deletions doc/gallery/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,5 @@
PIL.Image.fromarray(out[:], mode="RGBA").save("sphere.png")

if len(sys.argv) > 1 and sys.argv[1] == "hires":
out = fresnel.pathtrace(
scene, samples=256, light_samples=16, w=1380, h=1380
)
out = fresnel.pathtrace(scene, samples=256, light_samples=16, w=1380, h=1380)
PIL.Image.fromarray(out[:], mode="RGBA").save("sphere-hires.png")
3 changes: 1 addition & 2 deletions fresnel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def __init__(self, mode="auto", n=None):
selected_mode = "cpu"
if not _common.cpu_built():
raise RuntimeError(
"No GPUs available AND CPU "
"implementation is not compiled"
"No GPUs available AND CPU " "implementation is not compiled"
)

if mode == "gpu":
Expand Down
28 changes: 7 additions & 21 deletions fresnel/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,8 @@ def get_extents(self):
r = r.reshape(len(r), 1)
res = numpy.array(
[
numpy.min(
[numpy.min(A - r, axis=0), numpy.min(B - r, axis=0)], axis=0
),
numpy.max(
[numpy.max(A + r, axis=0), numpy.max(B + r, axis=0)], axis=0
),
numpy.min([numpy.min(A - r, axis=0), numpy.min(B - r, axis=0)], axis=0),
numpy.max([numpy.max(A + r, axis=0), numpy.max(B + r, axis=0)], axis=0),
]
)
return res
Expand Down Expand Up @@ -249,9 +245,7 @@ class Box(Cylinder):
"""

def __init__(self, scene, box, box_radius=0.5, box_color=[0, 0, 0]):
super().__init__(
scene=scene, N=12, material=material.Material(solid=1.0)
)
super().__init__(scene=scene, N=12, material=material.Material(solid=1.0))
self._box = self._from_box(box)
self.points[:] = self._generate_points(self._box)

Expand Down Expand Up @@ -316,9 +310,7 @@ def _generate_points(self, box):
yz = box[5]

# Follow hoomd convention
box_matrix = numpy.array(
[[Lx, xy * Ly, xz * Lz], [0, Ly, yz * Lz], [0, 0, Lz]]
)
box_matrix = numpy.array([[Lx, xy * Ly, xz * Lz], [0, Ly, yz * Lz], [0, 0, Lz]])
a_1, a_2, a_3 = box_matrix.T
# F--------------H
# /| /|
Expand Down Expand Up @@ -503,9 +495,7 @@ def get_extents(self):
"""
pos = self.position[:]
r = self._geometry.getRadius()
res2d = numpy.array(
[numpy.min(pos - r, axis=0), numpy.max(pos + r, axis=0)]
)
res2d = numpy.array([numpy.min(pos - r, axis=0), numpy.max(pos + r, axis=0)])
res = numpy.array(
[
[res2d[0][0], res2d[0][1], -1e-5],
Expand Down Expand Up @@ -606,9 +596,7 @@ def get_extents(self):
pos = self.position[:]
r = self.radius[:]
r = r.reshape(len(r), 1)
res = numpy.array(
[numpy.min(pos - r, axis=0), numpy.max(pos + r, axis=0)]
)
res = numpy.array([numpy.min(pos - r, axis=0), numpy.max(pos + r, axis=0)])
return res

@property
Expand Down Expand Up @@ -867,9 +855,7 @@ def get_extents(self):
"""
pos = self.position[:]
r = self._radius
res = numpy.array(
[numpy.min(pos - r, axis=0), numpy.max(pos + r, axis=0)]
)
res = numpy.array([numpy.min(pos - r, axis=0), numpy.max(pos + r, axis=0)])
return res

@property
Expand Down
14 changes: 6 additions & 8 deletions fresnel/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Interactive Qt widgets."""

import sys

import numpy

# workaround bug in ipython that prevents pyside2 importing
Expand All @@ -16,13 +17,12 @@
except: # noqa: E722
pass

from PySide2 import QtGui
from PySide2 import QtCore
from PySide2 import QtWidgets
import rowan
import copy

from fresnel import tracer, camera
import rowan
from PySide2 import QtCore, QtGui, QtWidgets

from fresnel import camera, tracer

# initialize QApplication
# but not in sphinx
Expand Down Expand Up @@ -288,9 +288,7 @@ def paintEvent(self, event): # noqa: N802 - allow Qt style naming
)
qp = QtGui.QPainter(self)
target = QtCore.QRectF(0, 0, self.width(), self.height())
source = QtCore.QRectF(
0.0, 0.0, image_array.shape[1], image_array.shape[0]
)
source = QtCore.QRectF(0.0, 0.0, image_array.shape[1], image_array.shape[0])

qp.drawImage(target, img, source)
qp.end()
Expand Down
12 changes: 3 additions & 9 deletions fresnel/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,8 @@ def cloudy():
list[Light]: The lights.
"""
res = []
res.append(
Light(direction=(0, 1, 0), color=(0.9, 0.9, 0.9), theta=math.pi / 2)
)
res.append(
Light(direction=(0, -1, 0), color=(0.1, 0.1, 0.1), theta=math.pi / 2)
)
res.append(Light(direction=(0, 1, 0), color=(0.9, 0.9, 0.9), theta=math.pi / 2))
res.append(Light(direction=(0, -1, 0), color=(0.1, 0.1, 0.1), theta=math.pi / 2))
return res


Expand All @@ -294,7 +290,5 @@ def ring():
list[Light]: The lights.
"""
res = []
res.append(
Light(direction=(0, 0, 1), color=(0.9, 0.9, 0.9), theta=math.pi / 4)
)
res.append(Light(direction=(0, 0, 1), color=(0.9, 0.9, 0.9), theta=math.pi / 4))
return res
8 changes: 2 additions & 6 deletions fresnel/test/test_camera_perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def scene(device):
for j in range(-8, 8):
position.append([i, 0, j])

mat = fresnel.material.Material(
color=fresnel.color.linear([0.42, 0.267, 0.9])
)
mat = fresnel.material.Material(color=fresnel.color.linear([0.42, 0.267, 0.9]))
fresnel.geometry.Sphere(
scene,
position=position,
Expand Down Expand Up @@ -80,9 +78,7 @@ def test_perspective_attributes():
numpy.testing.assert_allclose(cam.focus_on, [0, 0, 5])
numpy.testing.assert_allclose(cam.focus_distance, 15)

numpy.testing.assert_allclose(
cam.vertical_field_of_view, 0.19933730498232408
)
numpy.testing.assert_allclose(cam.vertical_field_of_view, 0.19933730498232408)
cam.vertical_field_of_view = 0.4
numpy.testing.assert_allclose(cam.focal_length, 0.6166443824768066)

Expand Down
4 changes: 1 addition & 3 deletions fresnel/test/test_geometry_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ def test_box_update(scene_box_, generate=False):

if generate:
PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
open(
f"output/test_geometry_box.test_render{box_index}.png", "wb"
),
open(f"output/test_geometry_box.test_render{box_index}.png", "wb"),
"png",
)
else:
Expand Down
36 changes: 9 additions & 27 deletions fresnel/test/test_geometry_convex_polyhedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def scene_eight_polyhedra(device):
"radius": math.sqrt(3),
"face_color": fresnel.color.linear(colors),
}
geometry = fresnel.geometry.ConvexPolyhedron(
scene, poly_info, position=position
)
geometry = fresnel.geometry.ConvexPolyhedron(scene, poly_info, position=position)

geometry.material = fresnel.material.Material(
color=fresnel.color.linear([1.0, 0, 0]),
Expand All @@ -84,23 +82,17 @@ def scene_eight_polyhedra_(device_):

def test_render(scene_eight_polyhedra_, generate=False):
"""Test that convex polyhedra render properly."""
buf_proxy = fresnel.preview(
scene_eight_polyhedra_, w=150, h=100, anti_alias=False
)
buf_proxy = fresnel.preview(scene_eight_polyhedra_, w=150, h=100, anti_alias=False)

if generate:
PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
open(
"output/test_geometry_convex_polyhedron.test_render.png", "wb"
),
open("output/test_geometry_convex_polyhedron.test_render.png", "wb"),
"png",
)
else:
conftest.assert_image_approx_equal(
buf_proxy[:],
dir_path
/ "reference"
/ "test_geometry_convex_polyhedron.test_render.png",
dir_path / "reference" / "test_geometry_convex_polyhedron.test_render.png",
)


Expand All @@ -109,39 +101,29 @@ def test_outline(scene_eight_polyhedra_, generate=False):
geometry = scene_eight_polyhedra_.geometry[0]
geometry.outline_width = 0.1

buf_proxy = fresnel.preview(
scene_eight_polyhedra_, w=150, h=100, anti_alias=False
)
buf_proxy = fresnel.preview(scene_eight_polyhedra_, w=150, h=100, anti_alias=False)

if generate:
PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
open(
"output/test_geometry_convex_polyhedron.test_outline.png", "wb"
),
open("output/test_geometry_convex_polyhedron.test_outline.png", "wb"),
"png",
)
else:
conftest.assert_image_approx_equal(
buf_proxy[:],
dir_path
/ "reference"
/ "test_geometry_convex_polyhedron.test_outline.png",
dir_path / "reference" / "test_geometry_convex_polyhedron.test_outline.png",
)


def test_face_color(scene_eight_polyhedra_, generate=False):
"""Test that faces can be colored individually."""
buf_proxy = fresnel.preview(
scene_eight_polyhedra_, w=150, h=100, anti_alias=False
)
buf_proxy = fresnel.preview(scene_eight_polyhedra_, w=150, h=100, anti_alias=False)

geometry = scene_eight_polyhedra_.geometry[0]
geometry.color_by_face = 1.0
geometry.material.primitive_color_mix = 1.0

buf_proxy = fresnel.preview(
scene_eight_polyhedra_, w=150, h=100, anti_alias=False
)
buf_proxy = fresnel.preview(scene_eight_polyhedra_, w=150, h=100, anti_alias=False)

if generate:
PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
Expand Down
20 changes: 5 additions & 15 deletions fresnel/test/test_geometry_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def scene_four_cylinders_(device_):

def test_render(scene_four_cylinders_, generate=False):
"""Test that Cylinder renders properly."""
buf_proxy = fresnel.preview(
scene_four_cylinders_, w=150, h=100, anti_alias=False
)
buf_proxy = fresnel.preview(scene_four_cylinders_, w=150, h=100, anti_alias=False)

if generate:
PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
Expand All @@ -74,9 +72,7 @@ def test_radius(scene_four_cylinders_, generate=False):
geometry.radius[:] = r
numpy.testing.assert_array_equal(r, geometry.radius[:])

buf_proxy = fresnel.preview(
scene_four_cylinders_, w=150, h=100, anti_alias=False
)
buf_proxy = fresnel.preview(scene_four_cylinders_, w=150, h=100, anti_alias=False)

if generate:
PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
Expand Down Expand Up @@ -105,9 +101,7 @@ def test_points(scene_four_cylinders_, generate=False):
geometry.points[:] = p
numpy.testing.assert_array_equal(p, geometry.points[:])

buf_proxy = fresnel.preview(
scene_four_cylinders_, w=150, h=100, anti_alias=False
)
buf_proxy = fresnel.preview(scene_four_cylinders_, w=150, h=100, anti_alias=False)

if generate:
PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
Expand Down Expand Up @@ -137,9 +131,7 @@ def test_color(scene_four_cylinders_, generate=False):
geometry.color[:] = c
numpy.testing.assert_array_equal(c, geometry.color[:])

buf_proxy = fresnel.preview(
scene_four_cylinders_, w=150, h=100, anti_alias=False
)
buf_proxy = fresnel.preview(scene_four_cylinders_, w=150, h=100, anti_alias=False)

if generate:
PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
Expand All @@ -157,9 +149,7 @@ def test_outline(scene_four_cylinders_, generate=False):
geometry = scene_four_cylinders_.geometry[0]
geometry.outline_width = 0.3

buf_proxy = fresnel.preview(
scene_four_cylinders_, w=150, h=100, anti_alias=False
)
buf_proxy = fresnel.preview(scene_four_cylinders_, w=150, h=100, anti_alias=False)

if generate:
PIL.Image.fromarray(buf_proxy[:], mode="RGBA").save(
Expand Down
Loading

0 comments on commit 4e419c1

Please sign in to comment.