1
0
mirror of synced 2024-09-24 03:18:22 +02:00

Don't draw shapes/sprites with zero scaling factor.

This commit is contained in:
Jennifer Taylor 2021-04-20 23:33:43 +00:00
parent 05a85abce8
commit cc25c3c8dc
2 changed files with 18 additions and 9 deletions

View File

@ -297,7 +297,11 @@ class AFPRenderer(VerboseOutput):
transform = parent_transform.multiply(renderable.tag.transform or Matrix.identity())
# Calculate the inverse so we can map canvas space back to texture space.
inverse = transform.inverse()
try:
inverse = transform.inverse()
except ZeroDivisionError:
print(f"WARNING: Transform Matrix {transform} has zero scaling factor, making it non-invertible!")
return
# Render individual shapes if this is a sprite.
if renderable.tag.source_tag_id in self.__registered_sprites:

View File

@ -123,14 +123,19 @@ class Matrix:
def inverse(self) -> "Matrix":
denom = (self.a * self.d - self.b * self.c)
return Matrix(
a=self.d / denom,
b=-self.b / denom,
c=-self.c / denom,
d=self.a / denom,
tx=(self.c * self.ty - self.d * self.tx) / denom,
ty=-(self.a * self.ty - self.b * self.tx) / denom,
)
try:
return Matrix(
a=self.d / denom,
b=-self.b / denom,
c=-self.c / denom,
d=self.a / denom,
tx=(self.c * self.ty - self.d * self.tx) / denom,
ty=-(self.a * self.ty - self.b * self.tx) / denom,
)
except ZeroDivisionError:
pass
raise ZeroDivisionError(f"Matrix({self}) cannot be inverted!")
def __repr__(self) -> str:
return f"a: {round(self.a, 5)}, b: {round(self.b, 5)}, c: {round(self.c, 5)}, d: {round(self.d, 5)}, tx: {round(self.tx, 5)}, ty: {round(self.ty, 5)}"