serenity
serenity copied to clipboard
LibGfx: Simplify path storage and tidy up APIs
Rather than make path segments virtual and refcounted let's store Gfx::Paths 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::Pathsegments
- All current uses could be replaced by a new
-
path.add_path(other_path)has been removed- This was a duplicate of
path.append_path(other_path)
- This was a duplicate of
-
path.ensure_subpath(point)has been removed- Had one use and is equivalent to an
is_empty()check +move_to()
- Had one use and is equivalent to an
-
path.close()andpath.close_all_subpaths()assume an implicitmoveto 0,0if there's nomovetoat the start of a path (for consistency withpath.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).