Better HN
topnewbestaskshowjobs
Log inSign up

raphlinus

14,081 karma · joined Mar 7, 2014 (12y ago) · 1,887 submissions

I do research on fundamental UI technology and 2D graphics, with a focus on Rust and fonts. @raph@mastodon.online
Submissions

comment 4y ago · link · parent

This is exactly the hard part. If you have an intersection of even multiplicity, then they won't alternate. In addition, when you're using these things for path intersection, you also want to be notified of "near misses", because adding floating point roundoff could make these curves intersect even if the exact input doesn't.

comment 4y ago · link · parent

An at least pretty good solution to computing parallel curves of Béziers is given in [1]. This can give very accurate results with a modest number of segments, using techniques that are fast to evaluate and not terribly complicated. I know it's possible to do better in terms of number of segments, but it's not obvious to me how to make that faster than doing curve fitting and error bounding.

[1]: https://raphlinus.github.io/curves/2021/02/19/parallel-curve...

comment 4y ago · link · parent

Yes, very happy to discuss; my email is raph.levien at the mail service operated by Google.

I think my approach may be less difficult, as it's based on accepting numerical errors when curves are within epsilon of each other. Thus, a lot of the guts of my algorithm is computing bounds and geometric intervals (adapting some ideas from North's master's thesis[1]). I'm I'm not yet convinced that precise orientation is even possible with cubics.

[1]: https://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=...

comment 4y ago · link · parent

I'm working on this as we speak. As as another commenter has mentioned, the "fat line" Bézier clipping algorithm is the current state of the art, but I'm confident at this point I can do better. The weakness of this class of algorithms is when two curves are very close to each other, then they keep subdividing. Another major challenge is numerical stability - getting a guarantee that no two curve segments in the output cross is tricky and requires careful definition of what correct operation means.

I'd love to work with a more mathematical colleague on the error bounds and so on. Ideally one who knows the way of the land regarding academic publication, as I think even what I have now is publishable.

Another good implementation to be aware of is Skia path ops[1], used quite a bit in production, including fonts.

[1]: https://skia.org/docs/dev/present/pathops/

comment 4y ago · link · parent

I have no idea why this popped up now. Overall I think it holds up reasonably well, though it's in a brasher and younger voice than I would use today. I went back and fixed the link rot.

(Incidentally, the process of updating web pages on levien.com is to log in to my Linode instance and use vim to edit the static directory. I probably should upgrade to some more modern way, at least use version control, but I do get a warm sense of nostalgia doing it this way.)

comment 4y ago · link · parent

Also the mathematical basis of the Euler spiral, also known as Cornu spiral and clothoid, which is a beautiful curve and a very good basis for curvature-continuous splines. I wrote about that extensively in my thesis.

comment 4y ago · link · parent

https://raphlinus.github.io/xi/2020/06/27/xi-retrospective.h...

comment 4y ago · link · parent

I still use vim for light editing tasks (mostly when I'm already in a command line), but VS Code is my main, largely because of its excellent rust-analyzer integration. At other times I have used emacs and Sublime.

comment 4y ago · link · parent

Maybe I haven't spent enough time digging into the academic literature, but I'm not aware of very much that's good. The original Elm paper[1] is quite good but interestingly enough Elm has moved away from FRP. There are blog posts and talks but not as far as I know a paper.

The computer science content behind UI is pretty similar to that of build systems, particularly incremental computation and trying to derive dependency graphs, and [2] is a seminal paper on that topic.

If other people have suggestions I'd like to hear them.

[1]: https://people.seas.harvard.edu/~chong/pubs/pldi13-elm.pdf

[2]: https://www.microsoft.com/en-us/research/uploads/prod/2018/0...

comment 4y ago · link · parent

I will confess, an editor doesn't feel quite right unless it's Inconsolata. Source Code Pro would probably be my second choice - it's the official Rust doc font, and feels good for that.

comment 4y ago · link · parent

It was pretty good, my son and I ordered Bangkok Thai on University here in Berkeley. The satay and tom kha gai were excellent, but the chu-chee salmon wasn't as good as the last time we had it. (we got delivery rather than dine-in because of Covid caution)

comment 4y ago · link · parent

I just broke 10k a few weeks ago, so I guess I'm famous now. AMA!

comment 4y ago · link · parent

After jerk come snap, crackle, and pop. These are rarely used in practice, but I believe snap (the 4th derivative) correlates with noise in high speed trains, so it's worth optimizing railroad tracks to keep snap (and of course jerk) low. This is one reason why polynomial spirals (Spiro curves) can be great tools for representing trackways or road centerlines; with G4 continuity, snap is continuous which means crackle is finite.

Also see this paper[1] (also cited by 'jjgreen elsewhere in this thread) which discusses the perception of higher derivatives in the context of roller coaster rides.

[1]: https://iopscience.iop.org/article/10.1088/0143-0807/37/6/06...

comment 4y ago · link · parent

It might be a different mechanism, like brain-derived neurotrophic factor[1].

[1]: https://www.science.org/content/blog-post/how-antidepressant...

comment 4y ago · link · parent

Yes definitely, but my situation is unusual. I use my blog primarily to publish research results. A typical post is halfway between a typical blog post and a peer-reviewed paper in an academic journal or conference. I've been dipping my toes into the latter and have not been having as good results. Basically, a blog is more efficient in use of time, and I also like the voice where I'm trying to explain things to a broad audience.

I really don't like Medium - I did a few things there before switching to GitHub Pages. The point of writing is to reach an audience. Why accept friction to juice their monetization?

And yes, there's no question my blog opens doors for me. For example, I recently got invited to give a keynote at RustLab this fall, and I'm sure that was on the strength of a blog post I had done on Rust UI architecture.

comment 4y ago · link · parent

'infogulch has it right. A damage region is a way of saying "this region of pixels hasn't changed," but you can also say that for a scene graph, attributes of widgets, layout, the view tree, and other things. Ideally you press a key and the CPU does only a tiny amount of work figuring out what changed, followed by the GPU doing a tiny amount of work rerendering the changed pixels.

comment 4y ago · link · parent

That's fair. The main reason Tauri isn't higher on my radar is that if you're going to make an app based on the web technology stack, why not just use Electron? The tooling is mature, there's lots of knowledge, and you can use Rust modules (through wasm) easily enough. I suppose it depends on the actual use case, I'm sure there is a niche for Tauri, but it doesn't intersect use cases I'm interested in particularly.

comment 4y ago · link · parent

Thanks! I might add that explicitly, but meant it to be included under "keyboard shortcuts according to platform human interface guidelines".

comment 4y ago · link · parent

From a computation perspective, UI is fundamentally an incremental computation engine. Most elements are not changing from frame to frame, so you can either recompute and re-render, or be smarter about only propagating deltas. I'd like to propagate those deltas all the way to the GPU, so you reuse lots of things from the previous frame if they haven't been invalidated. I'll be writing about this in considerably more detail; stay tuned.

comment 4y ago · link · parent

I'll have a lot more to say about this as I gather quantitative performance data. But it's a good question. I expect the big wins are: fast 2D (vector with blends and so on) rendering with compute shaders, multithreaded creation of expensive resources like image decompression and text layout, pushing incremental reactivity all the way from app logic to GPU (as opposed to needlessly redoing work), and of course just using a fast, non-GC language.

comment 4y ago · link · parent

I don't follow slint as closely as maybe I should. I'm definitely happy there's a real product out there, and would be happy to work with them on common infrastructure, but we haven't had much interaction (yet).

comment 4y ago · link · parent

I think the answer is yes. See rui in particular (linked by its author in another comment), which inspired my Xilem exploration.

comment 4y ago · link · parent

I could probably have written this in a clearer way. Child windows like a proto-compositor in a way, just with more limitations. You can put video/3D/etc content in a child window, but there are serious tradeoffs. When it's in a scrolling container, either your scrolling implementation is built from child windows, or you're going to deal with less than perfect synchronization as you overlay a changing clip/translate for the embedded content with draws of the rest of your UI (this used to be a common problem in browsers). Modern compositor APIs have explicit transactions[1, 2] causing the various view changes to be applied at the same time. It's not that the problem can't be solved, it's that it's trickier than people imagine.

And of course a Wayland subsurface is using the compositor.

[1]: https://docs.microsoft.com/en-us/windows/win32/directcomp/ba... [2]: https://developer.apple.com/documentation/quartzcore/catrans...

comment 4y ago · link · parent

“If you want to build a ship, don’t drum up the men to gather wood, divide the work, and give orders. Instead, teach them to yearn for the vast and endless sea.” — Antoine de Saint-Exupéry

I will one hundred percent agree with you that my approach is not a good one if you want a pretty good GUI in a reasonable amount of time. For that, an incremental approach, especially adapting some existing successful design, would be better. But that is not in fact my goal, it is to yearn for the sea.

I am, quite deliberately, spending a lot of risk points. In addition to using a language which may (see elsethread) not be a good fit for expressing UI at all, I'm building a GPU 2D renderer from scratch, also using compute shader techniques which have not been proven, and I am designing a reactive architecture that is not just a simple adaptation of React. Any of these could fail, as have some of my previous attempts. But I think they will be interesting failures, in that we'll learn something, and if all the pieces do come together, it will be a UI toolkit capable of performance completely untouchable by the existing state of the art. In turn, I'm interested in how that could open up new creative possibilities constrained by current implementations.

So I'm pretty comfortable with my approach. And hey, next time you're in the Bay Area (or perhaps when I'm in your neck of the woods), lemme buy you beer and we can talk about why it gives you satisfaction to dump on other people's work.

comment 4y ago · link · parent

I'm not a fan of distance fields for GUI text rendering. Their main advantage in games is super-easy integration into the rendering pipeline (they're basically just a texture and a simple shader), but the quality is not quite as good as standard font rendering. There are other issues, including fairly large texture RAM requirements for CJK fonts, and no easy way to do do variable fonts. My main work these days is piet-gpu, which is intended to do 2D graphics (including font rendering) "the right way." In the meantime, using existing platform glyph rendering capabilities makes sense and will certainly give the best visual match to platform text.

506.

Advice for the next dozen Rust GUIs(raphlinus.github.io ↗)

345 points · by raphlinus · 4y ago · 270 comments

comment 4y ago · link · parent

Yeah, it does seem to come up a lot more often than discussions about U+5350.

comment 4y ago · link · parent

UWP is most definitely not HWND per control, and doing so would be incredibly limiting. I don't know the UWP (WinUI) internals, but on mac it's generally a CALayer per widget, and Core Animation is doing the compositing. On Windows, the Windows 8 equivalent is DirectComposition, but I think the WinRT Windows.UI.Composition interface has some capabilities not exposed through winapi.

comment 4y ago · link · parent

It used to be they didn't render high-dpi text correctly, but fixes went in for that. Even so, it's a hack and often not pixel perfect. If you're trying to do visually sophisticated things (soft shadows, fading animations), GDI+ is inadequate. So basically it looks antiquated. It might be fine for simple form-like programs.

My main point is that "native" covers a lot of ground, and "native legacy compatibility" and "native modern" are radically different technology stacks on Windows.

comment 4y ago · link · parent

A serious question: what are native controls on Windows? Is the Windows XP era where each control is its own HWND (and usually drawn with GDI+)? Is it Windows 7 era where the drawing is Direct2D? Windows 8 where the elements of the app come together with DirectComposition? Or maybe Windows 10 style which is an evolution of UWP (now rebranded WinUI), with drawing in Win2D?
1
161718
63