1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 13:47:46 +00:00

Everywhere: Stop using NonnullRefPtrVector

This class had slightly confusing semantics and the added weirdness
doesn't seem worth it just so we can say "." instead of "->" when
iterating over a vector of NNRPs.

This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
This commit is contained in:
Andreas Kling 2023-03-06 14:17:01 +01:00
parent 104be6c8ac
commit 8a48246ed1
168 changed files with 1280 additions and 1280 deletions

View file

@ -232,52 +232,52 @@ void AntiAliasingPainter::stroke_path(Path const& path, Color color, float thick
Optional<FloatLine> first_line;
for (auto& segment : path.segments()) {
switch (segment.type()) {
switch (segment->type()) {
case Segment::Type::Invalid:
VERIFY_NOT_REACHED();
case Segment::Type::MoveTo:
cursor = segment.point();
cursor = segment->point();
break;
case Segment::Type::LineTo:
draw_line(cursor, segment.point(), color, thickness);
draw_line(cursor, segment->point(), color, thickness);
if (thickness > 1) {
if (!first_line.has_value())
first_line = FloatLine(cursor, segment.point());
first_line = FloatLine(cursor, segment->point());
if (previous_was_line)
stroke_segment_intersection(cursor, segment.point(), last_line, color, thickness);
stroke_segment_intersection(cursor, segment->point(), last_line, color, thickness);
last_line.set_a(cursor);
last_line.set_b(segment.point());
last_line.set_b(segment->point());
}
cursor = segment.point();
cursor = segment->point();
break;
case Segment::Type::QuadraticBezierCurveTo: {
auto through = static_cast<QuadraticBezierCurveSegment const&>(segment).through();
draw_quadratic_bezier_curve(through, cursor, segment.point(), color, thickness);
cursor = segment.point();
auto through = static_cast<QuadraticBezierCurveSegment const&>(*segment).through();
draw_quadratic_bezier_curve(through, cursor, segment->point(), color, thickness);
cursor = segment->point();
break;
}
case Segment::Type::CubicBezierCurveTo: {
auto& curve = static_cast<CubicBezierCurveSegment const&>(segment);
auto& curve = static_cast<CubicBezierCurveSegment const&>(*segment);
auto through_0 = curve.through_0();
auto through_1 = curve.through_1();
draw_cubic_bezier_curve(through_0, through_1, cursor, segment.point(), color, thickness);
cursor = segment.point();
draw_cubic_bezier_curve(through_0, through_1, cursor, segment->point(), color, thickness);
cursor = segment->point();
break;
}
case Segment::Type::EllipticalArcTo:
auto& arc = static_cast<EllipticalArcSegment const&>(segment);
draw_elliptical_arc(cursor, segment.point(), arc.center(), arc.radii(), arc.x_axis_rotation(), arc.theta_1(), arc.theta_delta(), color, thickness);
cursor = segment.point();
auto& arc = static_cast<EllipticalArcSegment const&>(*segment);
draw_elliptical_arc(cursor, segment->point(), arc.center(), arc.radii(), arc.x_axis_rotation(), arc.theta_1(), arc.theta_delta(), color, thickness);
cursor = segment->point();
break;
}
previous_was_line = segment.type() == Segment::Type::LineTo;
previous_was_line = segment->type() == Segment::Type::LineTo;
}
// Check if the figure was started and closed as line at the same position.
if (thickness > 1 && previous_was_line && path.segments().size() >= 2 && path.segments().first().point() == cursor
&& (path.segments().first().type() == Segment::Type::LineTo
|| (path.segments().first().type() == Segment::Type::MoveTo && path.segments()[1].type() == Segment::Type::LineTo))) {
if (thickness > 1 && previous_was_line && path.segments().size() >= 2 && path.segments().first()->point() == cursor
&& (path.segments().first()->type() == Segment::Type::LineTo
|| (path.segments().first()->type() == Segment::Type::MoveTo && path.segments()[1]->type() == Segment::Type::LineTo))) {
stroke_segment_intersection(first_line.value().a(), first_line.value().b(), last_line, color, thickness);
}
}

View file

@ -2356,35 +2356,35 @@ void Painter::stroke_path(Path const& path, Color color, int thickness)
FloatPoint cursor;
for (auto& segment : path.segments()) {
switch (segment.type()) {
switch (segment->type()) {
case Segment::Type::Invalid:
VERIFY_NOT_REACHED();
break;
case Segment::Type::MoveTo:
cursor = segment.point();
cursor = segment->point();
break;
case Segment::Type::LineTo:
draw_line(cursor.to_type<int>(), segment.point().to_type<int>(), color, thickness);
cursor = segment.point();
draw_line(cursor.to_type<int>(), segment->point().to_type<int>(), color, thickness);
cursor = segment->point();
break;
case Segment::Type::QuadraticBezierCurveTo: {
auto through = static_cast<QuadraticBezierCurveSegment const&>(segment).through();
draw_quadratic_bezier_curve(through.to_type<int>(), cursor.to_type<int>(), segment.point().to_type<int>(), color, thickness);
cursor = segment.point();
auto through = static_cast<QuadraticBezierCurveSegment const&>(*segment).through();
draw_quadratic_bezier_curve(through.to_type<int>(), cursor.to_type<int>(), segment->point().to_type<int>(), color, thickness);
cursor = segment->point();
break;
}
case Segment::Type::CubicBezierCurveTo: {
auto& curve = static_cast<CubicBezierCurveSegment const&>(segment);
auto& curve = static_cast<CubicBezierCurveSegment const&>(*segment);
auto through_0 = curve.through_0();
auto through_1 = curve.through_1();
draw_cubic_bezier_curve(through_0.to_type<int>(), through_1.to_type<int>(), cursor.to_type<int>(), segment.point().to_type<int>(), color, thickness);
cursor = segment.point();
draw_cubic_bezier_curve(through_0.to_type<int>(), through_1.to_type<int>(), cursor.to_type<int>(), segment->point().to_type<int>(), color, thickness);
cursor = segment->point();
break;
}
case Segment::Type::EllipticalArcTo:
auto& arc = static_cast<EllipticalArcSegment const&>(segment);
draw_elliptical_arc(cursor.to_type<int>(), segment.point().to_type<int>(), arc.center().to_type<int>(), arc.radii(), arc.x_axis_rotation(), arc.theta_1(), arc.theta_delta(), color, thickness);
cursor = segment.point();
auto& arc = static_cast<EllipticalArcSegment const&>(*segment);
draw_elliptical_arc(cursor.to_type<int>(), segment->point().to_type<int>(), arc.center().to_type<int>(), arc.radii(), arc.x_axis_rotation(), arc.theta_1(), arc.theta_delta(), color, thickness);
cursor = segment->point();
break;
}
}

View file

@ -27,7 +27,7 @@ void Path::elliptical_arc_to(FloatPoint point, FloatSize radii, double x_axis_ro
// Find the last point
FloatPoint last_point { 0, 0 };
if (!m_segments.is_empty())
last_point = m_segments.last().point();
last_point = m_segments.last()->point();
// Step 1 of out-of-range radii correction
if (rx == 0.0 || ry == 0.0) {
@ -120,14 +120,14 @@ void Path::close()
if (m_segments.size() <= 1)
return;
auto last_point = m_segments.last().point();
auto last_point = m_segments.last()->point();
for (ssize_t i = m_segments.size() - 1; i >= 0; --i) {
auto& segment = m_segments[i];
if (segment.type() == Segment::Type::MoveTo) {
if (last_point == segment.point())
if (segment->type() == Segment::Type::MoveTo) {
if (last_point == segment->point())
return;
append_segment<LineSegment>(segment.point());
append_segment<LineSegment>(segment->point());
invalidate_split_lines();
return;
}
@ -145,7 +145,7 @@ void Path::close_all_subpaths()
bool is_first_point_in_subpath { false };
for (auto& segment : m_segments) {
switch (segment.type()) {
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
@ -157,7 +157,7 @@ void Path::close_all_subpaths()
append_segment<LineSegment>(start_of_subpath.value());
}
is_first_point_in_subpath = true;
cursor = segment.point();
cursor = segment->point();
break;
}
case Segment::Type::LineTo:
@ -168,7 +168,7 @@ void Path::close_all_subpaths()
start_of_subpath = cursor;
is_first_point_in_subpath = false;
}
cursor = segment.point();
cursor = segment->point();
break;
case Segment::Type::Invalid:
VERIFY_NOT_REACHED();
@ -182,7 +182,7 @@ DeprecatedString Path::to_deprecated_string() const
StringBuilder builder;
builder.append("Path { "sv);
for (auto& segment : m_segments) {
switch (segment.type()) {
switch (segment->type()) {
case Segment::Type::MoveTo:
builder.append("MoveTo"sv);
break;
@ -202,21 +202,21 @@ DeprecatedString Path::to_deprecated_string() const
builder.append("Invalid"sv);
break;
}
builder.appendff("({}", segment.point());
builder.appendff("({}", segment->point());
switch (segment.type()) {
switch (segment->type()) {
case Segment::Type::QuadraticBezierCurveTo:
builder.append(", "sv);
builder.append(static_cast<QuadraticBezierCurveSegment const&>(segment).through().to_deprecated_string());
builder.append(static_cast<QuadraticBezierCurveSegment const&>(*segment).through().to_deprecated_string());
break;
case Segment::Type::CubicBezierCurveTo:
builder.append(", "sv);
builder.append(static_cast<CubicBezierCurveSegment const&>(segment).through_0().to_deprecated_string());
builder.append(static_cast<CubicBezierCurveSegment const&>(*segment).through_0().to_deprecated_string());
builder.append(", "sv);
builder.append(static_cast<CubicBezierCurveSegment const&>(segment).through_1().to_deprecated_string());
builder.append(static_cast<CubicBezierCurveSegment const&>(*segment).through_1().to_deprecated_string());
break;
case Segment::Type::EllipticalArcTo: {
auto& arc = static_cast<EllipticalArcSegment const&>(segment);
auto& arc = static_cast<EllipticalArcSegment const&>(*segment);
builder.appendff(", {}, {}, {}, {}, {}",
arc.radii().to_deprecated_string().characters(),
arc.center().to_deprecated_string().characters(),
@ -273,47 +273,47 @@ void Path::segmentize_path()
bool first = true;
for (auto& segment : m_segments) {
switch (segment.type()) {
switch (segment->type()) {
case Segment::Type::MoveTo:
if (first) {
min_x = segment.point().x();
min_y = segment.point().y();
max_x = segment.point().x();
max_y = segment.point().y();
min_x = segment->point().x();
min_y = segment->point().y();
max_x = segment->point().x();
max_y = segment->point().y();
} else {
add_point_to_bbox(segment.point());
add_point_to_bbox(segment->point());
}
cursor = segment.point();
cursor = segment->point();
break;
case Segment::Type::LineTo: {
add_line(cursor, segment.point());
cursor = segment.point();
add_line(cursor, segment->point());
cursor = segment->point();
break;
}
case Segment::Type::QuadraticBezierCurveTo: {
auto control = static_cast<QuadraticBezierCurveSegment const&>(segment).through();
Painter::for_each_line_segment_on_bezier_curve(control, cursor, segment.point(), [&](FloatPoint p0, FloatPoint p1) {
auto control = static_cast<QuadraticBezierCurveSegment const&>(*segment).through();
Painter::for_each_line_segment_on_bezier_curve(control, cursor, segment->point(), [&](FloatPoint p0, FloatPoint p1) {
add_line(p0, p1);
});
cursor = segment.point();
cursor = segment->point();
break;
}
case Segment::Type::CubicBezierCurveTo: {
auto& curve = static_cast<CubicBezierCurveSegment const&>(segment);
auto& curve = static_cast<CubicBezierCurveSegment const&>(*segment);
auto control_0 = curve.through_0();
auto control_1 = curve.through_1();
Painter::for_each_line_segment_on_cubic_bezier_curve(control_0, control_1, cursor, segment.point(), [&](FloatPoint p0, FloatPoint p1) {
Painter::for_each_line_segment_on_cubic_bezier_curve(control_0, control_1, cursor, segment->point(), [&](FloatPoint p0, FloatPoint p1) {
add_line(p0, p1);
});
cursor = segment.point();
cursor = segment->point();
break;
}
case Segment::Type::EllipticalArcTo: {
auto& arc = static_cast<EllipticalArcSegment const&>(segment);
auto& arc = static_cast<EllipticalArcSegment const&>(*segment);
Painter::for_each_line_segment_on_elliptical_arc(cursor, arc.point(), arc.center(), arc.radii(), arc.x_axis_rotation(), arc.theta_1(), arc.theta_delta(), [&](FloatPoint p0, FloatPoint p1) {
add_line(p0, p1);
});
cursor = segment.point();
cursor = segment->point();
break;
}
case Segment::Type::Invalid:
@ -337,28 +337,28 @@ Path Path::copy_transformed(Gfx::AffineTransform const& transform) const
Path result;
for (auto const& segment : m_segments) {
switch (segment.type()) {
switch (segment->type()) {
case Segment::Type::MoveTo:
result.move_to(transform.map(segment.point()));
result.move_to(transform.map(segment->point()));
break;
case Segment::Type::LineTo: {
result.line_to(transform.map(segment.point()));
result.line_to(transform.map(segment->point()));
break;
}
case Segment::Type::QuadraticBezierCurveTo: {
auto const& quadratic_segment = static_cast<QuadraticBezierCurveSegment const&>(segment);
result.quadratic_bezier_curve_to(transform.map(quadratic_segment.through()), transform.map(segment.point()));
auto const& quadratic_segment = static_cast<QuadraticBezierCurveSegment const&>(*segment);
result.quadratic_bezier_curve_to(transform.map(quadratic_segment.through()), transform.map(segment->point()));
break;
}
case Segment::Type::CubicBezierCurveTo: {
auto const& cubic_segment = static_cast<CubicBezierCurveSegment const&>(segment);
result.cubic_bezier_curve_to(transform.map(cubic_segment.through_0()), transform.map(cubic_segment.through_1()), transform.map(segment.point()));
auto const& cubic_segment = static_cast<CubicBezierCurveSegment const&>(*segment);
result.cubic_bezier_curve_to(transform.map(cubic_segment.through_0()), transform.map(cubic_segment.through_1()), transform.map(segment->point()));
break;
}
case Segment::Type::EllipticalArcTo: {
auto const& arc_segment = static_cast<EllipticalArcSegment const&>(segment);
auto const& arc_segment = static_cast<EllipticalArcSegment const&>(*segment);
result.elliptical_arc_to(
transform.map(segment.point()),
transform.map(segment->point()),
transform.map(arc_segment.center()),
transform.map(arc_segment.radii()),
arc_segment.x_axis_rotation(),

View file

@ -160,7 +160,7 @@ public:
{
float previous_y = 0;
if (!m_segments.is_empty())
previous_y = m_segments.last().point().y();
previous_y = m_segments.last()->point().y();
line_to({ x, previous_y });
}
@ -168,7 +168,7 @@ public:
{
float previous_x = 0;
if (!m_segments.is_empty())
previous_x = m_segments.last().point().x();
previous_x = m_segments.last()->point().x();
line_to({ previous_x, y });
}
@ -218,7 +218,7 @@ public:
float x;
};
NonnullRefPtrVector<Segment const> const& segments() const { return m_segments; }
Vector<NonnullRefPtr<Segment const>> const& segments() const { return m_segments; }
auto& split_lines() const
{
if (!m_split_lines.has_value()) {
@ -269,7 +269,7 @@ private:
m_segments.append(adopt_ref(*new T(forward<Args>(args)...)));
}
NonnullRefPtrVector<Segment const> m_segments {};
Vector<NonnullRefPtr<Segment const>> m_segments {};
Optional<Vector<SplitLineSegment>> m_split_lines {};
Optional<Gfx::FloatRect> m_bounding_box;