mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibGfx: Simplify path storage and tidy up APIs
Rather than make path segments virtual and refcounted let's store `Gfx::Path`s as a list of `FloatPoints` and a separate list of commands. This reduces the size of paths, for example, a `MoveTo` goes from 24 bytes to 9 bytes (one point + a single byte command), and removes a layer of indirection when accessing segments. A nice little bonus is transforming a path can now be done by applying the transform to all points in the path (without looking at the commands). Alongside this there's been a few minor API changes: - `path.segments()` has been removed * All current uses could be replaced by a new `path.is_empty()` API * There's also now an iterator for looping over `Gfx::Path` segments - `path.add_path(other_path)` has been removed * This was a duplicate of `path.append_path(other_path)` - `path.ensure_subpath(point)` has been removed * Had one use and is equivalent to an `is_empty()` check + `move_to()` - `path.close()` and `path.close_all_subpaths()` assume an implicit `moveto 0,0` if there's no `moveto` at the start of a path (for consistency with `path.segmentize_path()`). Only the last point could change behaviour (though in LibWeb/SVGs all paths start with a `moveto` as per the spec, it's only possible to construct a path without a starting `moveto` via LibGfx APIs).
This commit is contained in:
parent
14005f89a6
commit
8057542dea
Notes:
sideshowbarker
2024-07-17 10:54:57 +09:00
Author: https://github.com/MacDue
Commit: 8057542dea
Pull-request: https://github.com/SerenityOS/serenity/pull/23618
9 changed files with 237 additions and 273 deletions
|
@ -111,7 +111,7 @@ Gfx::Path path_from_path_instructions(ReadonlySpan<PathInstruction> instructions
|
|||
|
||||
for (auto& instruction : instructions) {
|
||||
// If the first path element uses relative coordinates, we treat them as absolute by making them relative to (0, 0).
|
||||
auto last_point = path.segments().is_empty() ? Gfx::FloatPoint { 0, 0 } : path.segments().last()->point();
|
||||
auto last_point = path.last_point();
|
||||
|
||||
auto& absolute = instruction.absolute;
|
||||
auto& data = instruction.data;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue