LibGfx: Add Path::close_all_subpaths()
Unlike Path::close() which closes only the last subpath (if possible), this closure mechanism closes _all_ available subpaths.
This commit is contained in:
parent
c3aa249a36
commit
6f15f23a40
Notes:
sideshowbarker
2024-07-19 06:48:18 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/6f15f23a40c Pull-request: https://github.com/SerenityOS/serenity/pull/2174 Issue: https://github.com/SerenityOS/serenity/issues/2172
2 changed files with 42 additions and 0 deletions
|
@ -55,6 +55,47 @@ void Path::close()
|
|||
}
|
||||
}
|
||||
|
||||
void Path::close_all_subpaths()
|
||||
{
|
||||
if (m_segments.size() <= 1)
|
||||
return;
|
||||
|
||||
invalidate_split_lines();
|
||||
|
||||
Optional<FloatPoint> cursor, start_of_subpath;
|
||||
bool is_first_point_in_subpath { false };
|
||||
|
||||
for (auto& segment : m_segments) {
|
||||
switch (segment.type) {
|
||||
case Segment::Type::MoveTo: {
|
||||
if (cursor.has_value() && !is_first_point_in_subpath) {
|
||||
// This is a move from a subpath to another
|
||||
// connect the two ends of this subpath before
|
||||
// moving on to the next one
|
||||
ASSERT(start_of_subpath.has_value());
|
||||
|
||||
m_segments.append({ Segment::Type::MoveTo, cursor.value() });
|
||||
m_segments.append({ Segment::Type::LineTo, start_of_subpath.value() });
|
||||
}
|
||||
is_first_point_in_subpath = true;
|
||||
cursor = segment.point;
|
||||
break;
|
||||
}
|
||||
case Segment::Type::LineTo:
|
||||
case Segment::Type::QuadraticBezierCurveTo:
|
||||
if (is_first_point_in_subpath) {
|
||||
start_of_subpath = cursor;
|
||||
is_first_point_in_subpath = false;
|
||||
}
|
||||
cursor = segment.point;
|
||||
break;
|
||||
case Segment::Type::Invalid:
|
||||
ASSERT_NOT_REACHED();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String Path::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
|
|
@ -69,6 +69,7 @@ public:
|
|||
}
|
||||
|
||||
void close();
|
||||
void close_all_subpaths();
|
||||
|
||||
struct LineSegment {
|
||||
FloatPoint from, to;
|
||||
|
|
Loading…
Add table
Reference in a new issue