hgeometry icon indicating copy to clipboard operation
hgeometry copied to clipboard

Better visual debugging

Open noinia opened this issue 3 years ago • 13 comments

Debugging the algorithms is sometimes a bit of a hassle since the show instances are quite verbose. Ideally we would have some way of showing/rendering some image that shows the geometry in question. The best thing we have so far is to render ipe or svg images. But since those parts are now in separate packages, that is sometimes a bit cumbersome as well.

Ideally the user/developer can click points/polygons/segments to show whatever data is associated with them. I'm not sure what the best way is to implement any of that. I've fiddled a bit with miso (some web framework) and reflex-sdl before to try and build some interactive application to this end. But both seem a mountain of work, nor am I sure how/what I would want precisely.

Any thoughts on how we could improve the situation?

noinia avatar Dec 26 '20 12:12 noinia

Can we use hgeometry as an ipelet? I tried to find documentation for ipelets but didn't have any luck.

lemmih avatar Dec 26 '20 12:12 lemmih

ipe supports writing ipelets in lua and in c++. See e.g. the ipe manual (for whatever reason the official manual webpages are down, so I linked to some version on the archive). I investigated a bit on what the options are:

  1. I tried to write an ipelet in lua that directly called into haskell code using hslua. However, somehow I could not really get that to work (see the hgeometry-ipe/ipelet directory for some fiddling).

  2. I also considered going through c++ using the C-ffi. But somehow it didn't seem like that would be a very ergonomial solution/I didn't really know how I would get that to work precisely.

  3. The final thing I tried was to just have a haskell program that would read ipe data from an ipe file, and write its output to an ipe file again, and write a small ipelet in lua that would dump whatever was selected into a temporary file, call the haskell binary, and then load whatever was in the output file again. See my zeroset repository for details. This actually somewhat worked.

So out of these three things I think the third one would be most promising to produce an actual ipelet.

noinia avatar Dec 26 '20 16:12 noinia

I think option three is very promising. We want an hgeometry executable in any case. Wrapping the executable in an ipelet should be quite doable.

I'll give it a go. The Ipe manual is quite sparse but, apparently, I can put lua code in ~/.ipe/ipelets and have it loaded automatically.

lemmih avatar Dec 27 '20 04:12 lemmih

By the way, now that hgeometry-web compiles again we could also further investigate building some sort of interactive viewer that way. Here is a small demo that is in there (don't mind the horrible colors):

image

noinia avatar Dec 28 '20 18:12 noinia

hgeometry-web doesn't compile for me. It fails with:

src/Miso/Subscription/MouseExtra.hs:14:69: error:
    Not in scope: type constructor or class ‘Sub’
   |
14 | relativeMouseSub          :: MisoString -> ((Int,Int) -> action) -> Sub action
   |                                                                     ^^^

Maybe a version issue?

lemmih avatar Dec 29 '20 01:12 lemmih

when using GHC miso needs to be compiled with the '+jsaddle' flag

noinia avatar Dec 29 '20 08:12 noinia

How can I ask cabal to do that?

lemmih avatar Dec 29 '20 08:12 lemmih

I think 'cabal build miso -f jsaddle' should do. Or otherwise put

package miso flags: +jsaddle

in your cabal.project.local file. (or maybe we should even put it in the cabal.project file)

noinia avatar Dec 29 '20 08:12 noinia

That worked, thanks.

Maybe building it without optimizations would be feasible on the CI servers.

lemmih avatar Dec 29 '20 08:12 lemmih

Ergh, I accidentally clicked the wrong button

That worked, thanks.

Maybe building it without optimizations would be feasible on the CI servers.

Hmm I guess we can try. I think it's mostly a memory issue though. My machine has 8GB RAM and 8GB swap, but I had to manually add an additional swap file to get jsaddle-dom to build (at least with stack and GHC <= 8.6), so I'm somewhat skeptical.

noinia avatar Dec 29 '20 09:12 noinia

How does Ipe compare with Inkscape? Would it make more sense to write an Inkscape extension? @noinia

lemmih avatar Jan 10 '21 14:01 lemmih

Hmm good question. I don't really know; I know ipe well because I use often use it for work (nice features being that it supports LaTeX well, and can directly store/edit pdfs). Those are not necessarily features we care about in the debugging perspective though.

noinia avatar Jan 10 '21 17:01 noinia

  • Ipe extension:
    • Ipe is less developed than Inkscape but maybe that's a good thing.
    • Ipe is poorly documented.
    • Ipe extensions have limited capabilities. I'd love to dynamically calculate visibility polygons according to the position of the cursor but it shouldn't be straightforward in Ipe. I believe it could be done by taking advantage of the paste tool functionality but it wouldn't be pretty.
  • Inkscape extension:
    • Extension system is extremely simple. Inkscape will pipe an SVG image to a script and read the new SVG from stdout.
    • Cannot do any kind of interactivity. Querying the mouse position is impossible.
  • hgeometry-web:
    • Can be extended to do everything we want.
    • Quite difficult to build.
  • reanimate:
    • No interactivity.

I'm obviously biased but I think using 'reanimate' is one of the better options. I'll look into adding interactivity to the browser viewer.

lemmih avatar Jan 12 '21 05:01 lemmih