Add geometry package and a rasterizer #520
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Inspired by #514
Adds a new
Rasterizer
that is able to renderShape
s.A Shape is just an abstraction that:
There are a few more methods and optimizations, but this are the basic ones. Right now there are two public shapes (
ConvexPolygon
andCircle
), but it's not that hard to implement custom ones.A large part of the
ConvexPolygon
implementation was based on https://jtsorlinis.github.io/rendering-tutorial/Due to the way shapes are implemented, matrix operations is a bit weird:
So, for the general case, the transformation matrix needs to be inverted, as both versions of the matrix are needed.
However, concrete implementations can sometimes get away with just mapping points so, in this case,
Shape#contramapMatrix
is implemented usingShape#mapMatrix
.This is in contrast with
Plane
s, which benefit from contramappings. So, I ended up refactoring a lot of theMatrix
code in this PR as well. Which has the benefit that now it's also easier to construct transformation matrices by hand, which can help performance in some situations (e.g. if you can precompute a transformation matrix).While this breaks the API a bit (I moved
Matrix
toeu.joaocosta.minart.geometry
), I'm going to use the "It's version0.x
excuse" to not bump the major... The ergonomics of the oldMatrix
and related operations were quite bad, to the point where I doubt anyone would use that directly.Right now, the API is still experimental. I still want to:
Shape.circle
,Shape.triangle
,Shape.square
... not sure)