14,081 karma · joined Mar 7, 2014 (12y ago) · 1,887 submissions
comment 5y ago · link · parent
Whether these particular splines are useful for, eg, font design, I'm not yet sold :)
comment 5y ago · link · parent
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'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
comment 5y ago · link · parent
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
comment 5y ago · link · parent
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
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/
comment 5y ago · link · parent
[EWD539]: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD05xx/E...
comment 5y ago · link · parent
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.
comment 5y ago · link · parent
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
* 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
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
comment 5y ago · link · parent
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
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
comment 5y ago · link · parent
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
I don't think this is a scalable technique.
comment 5y ago · link · parent
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
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
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
comment 5y ago · link · parent
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
[1]: https://engineering.purdue.edu/~bouman/publications/pdf/ei94...