Skip to content

Truly independent web browser

LibGfx: Remove the Gfx::Path queries that only LibWeb asked

Aliaksandr Kalenik1f4d1c336318
diff --git a/Libraries/LibGfx/Path.cpp b/Libraries/LibGfx/Path.cpp
index 6052a601dc5..d114addc0e1 100644
--- a/Libraries/LibGfx/Path.cpp
+++ b/Libraries/LibGfx/Path.cpp
@@ -16,10 +16,6 @@
# include <LibGfx/Font/TypefaceCoreText.h>
#endif
-static_assert(sizeof(Gfx::PathVertex) == sizeof(Gfx::FFI::PathVertex));
-static_assert(offsetof(Gfx::PathVertex, point) == offsetof(Gfx::FFI::PathVertex, point));
-static_assert(offsetof(Gfx::PathVertex, distance) == offsetof(Gfx::FFI::PathVertex, distance));
-static_assert(offsetof(Gfx::PathVertex, direction) == offsetof(Gfx::FFI::PathVertex, direction));
static_assert(sizeof(Gfx::FloatPoint) == sizeof(Gfx::FFI::FloatPoint));
static_assert(to_underlying(Gfx::WindingRule::Nonzero) == 0 && to_underlying(Gfx::WindingRule::EvenOdd) == 1);
static_assert(to_underlying(Gfx::PathVerb::Move) == to_underlying(Gfx::FFI::PathVerb::Move));
@@ -92,56 +88,6 @@ void Path::close()
FFI::path_geometry_close(m_geometry);
}
-void Path::arc_to(FloatPoint point, float radius, bool large_arc, bool sweep)
-{
- FFI::path_geometry_arc_to(m_geometry, point.x(), point.y(), radius, large_arc, sweep);
-}
-
-void Path::quadratic_bezier_curve_to(FloatPoint through, FloatPoint point)
-{
- FFI::path_geometry_quadratic_bezier_curve_to(m_geometry, through.x(), through.y(), point.x(), point.y());
-}
-
-Vector<u8> Path::serialize_to_bytes() const
-{
- Vector<u8> bytes;
- FFI::path_geometry_encode(
- m_geometry, [](void* context, u8 const* bytes, size_t count) {
- static_cast<Vector<u8>*>(context)->append(bytes, count);
- },
- &bytes);
- return bytes;
-}
-
-float Path::length() const
-{
- return FFI::path_geometry_length(m_geometry);
-}
-
-Optional<PointAlongPath> Path::point_at_length(float distance) const
-{
- float point_and_tangent[4];
- if (!FFI::path_geometry_point_at_length(m_geometry, distance, point_and_tangent))
- return {};
- return PointAlongPath { { point_and_tangent[0], point_and_tangent[1] }, { point_and_tangent[2], point_and_tangent[3] } };
-}
-
-Vector<PathVertex> Path::vertices() const
-{
- Vector<PathVertex> vertices;
- FFI::path_geometry_vertices(
- m_geometry, [](void* context, FFI::PathVertex const* ffi_vertices, size_t count) {
- static_cast<Vector<PathVertex>*>(context)->append(reinterpret_cast<PathVertex const*>(ffi_vertices), count);
- },
- &vertices);
- return vertices;
-}
-
-bool Path::contains(FloatPoint point, WindingRule winding_rule) const
-{
- return FFI::path_geometry_contains(m_geometry, point.x(), point.y(), to_underlying(winding_rule));
-}
-
PathData PathData::from_ffi(FFI::PathGeometryData const& data)
{
return {
diff --git a/Libraries/LibGfx/Path.h b/Libraries/LibGfx/Path.h
index 027fa93003d..e1bee8133f3 100644
--- a/Libraries/LibGfx/Path.h
+++ b/Libraries/LibGfx/Path.h
@@ -8,7 +8,6 @@
#include <AK/Forward.h>
#include <AK/NonnullRefPtr.h>
-#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <AK/kmalloc.h>
@@ -16,7 +15,6 @@
#include <LibGfx/Forward.h>
#include <LibGfx/Point.h>
#include <LibGfx/Rect.h>
-#include <LibGfx/Vector2.h>
#include <LibGfx/WindingRule.h>
namespace Gfx {
@@ -28,17 +26,6 @@ struct PathGeometryData;
}
-struct PointAlongPath {
- FloatPoint point;
- FloatVector2 tangent;
-};
-
-struct PathVertex {
- FloatPoint point;
- float distance;
- FloatVector2 direction;
-};
-
enum class PathVerb : u8 {
Move,
Line,
@@ -89,16 +76,6 @@ public:
Bevel,
};
- void arc_to(FloatPoint point, float radius, bool large_arc, bool sweep);
- void quadratic_bezier_curve_to(FloatPoint through, FloatPoint point);
-
- [[nodiscard]] Vector<u8> serialize_to_bytes() const;
-
- float length() const;
- Optional<PointAlongPath> point_at_length(float distance) const;
- Vector<PathVertex> vertices() const;
- bool contains(FloatPoint point, Gfx::WindingRule) const;
-
Gfx::Path clone() const { return *this; }
PathData data() const;
diff --git a/Libraries/LibGfx/Rust/src/path.rs b/Libraries/LibGfx/Rust/src/path.rs
index 00104934183..1ca2d3affe1 100644
--- a/Libraries/LibGfx/Rust/src/path.rs
+++ b/Libraries/LibGfx/Rust/src/path.rs
@@ -335,3 +335,193 @@ impl PartialEq for Path {
// The contours are compared bit for bit, which is reflexive even for NaN.
impl Eq for Path {}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn point(x: f32, y: f32) -> FloatPoint {
+ FloatPoint { x, y }
+ }
+
+ fn assert_approximately(actual: f32, expected: f32, tolerance: f32) {
+ assert!(
+ (actual - expected).abs() <= tolerance,
+ "{actual} is not within {tolerance} of {expected}"
+ );
+ }
+
+ fn assert_point_along_path(path: &Path, distance: f32, expected_point: FloatPoint, expected_tangent: FloatPoint) {
+ let [x, y, tangent_x, tangent_y] = path
+ .point_at_length(distance)
+ .expect("a path with a point has a point at every distance");
+ for (actual, expected) in [
+ (x, expected_point.x),
+ (y, expected_point.y),
+ (tangent_x, expected_tangent.x),
+ (tangent_y, expected_tangent.y),
+ ] {
+ assert_approximately(actual, expected, 0.000_000_5);
+ }
+ }
+
+ #[test]
+ fn point_at_length_along_a_line() {
+ let mut path = Path::new();
+ path.move_to(point(0.0, 0.0));
+ path.line_to(point(100.0, 0.0));
+
+ assert_point_along_path(&path, 25.0, point(25.0, 0.0), point(1.0, 0.0));
+ assert_point_along_path(&path, -10.0, point(0.0, 0.0), point(1.0, 0.0));
+ assert_point_along_path(&path, 1000.0, point(100.0, 0.0), point(1.0, 0.0));
+ }
+
+ #[test]
+ fn point_at_length_skips_the_gaps_between_subpaths() {
+ let mut path = Path::new();
+ path.move_to(point(0.0, 0.0));
+ path.line_to(point(10.0, 0.0));
+ path.move_to(point(50.0, 50.0));
+ path.move_to(point(100.0, 100.0));
+ path.line_to(point(100.0, 110.0));
+
+ assert_point_along_path(&path, 5.0, point(5.0, 0.0), point(1.0, 0.0));
+ assert_point_along_path(&path, 15.0, point(100.0, 105.0), point(0.0, 1.0));
+ assert_point_along_path(&path, 25.0, point(100.0, 110.0), point(0.0, 1.0));
+ }
+
+ #[test]
+ fn point_at_length_along_a_closed_path() {
+ let mut path = Path::new();
+ path.move_to(point(0.0, 0.0));
+ path.line_to(point(10.0, 0.0));
+ path.line_to(point(10.0, 10.0));
+ path.line_to(point(0.0, 10.0));
+ path.close();
+
+ assert_point_along_path(&path, 15.0, point(10.0, 5.0), point(0.0, 1.0));
+ assert_point_along_path(&path, 35.0, point(0.0, 5.0), point(0.0, -1.0));
+ }
+
+ #[test]
+ fn point_at_length_of_a_path_without_length() {
+ let mut path = Path::new();
+ path.move_to(point(10.0, 20.0));
+ assert_point_along_path(&path, 5.0, point(10.0, 20.0), point(0.0, 0.0));
+
+ assert!(Path::new().point_at_length(0.0).is_none());
+ }
+
+ fn vertex(x: f32, y: f32, distance: f32, direction_x: f32, direction_y: f32) -> PathVertex {
+ PathVertex {
+ point: point(x, y),
+ distance,
+ direction: point(direction_x, direction_y),
+ }
+ }
+
+ fn assert_vertices(path: &Path, expected_vertices: &[PathVertex]) {
+ let vertices = path.vertices();
+ assert_eq!(vertices.len(), expected_vertices.len());
+ for (actual, expected) in vertices.iter().zip(expected_vertices) {
+ for (actual, expected) in [
+ (actual.point.x, expected.point.x),
+ (actual.point.y, expected.point.y),
+ (actual.distance, expected.distance),
+ (actual.direction.x, expected.direction.x),
+ (actual.direction.y, expected.direction.y),
+ ] {
+ assert_approximately(actual, expected, 0.0001);
+ }
+ }
+ }
+
+ #[test]
+ fn vertices_of_subpaths_of_lines() {
+ let mut path = Path::new();
+ path.move_to(point(0.0, 0.0));
+ path.line_to(point(10.0, 0.0));
+ path.line_to(point(10.0, 10.0));
+ path.close();
+ path.move_to(point(50.0, 50.0));
+ path.line_to(point(60.0, 50.0));
+
+ let diagonal = 200.0_f32.sqrt();
+ let inverse_sqrt_2 = 1.0 / 2.0_f32.sqrt();
+ assert_vertices(
+ &path,
+ &[
+ vertex(0.0, 0.0, 0.0, 1.0, 0.0),
+ vertex(10.0, 0.0, 10.0, 1.0, 0.0),
+ vertex(10.0, 0.0, 10.0, 0.0, 1.0),
+ vertex(10.0, 10.0, 20.0, 0.0, 1.0),
+ vertex(10.0, 10.0, 20.0, -inverse_sqrt_2, -inverse_sqrt_2),
+ vertex(0.0, 0.0, 20.0 + diagonal, -inverse_sqrt_2, -inverse_sqrt_2),
+ vertex(50.0, 50.0, 20.0 + diagonal, 1.0, 0.0),
+ vertex(60.0, 50.0, 30.0 + diagonal, 1.0, 0.0),
+ ],
+ );
+ }
+
+ #[test]
+ fn vertices_along_curves() {
+ let mut path = Path::new();
+ path.move_to(point(0.0, 0.0));
+ path.quadratic_bezier_curve_to(point(50.0, 0.0), point(100.0, 0.0));
+ assert_vertices(
+ &path,
+ &[vertex(0.0, 0.0, 0.0, 1.0, 0.0), vertex(100.0, 0.0, 100.0, 1.0, 0.0)],
+ );
+
+ let mut long_path = Path::new();
+ long_path.move_to(point(0.0, 0.0));
+ long_path.quadratic_bezier_curve_to(point(10_000_000.0, 0.0), point(20_000_000.0, 0.0));
+ assert_vertices(
+ &long_path,
+ &[
+ vertex(0.0, 0.0, 0.0, 1.0, 0.0),
+ vertex(20_000_000.0, 0.0, 20_000_000.0, 1.0, 0.0),
+ ],
+ );
+
+ let mut circle = Path::new();
+ circle.move_to(point(10.0, 0.0));
+ circle.arc_to(point(-10.0, 0.0), 10.0, false, true);
+ circle.arc_to(point(10.0, 0.0), 10.0, false, true);
+ let vertices = circle.vertices();
+ assert!(vertices.len() > 40);
+ for vertex in &vertices {
+ assert_approximately(vertex.point.x.hypot(vertex.point.y), 10.0, 0.001);
+ assert_approximately(vertex.direction.x.hypot(vertex.direction.y), 1.0, 0.001);
+ assert_approximately(
+ vertex.direction.x * vertex.point.x + vertex.direction.y * vertex.point.y,
+ 0.0,
+ 0.01,
+ );
+ }
+ for pair in vertices.windows(2) {
+ let midpoint = point(
+ (pair[0].point.x + pair[1].point.x) / 2.0,
+ (pair[0].point.y + pair[1].point.y) / 2.0,
+ );
+ assert!(midpoint.x.hypot(midpoint.y) > 10.0 - 0.5 / 16.0);
+ }
+ assert_approximately(vertices.first().unwrap().point.x, 10.0, 0.000_000_5);
+ assert_approximately(vertices.last().unwrap().point.x, 10.0, 0.000_000_5);
+ assert_approximately(vertices.last().unwrap().distance, 20.0 * std::f32::consts::PI, 0.05);
+ }
+
+ #[test]
+ fn vertices_of_a_path_without_length() {
+ let mut path = Path::new();
+ path.move_to(point(10.0, 20.0));
+ assert_vertices(&path, &[vertex(10.0, 20.0, 0.0, 0.0, 0.0)]);
+
+ let mut zero_length_line = Path::new();
+ zero_length_line.move_to(point(10.0, 20.0));
+ zero_length_line.line_to(point(10.0, 20.0));
+ assert_vertices(&zero_length_line, &[vertex(10.0, 20.0, 0.0, 0.0, 0.0)]);
+
+ assert_vertices(&Path::new(), &[]);
+ }
+}
diff --git a/Libraries/LibGfx/Rust/src/path/ffi.rs b/Libraries/LibGfx/Rust/src/path/ffi.rs
index 0af772da3de..6caca83b2ac 100644
--- a/Libraries/LibGfx/Rust/src/path/ffi.rs
+++ b/Libraries/LibGfx/Rust/src/path/ffi.rs
@@ -4,18 +4,14 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-//! The functions through which `Gfx::Path` in C++ owns, builds and queries a path.
+//! The functions through which `Gfx::Path` in C++ owns, builds and reads a path.
//!
//! Only LibGfx's copy of this crate makes and frees the paths of `Gfx::Path`. Rust code builds and
//! queries its own paths with `Path`.
use super::encoding;
use super::geometry::{PathGeometry, PathVerb};
-use super::hit_test;
-use super::measure::{self, PathVertex};
use crate::geometry::FloatPoint;
-use crate::paint_enums::WindingRule;
-use std::ffi::c_void;
/// The contours of a path, valid until the path changes or is destroyed. A path without geometry has
/// none.
@@ -34,18 +30,6 @@ fn point(x: f32, y: f32) -> FloatPoint {
FloatPoint { x, y }
}
-/// # Safety
-/// `out_point_and_tangent` must point to four floats.
-unsafe fn write_point_and_tangent(out_point_and_tangent: *mut f32, (position, tangent): (FloatPoint, FloatPoint)) {
- // SAFETY: The caller passes room for four floats.
- unsafe {
- std::ptr::write(
- out_point_and_tangent.cast::<[f32; 4]>(),
- [position.x, position.y, tangent.x, tangent.y],
- );
- }
-}
-
fn into_raw(geometry: PathGeometry) -> *mut PathGeometry {
Box::into_raw(Box::new(geometry))
}
@@ -97,35 +81,6 @@ pub unsafe extern "C" fn path_geometry_line_to(path: *mut PathGeometry, x: f32,
unsafe { &mut *path }.line_to(point(x, y));
}
-/// # Safety
-/// `path` must be a live path from this module, which nothing else uses for the call.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_quadratic_bezier_curve_to(
- path: *mut PathGeometry,
- control_x: f32,
- control_y: f32,
- x: f32,
- y: f32,
-) {
- // SAFETY: Forwarded from the caller.
- unsafe { &mut *path }.quadratic_bezier_curve_to(point(control_x, control_y), point(x, y));
-}
-
-/// # Safety
-/// `path` must be a live path from this module, which nothing else uses for the call.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_arc_to(
- path: *mut PathGeometry,
- x: f32,
- y: f32,
- radius: f32,
- large_arc: bool,
- sweep: bool,
-) {
- // SAFETY: Forwarded from the caller.
- unsafe { &mut *path }.arc_to(point(x, y), radius, large_arc, sweep);
-}
-
/// # Safety
/// `path` must be a live path from this module, which nothing else uses for the call.
#[unsafe(no_mangle)]
@@ -194,74 +149,6 @@ pub unsafe extern "C" fn path_geometry_contour_close(path: *mut PathGeometry) {
unsafe { &mut *path }.contour_close();
}
-/// # Safety
-/// `path` must be a live path from this module.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_length(path: *const PathGeometry) -> f32 {
- // SAFETY: Forwarded from the caller.
- measure::length(unsafe { &*path })
-}
-
-/// Writes the point and the unit tangent at the distance along the path, and returns whether the path
-/// has a point.
-///
-/// # Safety
-/// `path` must be a live path from this module, and `out_point_and_tangent` must point to four floats.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_point_at_length(
- path: *const PathGeometry,
- distance: f32,
- out_point_and_tangent: *mut f32,
-) -> bool {
- // SAFETY: Forwarded from the caller.
- let Some(point_and_tangent) = measure::point_at_length(unsafe { &*path }, distance) else {
- return false;
- };
- // SAFETY: Forwarded from the caller.
- unsafe { write_point_and_tangent(out_point_and_tangent, point_and_tangent) };
- true
-}
-
-/// Calls the callback once with the vertices of the polylines that follow the path.
-///
-/// # Safety
-/// `path` must be a live path from this module, and the callback must accept `context`.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_vertices(
- path: *const PathGeometry,
- callback: unsafe extern "C" fn(*mut c_void, *const PathVertex, usize),
- context: *mut c_void,
-) {
- // SAFETY: Forwarded from the caller.
- let vertices = measure::vertices(unsafe { &*path });
- // SAFETY: The vertices live for the synchronous call.
- unsafe { callback(context, vertices.as_ptr(), vertices.len()) };
-}
-
-/// # Safety
-/// `path` must be a live path from this module.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_contains(path: *const PathGeometry, x: f32, y: f32, winding_rule: i32) -> bool {
- // SAFETY: Forwarded from the caller.
- hit_test::contains(unsafe { &*path }, x, y, WindingRule::from_raw(winding_rule))
-}
-
-/// Calls the callback once with the byte form of the path.
-///
-/// # Safety
-/// `path` must be a live path from this module, and the callback must accept `context`.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_encode(
- path: *const PathGeometry,
- callback: unsafe extern "C" fn(*mut c_void, *const u8, usize),
- context: *mut c_void,
-) {
- // SAFETY: Forwarded from the caller.
- let bytes = encoding::encode(unsafe { &*path });
- // SAFETY: The bytes live for the synchronous call.
- unsafe { callback(context, bytes.as_ptr(), bytes.len()) };
-}
-
/// The path that the bytes describe. Bytes that describe no path give an empty path.
///
/// # Safety
diff --git a/Tests/LibGfx/CMakeLists.txt b/Tests/LibGfx/CMakeLists.txt
index c708e886e0f..38315371af4 100644
--- a/Tests/LibGfx/CMakeLists.txt
+++ b/Tests/LibGfx/CMakeLists.txt
@@ -5,7 +5,6 @@ set(TEST_SOURCES
TestFont.cpp
TestImageDecoder.cpp
TestImageWriter.cpp
- TestPath.cpp
TestRect.cpp
TestSharedFontProvider.cpp
TestWOFF.cpp
diff --git a/Tests/LibGfx/TestPath.cpp b/Tests/LibGfx/TestPath.cpp
deleted file mode 100644
index 1225a9d8b56..00000000000
--- a/Tests/LibGfx/TestPath.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/Math.h>
-#include <LibGfx/Path.h>
-#include <LibTest/TestCase.h>
-
-static void expect_point_along_path(Gfx::Path const& path, float distance, Gfx::FloatPoint point, Gfx::FloatVector2 tangent)
-{
- auto point_along_path = path.point_at_length(distance);
- VERIFY(point_along_path.has_value());
- EXPECT_APPROXIMATE(point_along_path->point.x(), point.x());
- EXPECT_APPROXIMATE(point_along_path->point.y(), point.y());
- EXPECT_APPROXIMATE(point_along_path->tangent.x(), tangent.x());
- EXPECT_APPROXIMATE(point_along_path->tangent.y(), tangent.y());
-}
-
-TEST_CASE(point_at_length_along_a_line)
-{
- Gfx::Path path;
- path.move_to({ 0, 0 });
- path.line_to({ 100, 0 });
-
- expect_point_along_path(path, 25, { 25, 0 }, { 1, 0 });
- expect_point_along_path(path, -10, { 0, 0 }, { 1, 0 });
- expect_point_along_path(path, 1000, { 100, 0 }, { 1, 0 });
-}
-
-TEST_CASE(point_at_length_skips_the_gaps_between_subpaths)
-{
- Gfx::Path path;
- path.move_to({ 0, 0 });
- path.line_to({ 10, 0 });
- path.move_to({ 50, 50 });
- path.move_to({ 100, 100 });
- path.line_to({ 100, 110 });
-
- expect_point_along_path(path, 5, { 5, 0 }, { 1, 0 });
- expect_point_along_path(path, 15, { 100, 105 }, { 0, 1 });
- expect_point_along_path(path, 25, { 100, 110 }, { 0, 1 });
-}
-
-TEST_CASE(point_at_length_along_a_closed_path)
-{
- Gfx::Path path;
- path.move_to({ 0, 0 });
- path.line_to({ 10, 0 });
- path.line_to({ 10, 10 });
- path.line_to({ 0, 10 });
- path.close();
-
- expect_point_along_path(path, 15, { 10, 5 }, { 0, 1 });
- expect_point_along_path(path, 35, { 0, 5 }, { 0, -1 });
-}
-
-TEST_CASE(point_at_length_of_a_path_without_length)
-{
- Gfx::Path path;
- path.move_to({ 10, 20 });
- expect_point_along_path(path, 5, { 10, 20 }, { 0, 0 });
-
- EXPECT(!Gfx::Path {}.point_at_length(0).has_value());
-}
-
-static void expect_vertices(Gfx::Path const& path, Vector<Gfx::PathVertex> const& expected_vertices)
-{
- auto vertices = path.vertices();
- VERIFY(vertices.size() == expected_vertices.size());
- for (size_t i = 0; i < vertices.size(); ++i) {
- EXPECT_APPROXIMATE_WITH_ERROR(vertices[i].point.x(), expected_vertices[i].point.x(), 0.0001f);
- EXPECT_APPROXIMATE_WITH_ERROR(vertices[i].point.y(), expected_vertices[i].point.y(), 0.0001f);
- EXPECT_APPROXIMATE_WITH_ERROR(vertices[i].distance, expected_vertices[i].distance, 0.0001f);
- EXPECT_APPROXIMATE_WITH_ERROR(vertices[i].direction.x(), expected_vertices[i].direction.x(), 0.0001f);
- EXPECT_APPROXIMATE_WITH_ERROR(vertices[i].direction.y(), expected_vertices[i].direction.y(), 0.0001f);
- }
-}
-
-TEST_CASE(vertices_of_subpaths_of_lines)
-{
- Gfx::Path path;
- path.move_to({ 0, 0 });
- path.line_to({ 10, 0 });
- path.line_to({ 10, 10 });
- path.close();
- path.move_to({ 50, 50 });
- path.line_to({ 60, 50 });
-
- auto diagonal = AK::sqrt(200.f);
- auto inverse_sqrt_2 = 1 / AK::sqrt(2.f);
- expect_vertices(path,
- {
- { { 0, 0 }, 0, { 1, 0 } },
- { { 10, 0 }, 10, { 1, 0 } },
- { { 10, 0 }, 10, { 0, 1 } },
- { { 10, 10 }, 20, { 0, 1 } },
- { { 10, 10 }, 20, { -inverse_sqrt_2, -inverse_sqrt_2 } },
- { { 0, 0 }, 20 + diagonal, { -inverse_sqrt_2, -inverse_sqrt_2 } },
- { { 50, 50 }, 20 + diagonal, { 1, 0 } },
- { { 60, 50 }, 30 + diagonal, { 1, 0 } },
- });
-}
-
-TEST_CASE(vertices_along_curves)
-{
- Gfx::Path path;
- path.move_to({ 0, 0 });
- path.quadratic_bezier_curve_to({ 50, 0 }, { 100, 0 });
- expect_vertices(path, { { { 0, 0 }, 0, { 1, 0 } }, { { 100, 0 }, 100, { 1, 0 } } });
-
- Gfx::Path long_path;
- long_path.move_to({ 0, 0 });
- long_path.quadratic_bezier_curve_to({ 10'000'000, 0 }, { 20'000'000, 0 });
- expect_vertices(long_path, { { { 0, 0 }, 0, { 1, 0 } }, { { 20'000'000, 0 }, 20'000'000, { 1, 0 } } });
-
- Gfx::Path circle;
- circle.move_to({ 10, 0 });
- circle.arc_to({ -10, 0 }, 10, false, true);
- circle.arc_to({ 10, 0 }, 10, false, true);
- auto vertices = circle.vertices();
- EXPECT(vertices.size() > 40);
- for (auto const& vertex : vertices) {
- EXPECT_APPROXIMATE_WITH_ERROR(vertex.point.distance_from({ 0, 0 }), 10.f, 0.001f);
- EXPECT_APPROXIMATE_WITH_ERROR(vertex.direction.length(), 1.f, 0.001f);
- EXPECT_APPROXIMATE_WITH_ERROR(vertex.direction.dot({ vertex.point.x(), vertex.point.y() }), 0.f, 0.01f);
- }
- for (size_t i = 1; i < vertices.size(); ++i) {
- auto midpoint = (vertices[i - 1].point + vertices[i].point) / 2;
- EXPECT(midpoint.distance_from({ 0, 0 }) > 10.f - 0.5f / 16);
- }
- EXPECT_APPROXIMATE(vertices.first().point.x(), 10.f);
- EXPECT_APPROXIMATE(vertices.last().point.x(), 10.f);
- EXPECT_APPROXIMATE_WITH_ERROR(vertices.last().distance, 20 * AK::Pi<float>, 0.05f);
-}
-
-TEST_CASE(vertices_of_a_path_without_length)
-{
- Gfx::Path path;
- path.move_to({ 10, 20 });
- expect_vertices(path, { { { 10, 20 }, 0, {} } });
-
- Gfx::Path zero_length_line;
- zero_length_line.move_to({ 10, 20 });
- zero_length_line.line_to({ 10, 20 });
- expect_vertices(zero_length_line, { { { 10, 20 }, 0, {} } });
-
- expect_vertices(Gfx::Path {}, {});
-}