Skip to content

Commit

Permalink
Lint with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
janbridley committed Nov 27, 2024
1 parent 4a6c6c2 commit 188f2b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
9 changes: 5 additions & 4 deletions svg3d/shaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def diffuse_lighting(
return base_style | {"fill": new_color}



class Shader(ABC):
"""
Abstract base class for shaders.
Expand Down Expand Up @@ -121,12 +120,15 @@ def base_style(self):
def base_style(self, base_style: dict):
self._base_style = base_style


class DiffuseShader(Shader):
"""
Shade Mesh objects with per-face, Lambertian (dot product diffuse) lighting.
"""

def __init__(self, base_color="#71618D", light_direction=DEFAULT_LIGHT, base_style=None):
def __init__(
self, base_color="#71618D", light_direction=DEFAULT_LIGHT, base_style=None
):
"""Initialize the diffuse shader.
Parameters
Expand All @@ -143,7 +145,7 @@ def __init__(self, base_color="#71618D", light_direction=DEFAULT_LIGHT, base_sty
self._diffuse_light_direction = np.asarray(light_direction)

@classmethod
def from_style_dict(cls, style: dict, light_direction = DEFAULT_LIGHT):
def from_style_dict(cls, style: dict, light_direction=DEFAULT_LIGHT):
"""Create a :obj:`~.Shader` instance with a style dictionary.
Parameters
Expand All @@ -158,7 +160,6 @@ def from_style_dict(cls, style: dict, light_direction = DEFAULT_LIGHT):
new.base_style = style
return new


@classmethod
def from_color(cls, base_color):
"""Create a :obj:`~.Shader` instance with a specified base color.
Expand Down
16 changes: 8 additions & 8 deletions svg3d/svg3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import warnings
from typing import TYPE_CHECKING, Callable

Expand All @@ -25,7 +26,7 @@
"stroke": "black",
"stroke_linejoin": "round",
"stroke_width": "0.005",
} # Sample style dictionary for use in examples.
} # Sample style dictionary for use in examples.


def _pad_arrays(arrays):
Expand All @@ -40,7 +41,7 @@ def _pad_arrays(arrays):
return np.array(padded_array)


class Mesh: # TODO: rename to PolygonMesh, create Object? base class, and add Sphere
class Mesh: # TODO: rename to PolygonMesh, create Object? base class, and add Sphere
def __init__(
self,
faces: list[np.ndarray],
Expand Down Expand Up @@ -113,7 +114,7 @@ def from_coxeter(
cls,
poly: "coxeter.shapes.ConvexPolyhedron",
shader: Callable[[int, float], dict] | None = None,
style: dict | None =None,
style: dict | None = None,
):
"""Create a :obj:`~.Mesh` object from a coxeter
:class:`~coxeter.shapes.ConvexPolyhedron`."""
Expand All @@ -129,7 +130,7 @@ def from_vertices_and_faces(
vertices: np.ndarray[float],
faces: list[np.ndarray[int]],
shader: Callable[[int, float], dict] | None = None,
style: dict | None =None,
style: dict | None = None,
):
return cls(
faces=[vertices[face] for face in faces],
Expand Down Expand Up @@ -159,18 +160,18 @@ def example_mesh(cls):
[4, 6, 7, 5],
[0, 1, 3, 2],
[2, 3, 7, 6],
[1, 5, 7, 3]
[1, 5, 7, 3],
]

return cls(
faces=[vertices[face] for face in faces],
shader=DiffuseShader(base_style=EXAMPLE_STYLE),
style=EXAMPLE_STYLE
style=EXAMPLE_STYLE,
)


class Engine:
def __init__(self, views, precision:int=10):
def __init__(self, views, precision: int = 10):
"""The engine used to render a scene into an image.
Expand Down Expand Up @@ -337,7 +338,6 @@ def _sort_back_to_front(self, faces):
return np.argsort(z_centroids)



# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
Expand Down
9 changes: 4 additions & 5 deletions svg3d/view.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Define OpenGL-style views and viewports for scene rendering.
"""
"""Define OpenGL-style views and viewports for scene rendering."""

import math
from typing import NamedTuple
Expand Down Expand Up @@ -157,13 +156,13 @@ def __init__(
[0, 2, np.sqrt(2), 0],
[-np.sqrt(3), -1, np.sqrt(2), 0],
[0, 0, -100 * np.sqrt(6), np.sqrt(6)],
] / np.sqrt(6) # TODO: no-undoc-members, don't want to expose this
] / np.sqrt(6) # TODO: no-undoc-members, don't want to expose this

@property
def look_at(self):
""":math:`(4,4)` :class:`numpy.ndarray`: The openGL-style lookAt matrix.
.. TODO: add links to openGL docs, explain transpose if required.
.. TODO: add links to openGL docs, explain transpose if required.
"""
return self._look_at

Expand All @@ -175,7 +174,7 @@ def look_at(self, look_at: np.ndarray):
def projection(self):
""":math:`(4,4)` :class:`numpy.ndarray`: The openGL-style projection matrix.
.. TODO: add links to openGL docs, explain transpose if required.
.. TODO: add links to openGL docs, explain transpose if required.
"""
return self._projection

Expand Down

0 comments on commit 188f2b9

Please sign in to comment.