Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add common matrix functions to standard library #1538

Merged
merged 92 commits into from Aug 5, 2023
Merged

Conversation

keenancrane
Copy link
Collaborator

@keenancrane keenancrane commented Jul 13, 2023

image

This PR adds common matrix functions, including 2D/3D transformations and camera matrices, to the library. It also adds corresponding documentation, tests and examples, and a language feature then for left-to-right composition of transformations.

New functions

New functions added to Functions.ts are listed below. See the new Vectors and Matrices page in the Documentation, as well as the generated Function Library documentation, for further details. (Design decisions for the naming conventions are also spelled out int his documentation.)

  • fromHomogeneous
  • fromHomogeneousList
  • toHomogeneous
  • toHomogeneousList
  • toHomogeneousMatrix
  • rotate
  • scale
  • skew
  • shear
  • translate
  • rotate2d
  • scale2d
  • skew2d
  • shear2d
  • rotate3d
  • scale3d
  • shear3d
  • rotate3dh
  • scale3dh
  • shear
  • translate3dh
  • lookAt
  • perspective
  • ortho
  • project
  • projectDepth
  • projectList
  • matrixMultiplyList

New language features

This PR adds the then keyword to the Style parser/compiler. This keyword is equivalent to the * operator, except that it reverses the order of the arguments, i.e., A then B is equilvalent to B * A. The main use case, as highlighted in the documentation, is to compose transformations in "natural language order", i.e., left to right. For instance, just as one can say "flip it over and put it in the oven" to mean "flip first, put in oven second," one can also write

translate(x,y) then rotate(θ) then scale(a,b)

Tests and examples

The triangle-mesh-3d example has been updated to use the new 3D transformations and camera matrices.

A new example, dinoshade, has also been added, with an extensive README that serves as a "Style for OpenGL Programmers" guide.

All the new matrix functions come with a suite of corresponding tests, in the examples/matrix-library/. These examples use the "red/green" testing paradigm, as explained in examples/matrix-library/README.md. The particular tests are

  • crossProductMatrix.trio.json
  • diagonal2d.trio.json
  • diagonal3d.trio.json
  • identity2d.trio.json
  • identity3d.trio.json
  • inverse2d.trio.json
  • inverse3d.trio.json
  • matrix2d.trio.json
  • matrix3d.trio.json
  • outerProduct2d.trio.json
  • outerProduct3d.trio.json
  • rotate.trio.json
  • rotate2d.trio.json
  • rotate3d.trio.json
  • rotate3dh.trio.json
  • scale2d.trio.json
  • scale3d.trio.json
  • shear2d.trio.json
  • shear3d.trio.json
  • skew2d.trio.json
  • translate2d.trio.json
  • translate3dh.trio.json

Documentation

As noted above, extensive documentation for new functionality has been added in

  1. the inline function descriptions (hence the automatically generated documentation of library functions),
  2. the new Vectors and Matrices page of the documentation, which has also refactored documentation on vector/matrix types and operations from the Style Usage page, and
  3. the dinoshade example, which provides a step-by-step tutorial on usage of 3d transformation and camera matrices.

@keenancrane keenancrane changed the title Matrix library feat: Add common matrix functions to standard library Jul 13, 2023
@github-actions
Copy link

github-actions bot commented Jul 13, 2023

± Registry diff

A	matrix-library/crossProductMatrix.svg
A	matrix-library/diagonal2d.svg
A	matrix-library/diagonal3d.svg
A	matrix-library/identity2d.svg
A	matrix-library/identity3d.svg
A	matrix-library/inverse2d.svg
A	matrix-library/inverse3d.svg
A	matrix-library/matrix2d.svg
A	matrix-library/matrix3d.svg
A	matrix-library/outerProduct2d.svg
A	matrix-library/outerProduct3d.svg
A	matrix-library/rotate.svg
A	matrix-library/rotate2d.svg
A	matrix-library/rotate3d.svg
A	matrix-library/rotate3dh.svg
A	matrix-library/scale2d.svg
A	matrix-library/scale3d.svg
A	matrix-library/shear2d.svg
A	matrix-library/shear3d.svg
A	matrix-library/skew2d.svg
A	matrix-library/translate2d.svg
A	matrix-library/translate3dh.svg
M	triangle-mesh-3d/two-triangles.svg

📊 Performance

Key

Note that each bar component rounds up to the nearest 100ms, so each full bar is an overestimate by up to 400ms.

     0s   1s   2s   3s   4s   5s   6s
     |    |    |    |    |    |    |
name ▝▀▀▀▀▀▀▀▀▀▚▄▄▄▄▄▄▄▄▄▄▞▀▀▀▀▀▀▀▀▀▘
      compiling optimizing rendering

If a row has only one bar instead of four, that means it's not a trio and the bar just shows the total time spent for that example, again rounded up to the nearest 100ms.

Data

                                                          0s   1s   2s   3s   4s   5s   6s   7s   8s
                                                          |    |    |    |    |    |    |    |    |
set-theory-domain/tree-venn                               ▝▀▀▞
set-theory-domain/tree-tree                               ▝▀▞
group-theory/quaternion-multiplication-table              ▝▀▀▀▚▀▘
walk-on-spheres/SignedAngleOutside                        ▝▀▀▀▚▀
spectral-graphs/examples/hypercube                        ▝▀▀▚▘
group-theory/quaternion-cayley-graph                      ▝▀▚▀
set-theory-domain/tree-venn-3d                            ▝▚▀
atoms-and-bonds/one-water-molecule                        ▝▞
structural-formula/molecules/caffeine                     ▝▀▀▀▀▄▄▀▘
walk-on-spheres/walk-on-stars                             ▝▀▀▀▀▀▀▞▀▀▘
set-theory-domain/continuousmap                           ▝▚▘
mobius/mobius                                             ▝▚▘
linear-algebra-domain/two-vectors-perp                    ▝▚▘
tutorials/tutorial1                                       ▝▞
tutorials/tutorial2                                       ▝▞
tutorials/tutorial3                                       ▝▞
molecules/nitricacid-lewis                                ▝▀▀▚▘
exterior-algebra/vector-wedge                             ▝▚▘
shape-spec/all-shapes                                     ▝▚▀▘
shape-spec/arrowheads                                     ▝▞
graph-domain/textbook/sec1/fig1                           ▝▀▀▚▄▘
graph-domain/textbook/sec1/fig2                           ▝▀▀▀▚▄▞
graph-domain/textbook/sec1/fig3                           ▝▀▀▀▀▄▄▞
graph-domain/textbook/sec1/fig4                           ▝▀▀▀▀▀▄▄▞
spectral-graphs/examples/hexagonal-lattice                ▝▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄▄▀▀▘
spectral-graphs/examples/grid                             ▝▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄▄▀▘
spectral-graphs/examples/box                              ▝▀▀▀▀▀▀▀▀▀▀▀▀▞▘
graph-domain/textbook/sec1/fig5                           ▝▀▀▀▀▚▄▄▄▘
graph-domain/textbook/sec1/fig6                           ▝▀▀▀▀▀▀▀▀▀▀▀▀▀▚▄▄▄▄▄▄▄▄▄▄▄▄▄▘
graph-domain/textbook/sec1/fig7                           ▝▀▚▀
graph-domain/textbook/sec1/fig8a                          ▝▀▀▀▀▚▄▄▞
graph-domain/textbook/sec1/fig8b                          ▝▀▀▀▚▄▄▘
graph-domain/textbook/sec1/fig9                           ▝▀▀▀▄▀
graph-domain/textbook/sec1/fig10                          ▝▀▀▚▀
graph-domain/textbook/sec1/fig11                          ▝▀▀▀▀▄▀▘
graph-domain/textbook/sec1/fig12                          ▝▀▀▀▀▀▚▄▄▀
graph-domain/textbook/sec1/fig13                          ▝▀▀▀▀▄▄▘
graph-domain/textbook/sec2/fig3                           ▝▀▀▀▀▀▀▀▀▄▄▄▄▞
graph-domain/textbook/sec2/fig4                           ▝▀▀▀▀▚▄▄▞
graph-domain/textbook/sec2/fig5                           ▝▀▀▀▀▀▀▀▚▄▄▄▄▘
graph-domain/textbook/sec2/fig6                           ▝▀▀▀▀▀▀▀▀▚▄▄▄▄▞
graph-domain/textbook/sec2/fig9                           ▝▀▀▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▞
graph-domain/textbook/sec2/fig10a                         ▝▀▀▀▚▄▞
graph-domain/textbook/sec2/fig10b                         ▝▀▀▚▀
graph-domain/textbook/sec2/fig11a                         ▝▀▚▀
graph-domain/textbook/sec2/fig11b                         ▝▀▞
graph-domain/textbook/sec2/fig11c                         ▝▀▚▘
graph-domain/textbook/sec2/fig12                          ▝▀▚▘
graph-domain/textbook/sec2/fig13                          ▝▀▀▀▀▀▀▀▀▀▀▀▀▚▄▄▄▄▄▄▄▄▄▄▄▄▄▄▞
graph-domain/textbook/sec2/fig14                          ▝▀▀▀▚▄▞
graph-domain/textbook/sec2/fig16b                         ▝▀▀▞▘
geometry-domain/textbook_problems/c05p13                  ▝▀▀▞
geometry-domain/textbook_problems/c01p01                  ▝▀▚▘
geometry-domain/textbook_problems/c03p01                  ▝▀▀▞
geometry-domain/textbook_problems/c05p01                  ▝▀▀▞
geometry-domain/textbook_problems/ex                      ▝▀▀▀▄▘
triangle-mesh-3d/two-triangles                            ▝▀▀▞
random-sampling/test                                      ▝▀▀▀▚▘
geometry-domain/textbook_problems/c11p12                  ▝▀▀▚▞
curve-examples/catmull-rom/catmull-rom                    ▝▚▘
word-cloud/example                                        ▝▀▚▄▘
geometry-domain/siggraph-teaser                           ▝▀▀▞
minkowski-tests/maze/non-convex                           ▝▚▘
lagrange-bases/lagrange-bases                             ▝▚▘
hypergraph/hypergraph                                     ▝▀▀▀▚▄▄▄▄▄▄▄▄▘
persistent-homology/persistent-homology                   ▝▀▀▄▄▄▄▀
walk-on-spheres/laplace-estimator                         ▝▀▀▀▞▘
walk-on-spheres/poisson-estimator                         ▝▀▀▞
walk-on-spheres/nested-estimator                          ▝▀▀▀▞▘
walk-on-spheres/offcenter-estimator                       ▝▀▀▞
shape-distance/points-around-star                         ▝▀▀▀▞▘
shape-distance/points-around-polyline                     ▝▀▀▞
shape-distance/points-around-line                         ▝▀▚▘
shape-distance/lines-around-rect                          ▝▚▘
fake-3d-linear-algebra/projection                         ▝▞
animation/center-shrink-circle                            ▝▞
graph-domain/other-examples/hamiltonian-cycle             ▝▀▀▀▀▚▄▀
structural-formula/reactions/methane-combustion           ▝▀▀▀▄▄▄▄▘
molecules/glutamine                                       ▝▀▚▘
matrix-ops/tests/matrix-matrix-addition                   ▝▀▞
matrix-ops/tests/matrix-matrix-division-elementwise       ▝▀▞
matrix-ops/tests/matrix-matrix-multiplication-elementwise ▝▀▞
matrix-ops/tests/matrix-matrix-multiplication             ▝▚▘
matrix-ops/tests/matrix-matrix-subtraction                ▝▀▞
matrix-ops/tests/matrix-transpose                         ▝▚▘
matrix-ops/tests/matrix-vector-left-multiplication        ▝▚▘
matrix-ops/tests/matrix-vector-right-multiplication       ▝▚▘
matrix-ops/tests/scalar-vector-division                   ▝▚▘
matrix-ops/tests/scalar-vector-left-multiplication        ▝▚▘
matrix-ops/tests/scalar-vector-right-multiplication       ▝▚▘
matrix-ops/tests/vector-vector-addition                   ▝▚▘
matrix-ops/tests/vector-vector-division-elementwise       ▝▚▘
matrix-ops/tests/vector-vector-multiplication-elementwise ▝▚▘
matrix-ops/tests/vector-vector-outerproduct               ▝▚▘
matrix-ops/tests/vector-vector-subtraction                ▝▚▘
logic-circuit-domain/half-adder                           ▝▀▞
curve-examples/cubic-bezier                               ▝▀▄▞
triangle-mesh-2d/diagrams/cotan-formula                   ▝▀▀▚▘
triangle-mesh-2d/diagrams/concyclic-pair                  ▝▀▚▘
triangle-mesh-2d/diagrams/halfedge-mesh                   ▝▀▚▘
triangle-mesh-2d/diagrams/relative-orientation            ▝▀▞
triangle-mesh-2d/diagrams/triangle-centers                ▝▀▞
triangle-mesh-2d/diagrams/angle-equivalence               ▝▀▀▄▄▘
timeline/penrose                                          ▝▀▀▀▚▞▘
graph-domain/textbook/sec5/ex32                           ▝▀▀▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▘
curve-examples/open-elastic-curve                         ▝▀▀▄▘
curve-examples/closed-elastic-curve                       ▝▀▚▄▘
graph-domain/other-examples/arpanet                       ▝▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▄▄▄▞
graph-domain/other-examples/nyc-subway                    ▝▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▘
fancy-text/fancy-text                                     ▝▀▚▞
curve-examples/blobs                                      ▝▀▀▀▀▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▞
curve-examples/space-curves                               ▝▀▀▀▀▀▚▄▄▘
geometric-queries/ray-intersect/test-group                ▝▀▀▀▀▀▀▀▀▀▞▘
ray-tracing/path-trace                                    ▝▀▀▞
ray-tracing/bidirectional                                 ▝▀▀▀▞
ray-tracing/next-event-estimation                         ▝▀▀▞
geometric-queries/test                                    ▝▀▞
geometric-queries/closest-point/test-group                ▝▀▞
geometric-queries/closest-point/test                      ▝▚▘
geometric-queries/closest-silhouette-point/test           ▝▚▘
geometric-queries/ray-intersect/test                      ▝▀▀▀▀▀▀▀▀▞▀▘
box-arrow-diagram/computer-architecture                   ▝▀▀▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▞
stochastic-process/stochastic-process                     ▝▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▚▀▀▀▀▘
stochastic-process/epsilon-shell/AbsorbingBoundary        ▝▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▞▀▀▀▀▀▀▀▀▀▀
solid/eigenspace                                          ▐██
solid/triangles                                           ▐█▌
solid/vectors                                             ▐█
tsne/tsne                                                 ▝▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▚▄▄▄▄▄▄▄▄▀▀▀▀▀▀▀▘
spectral-graphs/examples/4x4-sudoku-graph                 ▝▀▀▀▞▘
spectral-graphs/examples/dodecahedral-graph               ▝▀▚▘
matrix-library/crossProductMatrix                         ▝▚▘
matrix-library/diagonal2d                                 ▝▞
matrix-library/diagonal3d                                 ▝▞
matrix-library/identity2d                                 ▝▞
matrix-library/identity3d                                 ▝▞
matrix-library/inverse2d                                  ▝▞
matrix-library/inverse3d                                  ▝▞
matrix-library/matrix2d                                   ▝▞
matrix-library/matrix3d                                   ▝▞
matrix-library/outerProduct2d                             ▝▞
matrix-library/outerProduct3d                             ▝▞
matrix-library/rotate                                     ▝▞
matrix-library/rotate2d                                   ▝▞
matrix-library/rotate3d                                   ▝▞
matrix-library/rotate3dh                                  ▝▞
matrix-library/scale2d                                    ▝▞
matrix-library/scale3d                                    ▝▞
matrix-library/shear2d                                    ▝▞
matrix-library/shear3d                                    ▝▞
matrix-library/skew2d                                     ▝▞
matrix-library/translate2d                                ▝▞
matrix-library/translate3dh                               ▝▞
atoms-and-bonds/wet-floor                                 ▝▀▄▘
curve-examples/offset                                     ▝▀▄▞
curve-examples/frenet-frame                               ▝▚▘
curve-examples/osculating-circle                          ▝▚▘
curve-examples/evolute-of-cardioid                        ▝▀▀▀▞
spectral-graphs/examples/truncated-cube-graph             ▝▀▚▘
spectral-graphs/examples/torus                            ▝▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄▄▞▀▘
spectral-graphs/examples/mobius                           ▝▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▚▄▄▄▀▘
spectral-graphs/examples/periodic-hexagonal-lattice       ▝▀▀▀▀▀▀▚▄▀
alloy-models/dining-philosophers                          ▝▚▘
alloy-models/message-passing                              ▝▀▀▚▄▄▄▞
alloy-models/ring-leader-election                         ▝▚▘
alloy-models/river-crossing                               ▝▞▀▀▀
alloy-models/workstations                                 ▝▀▄▘
alloy-models/generic                                      ▝▀▀▀▀▀▀▀▀▀▄▄▄▄▄▘

@cloudflare-pages
Copy link

cloudflare-pages bot commented Jul 13, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: d671bde
Status: ✅  Deploy successful!
Preview URL: https://e35e5e41.penrose-72l.pages.dev
Branch Preview URL: https://matrix-library.penrose-72l.pages.dev

View logs

@keenancrane keenancrane marked this pull request as ready for review August 1, 2023 21:04
Copy link
Member

@wodeni wodeni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these functions and the great examples @keenancrane! Really appreciated the effort to document and test them. I'm sure they will enable many more diagrams soon!

I pushed one commit to tweak the documentation, and have some questions about vouter and error-handling. Hoping you can explain the former and @liangyiliang can possibly confirm the latter.

@keenancrane
Copy link
Collaborator Author

@wodeni I believe I've fixed your requested changes, and also updated the vim highlighting files with my local ones (the ones in the repo were long out of date…). Let me know if there's anything else!

Copy link
Member

@wodeni wodeni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look great. thanks @keenancrane!

@keenancrane keenancrane merged commit fdbe56e into main Aug 5, 2023
10 checks passed
@keenancrane keenancrane deleted the matrix-library branch August 5, 2023 01:43
@jiriminarcik jiriminarcik mentioned this pull request Oct 7, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants