Skip to content

Commit

Permalink
fix z-ordering (#290)
Browse files Browse the repository at this point in the history
* fix z-ordering

* ,...

* ruff
  • Loading branch information
mscroggs authored Dec 3, 2024
1 parent 8f77ffb commit e6077db
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 8 deletions.
Binary file modified img/dual_polygon_numbering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/hexahedron_numbering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/interval_numbering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/prism_numbering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/pyramid_numbering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/quadrilateral_numbering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/tetrahedron_numbering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/triangle_numbering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 10 additions & 5 deletions symfem/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ def get_tikz_definitions(self) -> str:
class PictureElement(ABC):
"""An element in a picture."""

def __init__(self):
def __init__(self, midpoint: typing.Tuple[float, ...] = ()):
"""Create an element."""
pass
self.midpoint = midpoint

@abstractmethod
def as_svg(self, map_pt: typing.Callable[[PointType], typing.Tuple[float, float]]) -> str:
Expand Down Expand Up @@ -218,7 +218,7 @@ def __init__(self, start: PointType, end: PointType, color: str, width: float):
color: The color
width: The width of the line
"""
super().__init__()
super().__init__(tuple(sum(i) for i in zip(start, end)))
self.start = start
self.end = end
self.color = color
Expand Down Expand Up @@ -288,7 +288,7 @@ def __init__(
color: The color
width: The width of the line
"""
super().__init__()
super().__init__(tuple(sum(i) for i in zip(start, end)))
self.start = start
self.mid1 = mid1
self.mid2 = mid2
Expand Down Expand Up @@ -356,7 +356,7 @@ def __init__(self, start: PointType, end: PointType, color: str, width: float):
color: The color
width: The width of the line
"""
super().__init__()
super().__init__(tuple(sum(i) for i in zip(start, end)))
self.start = start
self.end = end
self.color = color
Expand Down Expand Up @@ -454,6 +454,7 @@ def __init__(
width: The width of the line
font: The font to use for the number
"""
super().__init__(centre)
self.centre = centre
self.number = number
self.color = color
Expand Down Expand Up @@ -530,6 +531,7 @@ def __init__(self, vertices: SetOfPoints, color: str, opacity: float):
color: The colour to fill the polygon
opacity: The opacity
"""
super().__init__(tuple(sum(i) for i in zip(*vertices)))
self.vertices = vertices
self.color = color
self.opacity = opacity
Expand Down Expand Up @@ -585,6 +587,7 @@ def __init__(self, point: PointType, math: str, color: str, font_size: int, anch
font_size: The font size
anchor: The point on the equation to anchor to
"""
super().__init__(point)
self.point = parse_point_input(point)
self.math = math
self.color = color
Expand Down Expand Up @@ -1057,6 +1060,8 @@ def as_svg(self, filename: typing.Optional[str] = None) -> str:
if self.svg_metadata is not None:
img += self.svg_metadata + "\n"

self.elements.sort(key=lambda e: self.z(e.midpoint))

for e in self.elements:
img += e.as_svg(map_pt)

Expand Down
8 changes: 5 additions & 3 deletions symfem/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -1711,11 +1711,12 @@ def z_ordered_entities(self) -> typing.List[typing.List[typing.Tuple[int, int]]]
List of lists of subentity dimensions and numbers
"""
return [
[(2, 4), (2, 0), (1, 5), (2, 2), (1, 6), (1, 1), (0, 2)],
[(2, 4), (2, 0), (1, 5), (2, 2), (1, 6), (1, 11), (1, 1), (0, 2)],
[(3, 0)],
[(2, 3), (1, 3), (1, 7), (0, 3)],
[(2, 1), (1, 0), (1, 2), (1, 4), (0, 0), (0, 1)],
[(2, 5), (1, 8), (1, 9), (1, 10), (1, 11), (0, 4), (0, 5), (0, 6), (0, 7)],
[(2, 5), (1, 9), (1, 10), (0, 6), (0, 7)],
[(1, 8), (0, 4), (0, 5)],
]

def default_reference(self) -> Reference:
Expand Down Expand Up @@ -1940,7 +1941,8 @@ def z_ordered_entities(self) -> typing.List[typing.List[typing.Tuple[int, int]]]
[(2, 2), (1, 1), (1, 5), (0, 2)],
[(3, 0)],
[(2, 1), (1, 0), (1, 2), (1, 4), (0, 0), (0, 1)],
[(2, 4), (1, 6), (1, 7), (1, 8), (0, 3), (0, 4), (0, 5)],
[(2, 4), (1, 7), (1, 8), (0, 5)],
[(1, 6), (0, 3), (0, 4)],
]

def default_reference(self) -> Reference:
Expand Down

0 comments on commit e6077db

Please sign in to comment.