Commit Graph

121 Commits

Author SHA1 Message Date
Aaron Fenyes
5e117d5877 Merge branch 'main' into app-proto
Incorporate the engine prototype from pull request #13, which just got
merged into `main`.
2024-10-21 00:25:59 -07:00
b92be312e8 Engine prototype (#13)
This PR adds code for a Julia-language prototype of a configuration solver, in the `engine-proto` folder. It uses Julia version 1.10.0.

### Approaches
Development of this PR tried two broad approaches to the constraint geometry problem. Each one suggested various solution techniques. The Gram matrix approach, with the low-rank factorization technique, seems the most promising.

- **Algebraic** *(In the `alg-test` subfolder).* Write the constraints as polynomials in the inversive coordinates of the elements, and use computational algebraic geometry techniques to solve the resulting system. We tried the following techniques.
  - **Gröbner bases** *(`Engine.Algebraic.jl`).* Symbolic. Find a Gröbner basis for the ideal generated by the constraint equations. Information about the solution variety, like its codimension, is then relatively easy to extract.
  - **Homotopy continuation** *(`Engine.Numerical.jl`).* Numerical. Cut the solution set along a random hyperplane to get a generic zero-dimensional slice, and then use a fancy homotopy technique to approximate the points in that slice.

  A few notes about our experiences can be found on the [engine prototype](wiki/Engine-prototype) wiki page.
- **Gram matrix** *(in the `gram-test` subfolder).* A construction is described completely, up to conformal transformations, by the Gram matrix of the vectors representing its elements. Express the constraints as fixed entries of the Gram matrix, and use numerical linear algebra techniques to find a list of vectors whose Gram matrix fits the bill. We tried the following techniques.
  - **LDL decomposition** *(`gram-test.sage`, `gram-test.jl`, `overlap-test.jl`).* Find a cluster of up to five elements whose Gram matrix is completely filled in by the constraints. Use LDL decomposition to find a list of vectors with that Gram matrix. This technique can be made algebraic, as seen in `overlap-test.jl`.
  - **Low-rank factorization** *(source files listed in findings section).* Write down a quadratic loss function that says how far a set of vectors is from meeting the Gram matrix constraints. Use a smooth optimization technique like Newton's method or gradient descent to find a zero of the loss function. In addition to the polished prototype described in the results section, we have an early prototype using an off-the-shelf factorization package (`low-rank-test.jl`) and an visualization of the loss function landscape near global minima (`basin-shapes.jl`).

  The [Gram matrix parameterization](wiki/Gram-matrix-parameterization) wiki page contains detailed notes on this approach.

### Findings

With the algebraic approach, we hit a performance wall pretty quickly as our constructions grew. It was often hard to find real solutions of the polynomial system, since the techniques we use work most naturally in the complex world.

With the Gram matrix approach, on the other hand, we could solve interesting problems in acceptably short times using the low-rank factorization technique. We put the optimization routine in its own module (`Engine.jl`) and used it to solve five example problems:
- `overlapping-pyramids.jl`
- `circles-in-triangle.jl`
- `sphere-in-tetrahedron.jl`
- `tetrahedron-radius-ratio.jl`
- `irisawa-hexlet.jl`

We plan to use low-rank factorization of the Gram matrix in our first app prototype.

### Visualizations

We used the visualizer in the `ganja-test` folder to visually check our low-rank factorization results. The visualizer runs [Ganja.js](https://enkimute.github.io/ganja.js/) in an Electron app, made with [Blink](https://github.com/JuliaGizmos/Blink.jl). Although Ganja.js makes beautiful pictures under most circumstances, we found two obstacles to using it in production.

- It seems to have precision problems with low-curvature spheres.
- We couldn't figure out how to customize its clipping and transparency settings, and the default settings often obscure construction details.

Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Reviewed-on: #13
Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net>
Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
2024-10-21 03:18:47 +00:00
Aaron Fenyes
517fd327fa Assembly: mark constraints as active or not 2024-10-16 23:22:25 -07:00
Aaron Fenyes
f1690b62e1 Move full interface prototype to top level 2024-10-14 17:08:44 -07:00
Aaron Fenyes
cca5a781c4 Remove standalone display prototype 2024-10-14 16:43:13 -07:00
Aaron Fenyes
abe231126d Display: restore intersection and cusp highlighting
This increases resource use a bit, because we now have to hold two
fragments in memory at once instead of just one. It's still much better
than holding all of the top twelve fragments, though!
2024-10-14 16:36:52 -07:00
Aaron Fenyes
ee1c691787 Display: shade fragments after depth sorting
This reduces register pressure significantly. This stepping stone commit
temporarily removes highlighting of intersections and cusps.
2024-10-14 16:04:56 -07:00
Aaron Fenyes
19907838ce Display: remove redundant depth test 2024-09-30 17:59:48 -07:00
Aaron Fenyes
e3120f7109 Display: remove unused fragment-sorting function 2024-09-30 16:48:36 -07:00
Aaron Fenyes
18ebf3be2c Display: add turntable for benchmarking
Together with 25fa108 and 4f8f360, this lets us do a benchmarking
routine for `full-interface` which is comparable to the one we've been
using for `inversive-display`.
2024-09-30 00:44:13 -07:00
Aaron Fenyes
edace8e4ea Outline: include ID and label in element diff key 2024-09-29 23:41:16 -07:00
Aaron Fenyes
70bd39b9e5 App: remove unused imports 2024-09-29 23:30:35 -07:00
Aaron Fenyes
25fa108e9b AddRemove: add low-curvature test assembly from inversive-display 2024-09-28 19:37:43 -07:00
Aaron Fenyes
7977b11caf AddRemove: switch between pre-made test assemblies 2024-09-28 18:56:33 -07:00
Aaron Fenyes
1c9fec36e5 Display: make scene change flag track element list 2024-09-28 18:51:28 -07:00
Aaron Fenyes
721a8716d4 Assembly: don't track element list when inserting
Calling `try_insert_element` or `insert_new_element` in a responsive
context shouldn't make the context track `elements_by_id`.
2024-09-28 18:49:17 -07:00
Aaron Fenyes
4f8f36053f App: use general test assembly from inversive-display
This moves us toward dropping the separate display prototype.
2024-09-28 14:18:04 -07:00
Aaron Fenyes
28b1ecb8e9 App: use element insertion method in test 2024-09-28 13:29:09 -07:00
Aaron Fenyes
b08dbd6f93 Assembly: factor out element insertion 2024-09-28 13:27:03 -07:00
Aaron Fenyes
bd0982f821 AddRemove: make a button that adds elements
In the process, switch selection storage back to `FxHashSet`, reverting
commit b3afd6f.
2024-09-27 14:33:49 -07:00
Aaron Fenyes
2444649dd1 AddRemove: underscore unused event variables 2024-09-26 19:17:57 -07:00
Aaron Fenyes
b3afd6f555 App: Store selection in BTreeSet
Since we're using `BTreeSet` for element constraint sets now, we might
as well use it for the selection set too. This removes the `rustc-hash`
dependency.
2024-09-26 19:16:41 -07:00
Aaron Fenyes
9b39fe56b8 Outline: include constraints in element diff key
This tells Sycamore that the outline view of an element should update
when the element's constraint set has changed. To make the constraint
set hashable, so we can include it in the diff key, we store it as a
`BTreeSet` instead of an `FxHashSet`.
2024-09-26 19:10:34 -07:00
Aaron Fenyes
f5486fb0dd AddRemove: make a button that adds constraints 2024-09-26 15:02:51 -07:00
Aaron Fenyes
4e3c86fb71 Ignore profiling folders 2024-09-26 13:23:56 -07:00
Aaron Fenyes
7ff1b9cb65 App: rename directory 2024-09-26 13:22:48 -07:00
Aaron Fenyes
e6281cdcc6 Display: shrink canvas to 600px
This makes profiling more comparable with `inversive-display`.
2024-09-25 14:48:58 -07:00
Aaron Fenyes
fc85d15f83 Outline: show constraint details 2024-09-23 00:39:14 -07:00
Aaron Fenyes
7709c61f71 Outline: spruce up styling
Use `details` elements to hide and show constraints.
2024-09-22 23:55:07 -07:00
Aaron Fenyes
edee153e37 App: remove unused import 2024-09-22 23:50:16 -07:00
Aaron Fenyes
4a24a01928 App: insert constraints consistently
Also, write constructors for state objects.
2024-09-22 14:40:31 -07:00
Aaron Fenyes
050e2373a6 App: store constraints
Draft listing of constraints in outline view.
2024-09-22 14:05:40 -07:00
Aaron Fenyes
147e275823 App: don't bother copying key into element
When we access an element, we always have its key, either because the
slab iterator yielded it along side the element or because we used it to
get the element from the slab.
2024-09-22 02:38:17 -07:00
Aaron Fenyes
d121385c18 App: store assembly elements in slab 2024-09-22 02:21:45 -07:00
Aaron Fenyes
78f8ef8215 Outline: switch to single selection 2024-09-19 17:53:07 -07:00
Aaron Fenyes
96f8b6b5f3 App: store selection in hash map
Switch `Assembly.elements` to a hash map too, since that's probably
closer to what we'll want in the future.
2024-09-19 16:08:55 -07:00
Aaron Fenyes
96afad0c97 Display: highlight selected elements 2024-09-16 15:46:45 -07:00
Aaron Fenyes
a60624884a App: add element selection 2024-09-16 11:29:44 -07:00
Aaron Fenyes
93190e99da Display: bring in keyboard navigation code 2024-09-15 11:54:39 -07:00
Aaron Fenyes
e2d3af2867 Display: say "assembly" instead of "construction"
Update variable names and comments in code from the display prototype.
2024-09-15 11:41:16 -07:00
Aaron Fenyes
7cb01bab82 Ray-caster: drop outdated performance comment
The size of the internal fragment arrays is what really matters, as
discussed in the "Display" page on the wiki.
2024-09-15 11:38:32 -07:00
Aaron Fenyes
f47be08d98 Display: get the assembly from the app state 2024-09-15 11:31:22 -07:00
Aaron Fenyes
cd18d594e0 Display: bring in ray-casting code 2024-09-14 11:46:24 -07:00
Aaron Fenyes
49655a8d62 Ray-caster: remove debug code
Remove GPU code and uniforms that were used as scaffolding during
initial development, but have now been replaced by CPU analogues.
2024-09-14 10:58:46 -07:00
Aaron Fenyes
959e4cc8b5 App: pass app state into outline as context 2024-09-13 15:15:55 -07:00
Aaron Fenyes
49170671b4 App: add display canvas 2024-09-13 14:53:12 -07:00
Aaron Fenyes
0c2869d3f3 Outline: improve code formatting 2024-09-13 00:43:19 -07:00
Aaron Fenyes
e6d1e0b865 Outline: encapsulate assembly data 2024-09-13 00:40:34 -07:00
Aaron Fenyes
d481181ef8 Outline: sort elements by ID 2024-09-13 00:07:49 -07:00
Aaron Fenyes
20b96a9764 Outline: switch from "Editor" to "App" 2024-09-12 22:39:21 -07:00