homotopy-rs icon indicating copy to clipboard operation
homotopy-rs copied to clipboard

Debug renderer

Open NickHu opened this issue 3 years ago • 7 comments

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: image

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.

NickHu avatar Aug 27 '22 23:08 NickHu

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

NickHu avatar Aug 27 '22 23:08 NickHu

@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).

NickHu avatar Aug 27 '22 23:08 NickHu

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 🌎

github-actions[bot] avatar Aug 27 '22 23:08 github-actions[bot]

Very interesting idea Nick. How deep will this go into the scaffold?

jamievicary avatar Aug 28 '22 08:08 jamievicary

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).

NickHu avatar Aug 28 '22 09:08 NickHu

I'll take a look tomorrow!

doctorn avatar Aug 28 '22 19:08 doctorn

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: image 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.

NickHu avatar Aug 29 '22 19:08 NickHu