homotopy-rs
                                
                                 homotopy-rs copied to clipboard
                                
                                    homotopy-rs copied to clipboard
                            
                            
                            
                        Debug renderer
Far too frequently we need to get into the nitty gritty of a diagram, and this involves lots of tedious drawing by hand when we have a perfectly good 3D renderer already!
This is my attempt to add a function that can be called anywhere within homotopy-core, which when called will hijack the app and display a rotatable debug model of the diagram passed in:

It's a rough prototype, and I definitely need some help with the graphics stuff, but it's a decent way there.
Note that this is a debugging tool, so there is nothing to play with in the release version that the PR preview generates. To test it out, apply this patch:
diff --git a/homotopy-core/src/diagram.rs b/homotopy-core/src/diagram.rs
index 8e8081e..06b6092 100644
--- a/homotopy-core/src/diagram.rs
+++ b/homotopy-core/src/diagram.rs
@@ -89,6 +89,11 @@ impl Diagram {
 
     #[must_use]
     pub fn identity(&self) -> DiagramN {
+        #[cfg(debug_assertions)]
+        let (_sig, d) = crate::examples::two_monoid();
+        #[cfg(debug_assertions)]
+        crate::debug::debug_diagram(d.into());
+
         DiagramN::new_unsafe(self.clone(), vec![])
     }
and trigger the construction of an identity.
TODO:
- [x] Make text not blurry and scale correctly
- [ ] Make arrow tips not computed in the stupidest way possible
- [ ] Programatically strip diagram boundaries (currently hardcoded - that's why the tests fail too) - this will require a refactor
- [ ] Maybe generate the geometry separately from how it's generated for normal 3D mode
@doctorn would love a review on this, I'm for sure doing some things incorrectly GL-wise.
In particular, I'm almost certain this is wrong in some way: https://github.com/homotopy-io/homotopy-rs/blob/a064c1bbb14263927aaa4444efbdbea4e45eb729/homotopy-web/src/buffers.rs#L623-L653
And the way I'm initializing the 2D Canvas context is maybe not all there (could explain why the text is so pixelated).
Visit the preview URL for this PR (updated for commit 5af98eb):
https://homotopy-rs--homotopy-io-debug-ek5ikvjk.web.app
(expires Fri, 28 Oct 2022 12:02:37 GMT)
🔥 via Firebase Hosting GitHub Action 🌎
Very interesting idea Nick. How deep will this go into the scaffold?
This currently just uses the geometry you would get if you projected any diagram into 3D, but the intention is that this can be changed on the fly in order to draw any DAG representation of the fully exploded diagram. For instance, we might want to debug a 4D diagram by drawing all its 3D slices in the standard way, but in 3D space offset in the Z-axis (like the 'stack diagrams' we draw sometimes).
I'll take a look tomorrow!
I fixed the resolution problems with the text by making the 2D canvas which is drawn on top get rescaled. I also added some basic occlusion of text labels:
 Unfortunately, this occludes over everything in the 3D scene, which is unavoidable with this method of text rendering. I'm not really sure if this occlusion is worthwhile as a result.
Unfortunately, this occludes over everything in the 3D scene, which is unavoidable with this method of text rendering. I'm not really sure if this occlusion is worthwhile as a result.
Pictured is the associator; it looks a bit yikes but it's a lot nicer interactively rotating around the scene.