tldraw / tldraw

SDK for creating whiteboards and canvas experiences on the web.
https://tldraw.dev
Other
33.89k stars 2.04k forks source link

Hot elbows #2258

Closed ds300 closed 6 months ago

ds300 commented 6 months ago

Our ink has kinda homely elbows sometimes. This PR believes elbows can and should be beautiful.

The way this is achieved is by partitioning the points fed into perfect-freehand at elbow points, and then rendering each partition separately.

Doing this naively ballooned the size of the SVG path data so I also did a tiny bit of refactoring to allow us to use the SVG arc command. At the same time we are able to easily omit some of the points around the beginnings and ends of segments thanks to the nature of the corners.

All of this results in an average 13% reduction in SVG path data size over the current version.

Kapture 2023-11-27 at 14 39 57

Change Type

vercel[bot] commented 6 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
examples ✅ Ready (Inspect) Visit Preview Nov 29, 2023 11:36am
steveruizok commented 6 months ago

Hey, reviewing now. In general this is an improvement: the only place where I've noticed a regression in quality is that sharp corners tend to be reduced in size.

image

IIRC in our current freehand we actually push these corners out by a certain distance in order to capture detail. I'm not sure what the motivation for that was—it may have been a "feels good" feature, I vaguely recall adding that after watching videos of me drawing on the ipad.

steveruizok commented 6 months ago

Seems to handle short scribbles very well.

steveruizok commented 6 months ago

Some rare errors near the start of lines, like this one?

image
ds300 commented 6 months ago

ok i think i fixed those things, take another look when you have a moment.

ds300 commented 6 months ago

i think if we can get rid of these guys in a follow up it will actually be pretty close to perfect

image
steveruizok commented 6 months ago

Kapture 2023-11-29 at 10 54 14

steveruizok commented 6 months ago

Comparing the results, a few things I've noticed:

Knees are pointier due to the algorithm identifying a "sharp curve" as a "sharp corner". This is really difficult to distinguish; I remember trying to track the rate of directional change using acceleration in the past but likely just picked a "good enough" dot product change.

For example, the W and E here:

image

The settings you've used here is often an improvement, however, so I don't think it's a problem. For example, see the much improved corners around the W, A, and the twist to the D.

image

In general this is a big improvement in the detail we're able to pull from the same inputs. Well done!

steveruizok commented 6 months ago

I'm pushing a few small changes to the rendering for draw shapes.