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 5y ago · link · parent

I have seen it, and agree it's interesting. There's one idea in there that I think is more broadly applicable - circle-like forms when the deflection angles are relatively small, and higher tension (in this case, based on ellipses) as deflections increase.

Whether these particular splines are useful for, eg, font design, I'm not yet sold :)

comment 5y ago · link · parent

I'm definitely familiar with biarcs (and did talk about them a little in the thesis) because that's the basis of Ikarus. But generally I'm not a fan of biarcs, I feel Euler spirals can do pretty much anything biarcs can, just more smoothly. The simplicity of the arc as primitive curve has some nice features though, for example the fact that parallel curve is nearly trivial.

Shipbuilding has a long connection with splines, long before digital computation. The Autokon system was built by Even Mehlum in the 60s for the Norwegian shipbuilding industry, and this was a pioneering application of the Euler spiral spline. It's not surprising to learn the Chinese shipbuilding industry was also doing interesting things and engaging with mathematicians such as Liu Ding-Yuan and Su Buqing.

comment 5y ago · link · parent

I am currently (as of the first of the year) a research software engineer on the Google Fonts team. I'm doing a bunch of font tools in Rust now, and that gives me an opportunity to revisit classic algorithms and techniques to see if there's a better way to do things than the usual.

I'm sorry you got lost. This particular technique is fairly deeply mathematical, and to really appreciate it I guess you need some grounding in the relevant math as well as familiarity with the curve and geometry concepts. I tried to get the intuition across as much as possible, certainly as opposed to the "wall of greek" I see in a lot of academic papers.

This might well turn into an academic paper - I have as a goal to do one or two of those a year. But I also really wanted to do a blog post because I think this could be useful now, and also because the insight about triplets of similar cubic Béziers is something that might be useful even to artists and designers as opposed to tool builders.

comment 5y ago · link · parent

Thanks for noticing and appreciating. It's an iterative process - if you had seen earlier drafts and my notebook, it would be a lot more confusing. I think of it as visual storytelling, and try to pick out the image that explains a certain aspect of the overall narrative. Sometimes it works out pretty well.

comment 5y ago · link · parent

Thanks for the reference. I had a quick look now, and I wish I knew about this when I wrote my thesis. For the most part, it seems to cover the standard spline literature (Farin, de Boor, etc), though it goes into more detail than usual about the nonlinear splines.

I didn't find anything in the book about this curve fitting problem specifically, though it's possible I missed it.

936.

Fitting Cubic Bézier Curves(raphlinus.github.io ↗)

178 points · by raphlinus · 5y ago · 36 comments

comment 5y ago · link · parent

I enjoyed the Handmade Seattle talk last year about the process of creating the library: https://media.handmade-seattle.com/developing-a-handmade-min...

comment 5y ago · link · parent

That's actually the joke here, which got a chuckle out of me. The idea is that excessively large audio latency itself has gotten cancelled.

I haven't played with it myself (it's been a few years since I was actively involved in Android audio latency), but from what I've seen, AAudio is pretty good, probably close to what the hardware is capable of. I'd very much encourage people to do empirical measurements against, for example, PipeWire (which also looks good). Do keep in mind that constraints are different on mobile, and things like power management can and do get in the way of down-to-the-wire latency.

comment 5y ago · link · parent

There are few tools that are both geared to mainstream programming languages and reasonable to work with. But probably the best place to start is Infer [1]. It's marketed as a static analyzer, in other words a way to prove some properties, but the separation logic at its heart is a powerful and general program proof technique.

In time, I hope and expect that the RustBelt project[2] will become a practical tool to prove Rust programs correct. It's already found some bugs in the standard library, and the main focus is currently to firm up the semantics of the language. Its separation logic engine (Iris) builds on work from Infer.

Lastly, there are less mainstream languages that are better adapted to formal proving. To pick one, I'd probably go with Idris, as it is probably best at being a general purpose programming language in addition to a mathematical tool. But there are others. Lean is exciting because it is being used as the basis of an ambitious project to formalize mathematics, and its latest version (Lean 4) is trying to be a better programming language. Coq is mature and has been used for a lot of formal proving work (it underlies Iris, mentioned above), but is not a great executable programming language. ATS 2 generates extremely efficient code (it often wins benchmarks) but is inscrutable - probably only a handful of people in the world can write nontrivial programs in it.

[1]: https://fbinfer.com/

[2]: https://plv.mpi-sws.org/rustbelt/

comment 5y ago · link · parent

This reminds me a lot of [EWD539], which was originally written as a parody about how ridiculous it would be if mathematical proofs were developed with the same kind of processes that were used for software development. At the time, the message is that programs should be developed more like mathematics, but now it seems like the actual vision Dijkstra described is more or less coming to pass.

[EWD539]: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD05xx/E...

comment 5y ago · link · parent

Tangentially, huh?

So the underlying operation of finding a parallel "curve" is trivial when the curve is a line, as it's just another line. That doesn't mean the problems is simple, though. One challenge (which I didn't address in the post, nor do I have code yet) is dealing with corners, as there are the usual choices of round, miter, and bevel. Of these, only round represents a true Minkowski sum. The others are generally more commonly used. Btw, see "Polar Stroking" [1] for more details on this. I came very close to linking it.

The second detail is the "trimming" as the parallel curve paths generally have self-intersections, and very often you don't want those. So in the general case you have to do something similar to, say, Skia path ops. It's very difficult to make those operations completely numerically robust, and I think most implementations have gone through some pain as more test cases pop up which break.

It is a fascinating area. I'm glad you're curious.

[1]: https://arxiv.org/abs/2007.00308

comment 5y ago · link · parent

Numerical stability is a fundamental problem with interpolating splines defined over Euler spirals because a unique solution is not always guaranteed to exist. I'm pretty sure there's a theorem in there somewhere if deflections can be bounded, but I haven't found it yet.

If you don't need exact Euler spirals and are ok with increasing the tension on high deflection (which imho is valid for design tasks like making fonts), then the approach of the hyperbezier spline might be an appealing alternative. I believe that always has a solution, but the current solver is kinda dumb and can fail when points are very close together. I plan on improving it.

The general idea of the hyperbezier solver - use Hermite geometric interpolation, and solve the tangent angles for G2 continuity - is a better approach than what the Spiro code does. That has technically richer capabilities (including G4 continuity if needed), but is less stable.

I don't promise anything, but if you want to file an issue against linebender/spline with more detailed requirements of what you need, I will at least take a look at it.

comment 5y ago · link · parent

Great questions, thanks!

* Yes, absolutely. The fundamental concept common to both posts is the error metric. There's no general cookbook formula for coming up with good ones (see Trefethen's work for mathematical foundations), but if the function you're approximating has simple mathematical properties, it's often possible to come up with something. The technique that seems to work best for me is some integral based on curvature and curvature variation. With Euler spirals it's super easy to compute those.

* I'm actually working on both cubic and quadratic Béziers as the final output format. I thought the story here with the n^5 scaling of cubics was simple and compelling, and the two-parabola picture might be helpful to designers.

* Related to font design and rendering, yes. The main problems I'm thinking about right now include generating optimized simplified representations (mostly for fonts), overlap removal, and warping (waving flags for emoji was a motivation). One particular facet that's especially fascinating is generating variable fonts, where the outlines need to be "interpolation compatible."

* The problem with that idea is that HN would strip the leading number from the title, which would be confusing. In my opinion, that's a valid reason not to go with it.

944.

Cleaner parallel curves with Euler spirals(raphlinus.github.io ↗)

137 points · by raphlinus · 5y ago · 12 comments

comment 5y ago · link · parent

Another characteristic of this topic is that people from different camps keep talking past each other, and the discussion goes in circles.

What you propose is basically identical to Regehr's "Proposal for a Friendly Dialect of C". What's different in 2021 that will make it succeed now when it failed in 2014? If anything, there's less interest now, as there are viable alternatives and increased investment in tools that work with standard C.

Small bugs are being fixed. One of the most surprising is that shift-left of a negative number was UB (a fact that would be shocking to anyone in the semi-portable camp, who would reasonably expect to to compile to SAL on x86). Fortunately, this (ETA: hopefully) will be fixed in C2x.

ETA: As of N2596, it's still not fixed in the C2x draft. There certainly have been proposals to fix it, and I thought it had been agreed upon, but if so, it hasn't found its way into the draft yet. In the mean time, good luck shifting those negative integers!

comment 5y ago · link · parent

No, that's the unportable camp, which doesn't have much following these days. Semi-portable basically means that you use #ifdef and similar techniques to control the code that gets generated for the particular CPU and platform. To give one example, a lock-free ring buffer may have memory barriers that are #ifdef'ed out on x86 because you can rely on total store order. Similarly, `volatile` on MSVC can be expected to provide memory ordering guarantees (see https://docs.microsoft.com/en-us/cpp/cpp/volatile-cpp?view=m...).

comment 5y ago · link · parent

This same discussion happens in every thread about C safety. I wrote about it in my essay, "With undefined behavior, anything is possible"[1].

Basically, by saying the compiler is doing things wrong even though it is following the standard, you're putting yourself in the "semi-portable C" camp. That's fine, there are lots of people in that camp. It still represents important C projects such as the Linux kernel, which is written in the GCC dialect of C, with flags to control various things that would otherwise be undefined behavior. (It now compiles in Clang as well, but I'd ascribe that to a significant effort in making Clang successfully compile the GCC dialect; in either case it's most decidedly not standard C)

Here's the thing, though. Even though a good case can be made for the semi-portable C camp, it is losing. Regehr's proposal for a "Friendly C" dialect failed, and, a few years on it certainly doesn't look like it will be taken up again. A lot of people who care about undefined behavior are simply moving to Rust. Or if you do want the advantages of C (extreme portability, excellent support from tools, etc), then you use tools such as static analyzers, sanitizers, and fuzzers, with the goal of getting all UB (as defined by the standard) out of your program.

So, bottom line, if you're hoping for consensus on "reasonable" behavior from a C compiler, so that you can count on your code working (even if it contains UB as defined by the standard), it's not going to happen.

[1]: https://raphlinus.github.io/programming/rust/2018/08/17/unde...

comment 5y ago · link · parent

Great to hear! I've poked around a little and see that, and in any case wish you success and that we can all learn from it.

comment 5y ago · link · parent

So here's what I would do if I were in this situation. I wouldn't build a graphics processing unit per se, but instead would build a highly parallel SIMD CPU organized in workgroups, and with workgroup-local shared memory. These cores could be relatively simple in some respects (they wouldn't need complex out-of-order superscalar pipelines or sophisticated branch prediction), but should have good simultaneous multithreading to hide latency effectively.

Then, if you wanted to run a traditional rasterization pipeline, you'd do it basically in software, using approaches similar to cudaraster (which is BSD licensed!). The paper on that suggests that it would be on the order 2X slower than optimized GPU hardware for triangle-centric workloads, but that might be worth it. The good news is this story gets better the more the workload diverges from what traditional GPUs are tuned for - in particular, the more sophisticated the shaders get, the more performance depends on the ability to just evaluate the shader code efficiently.

It would of course be very difficult to make a chip that is competitive with modern GPUs (the engineering involved is impressive by any standards), but I think a lot would be gained from such an effort.

I should probably disclaim that this is definitely not legal advice. Anyone who wants to actually play in the GPU space should plan on spending some quality time with a team of topnotch lawyers.

comment 5y ago · link · parent

And Google:

https://opensource.googleblog.com/2021/02/google-joins-rust-...

comment 5y ago · link · parent

I'm really happy to see this happen. I'm also really thrilled to see Lars Bergstrom on the board, and am excited about taking Rust farther both at Google and across the industry. Rust is evolving from being centered at Mozilla to being a true community and collaboration between many different groups, including big companies, so I think a well-supported foundation is key. I'm very hopeful for the future.

comment 5y ago · link · parent

The use of a permissive license allows CodeMirror to be integrated into a lot more settings than would be possible with a copyleft license, even with a paid dual-license for proprietary applications.

Marijn has given CodeMirror to the world for free, and it is in my opinion a very valuable contribution indeed. Comments like yours reflect an entitled view of what proper behavior is for an open source developer.

Obviously anyone who wants to use CodeMirror commercially but doesn't feel Marijn is due any compensation for his work is free to act on that belief. I fail to see how that's "shitty."

comment 5y ago · link · parent

https://lettersofnote.com/2011/02/14/regarding-your-stupid-c...

I don't think this is a scalable technique.

comment 5y ago · link · parent

Saying there is no execution mask from the ISA perspective isn't quite true either: `__activemask` in CUDA translates to a simple fetch of that mask, and the Vulkan subgroup operations also access it - I believe subgroupBallot(true) is equivalent.

The way I would put this: the hardware is SIMD, and the number of operations executed per clock is the same as pure SIMD, but the independent instruction pointer per thread gives the scheduler considerably more flexibility, which is useful for avoiding deadlocks on synchronization, and also helpful for hiding memory access latency.

On top of that, there's an abstraction of a large number of scalar threads running on the hardware. It's a leaky abstraction, though, as performance really requires sympathy with the underlying SIMD reality, and also the subgroup operations also expose a good deal of the implementation details of that abstraction.

comment 5y ago · link · parent

That's partly true, but there are exceptions, of which the subgroup operations are the most obvious. These are roughly similar to broadcast and permute SIMD instructions, and in some cases can lead to dramatic speedups.

comment 5y ago · link · parent

Another interesting reference from a few years ago: http://www.joshbarczak.com/blog/?p=1028

Also read the followups (1120 and 1197), as they go into considerably more detail about the SPMD programming model and some use cases.

The author is now at Intel working on ray tracing.

comment 5y ago · link · parent

I'm not a specialist, but I can link you to the answer: [1]

Key quote: "B.1.1.7 is defined by 23 mutations from the original Wuhan strain, 8 of which are in the spike protein. The 3 mutations hypothesized to have the largest potential biological effect are N501Y, spike deletion 69-70del and P681H."

The B.1.351 (South Africa) variant has N501Y but not the 69-70 deletion. We're still learning, but virologists I follow are concerned that N501Y may be a driver of higher transmission. But it's likely that multiple mutations contribute.

[1]: https://asm.org/Articles/2021/January/B-1-1-7-What-We-Know-A...

comment 5y ago · link · parent

This is a good question, but it's not obvious that geodesics will lead to the most visually pleasing gradients. In particular, because of hue super-importance, a geodesic between two highly chromatic colors of different hues will bend toward gray, which might not be as representative of a "gradient" intent as linear motion through a nice space such as Oklab or IPT.

comment 5y ago · link · parent

I think it's perfectly fine to subjectively prefer one result over another. I like thinking of results in color science as tools to help designers, rather than some objective truth. There's a lot of scientism.

From that perspective, I definitely support offering designers either an IPT or Oklab based gradient tool. With the lightness predictions, it's likely that Oklab will do a slightly better job on blend modes, but clearly they're both good color spaces, certainly a major improvement over CIELAB which is vastly more popular.

comment 5y ago · link · parent

Yes. It turns out there is quite a bit of literature on palette generation and quantization ([1] comes to mind, which uses CIELAB as you describe), but limited palettes are mostly a retro curiosity these days.

[1]: https://engineering.purdue.edu/~bouman/publications/pdf/ei94...

1
313233
63