Skip to content

Truly independent web browser

LibWeb: Implement SVGGeometryElement.getPointAtLength()

Jelle Raaijmakers68e820c6a70e
diff --git a/Libraries/LibWeb/SVG/SVGGeometryElement.cpp b/Libraries/LibWeb/SVG/SVGGeometryElement.cpp
index c8120a0ac80..7ab10cd5355 100644
--- a/Libraries/LibWeb/SVG/SVGGeometryElement.cpp
+++ b/Libraries/LibWeb/SVG/SVGGeometryElement.cpp
@@ -15,6 +15,7 @@
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/SVG/SVGGeometryElement.h>
+#include <LibWeb/WebIDL/DOMException.h>
namespace Web::SVG {
@@ -111,10 +112,26 @@ WebIDL::ExceptionOr<float> SVGGeometryElement::get_total_length()
return computed_path().length();
}
-GC::Ref<Geometry::DOMPoint> SVGGeometryElement::get_point_at_length(float distance)
+// https://w3c.github.io/svgwg/svg2-draft/types.html#__svg__SVGGeometryElement__getPointAtLength
+WebIDL::ExceptionOr<GC::Ref<Geometry::DOMPoint>> SVGGeometryElement::get_point_at_length(float distance)
{
- (void)distance;
- return Geometry::DOMPoint::create(0, 0, 0, 0);
+ // When getPointAtLength(distance) is called, the following steps are run:
+ auto path = computed_path();
+
+ // 1. If current element is a non-rendered element, and the UA is not able to compute the total length of the path,
+ // then throw an InvalidStateError.
+ // NB: Like other engines, throw for an empty path whether or not the element is rendered.
+ auto point_along_path = path.point_at_length(distance);
+ if (!point_along_path.has_value())
+ return WebIDL::InvalidStateError::create(HTML::relevant_realm(*this), "The element's path is empty"_utf16);
+
+ // 2. Let length be the user agent's computed value for the total length of the path, in user units.
+ // 3. Clamp distance to [0, length].
+ // 4. Let (x, y) be the point on the path at distance distance.
+ // NB: Gfx::Path::point_at_length() clamps the distance to the ends of the path.
+
+ // 5. Return a newly created, detached DOMPoint object representing the point (x, y).
+ return Geometry::DOMPoint::create(point_along_path->point.x(), point_along_path->point.y(), 0, 1);
}
GC::Ref<SVGAnimatedNumber> SVGGeometryElement::path_length()
diff --git a/Libraries/LibWeb/SVG/SVGGeometryElement.h b/Libraries/LibWeb/SVG/SVGGeometryElement.h
index 967e3b0c737..68366f199a2 100644
--- a/Libraries/LibWeb/SVG/SVGGeometryElement.h
+++ b/Libraries/LibWeb/SVG/SVGGeometryElement.h
@@ -24,7 +24,7 @@ public:
Gfx::Path computed_path();
WebIDL::ExceptionOr<float> get_total_length();
- GC::Ref<Geometry::DOMPoint> get_point_at_length(float distance);
+ WebIDL::ExceptionOr<GC::Ref<Geometry::DOMPoint>> get_point_at_length(float distance);
GC::Ref<SVGAnimatedNumber> path_length();
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/path/property/test_style_flush_on_dom_api_with_d_property.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/path/property/test_style_flush_on_dom_api_with_d_property.txt
new file mode 100644
index 00000000000..f6e9453dcb8
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/path/property/test_style_flush_on_dom_api_with_d_property.txt
@@ -0,0 +1,10 @@
+Harness status: OK
+
+Found 4 tests
+
+2 Pass
+2 Fail
+Pass getTotalLength() with d property
+Pass getPointAtLength() with d property
+Fail isPointInFill() with d property
+Fail isPointInStroke() with d property
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/shapes/line-getPointAtLength.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/shapes/line-getPointAtLength.txt
new file mode 100644
index 00000000000..13b25666cc8
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/shapes/line-getPointAtLength.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Pass
+Pass line supports getPointAtLength
+Pass line getPointAtLength ignores pathLength
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/shapes/scripted/ellipse-auto-radii.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/shapes/scripted/ellipse-auto-radii.txt
new file mode 100644
index 00000000000..96a42d9fbc8
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/shapes/scripted/ellipse-auto-radii.txt
@@ -0,0 +1,13 @@
+Harness status: OK
+
+Found 7 tests
+
+5 Pass
+2 Fail
+Pass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, getTotalLength resolves auto rx/ry.
+Pass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, getTotalLength returns 0 when both rx and ry are auto.
+Pass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, getPointAtLength(0) at the 3 o'clock starting point.
+Fail SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, isPointInFill resolves auto rx/ry.
+Fail SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, isPointInStroke with dasharray resolves auto rx/ry.
+Pass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, getTotalLength resolves auto rx/ry against percentage values on the correct axis.
+Pass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, getPointAtLength(0) with percentage ry uses height-axis resolution.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/elements/SVGGeometryElement-rect.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/elements/SVGGeometryElement-rect.txt
new file mode 100644
index 00000000000..0a3b1c13f4a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/elements/SVGGeometryElement-rect.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Pass
+Pass getTotalLength and getPointAtLength do not take pathLength into account
+Pass getPointAtLength() returns instance of SVGPoint
+Pass getTotalLength and getPointAtLength are not affected by zoom
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-01.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-01.txt
new file mode 100644
index 00000000000..fe7ff4fc7ab
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-01.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 4 tests
+
+4 Pass
+Pass SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length], less than zero (SVGLineElement).
+Pass SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length], less than zero (SVGPathElement).
+Pass SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length], greater than 'length' (SVGLineElement).
+Pass SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length], greater than 'length' (SVGPathElement).
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-02.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-02.txt
new file mode 100644
index 00000000000..fd56f632955
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-02.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass SVGGeometryElement.prototype.getPointAtLength() query with 'pathLength'
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-03.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-03.txt
new file mode 100644
index 00000000000..136d8371771
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-03.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Pass
+Pass When SVGGeometryElement.getPointAtLength is called with an element that is not in the document, either succeed or throw exception with SVGPathElement
+Pass When SVGGeometryElement.getPointAtLength is called with an element that is not in the document, either succeed or throw exception with SVGRectElement
+Pass When SVGGeometryElement.getPointAtLength is called with an element that is not in the document, either succeed or throw exception with SVGCircleElement
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-04.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-04.txt
new file mode 100644
index 00000000000..457ddf57eae
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-04.txt
@@ -0,0 +1,18 @@
+Harness status: OK
+
+Found 13 tests
+
+13 Pass
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, path with display: default
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, path with display: none
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, path with display: none and inline style
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, rect with display: default
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, rect with display: none
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, circle with display: default
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, circle with display: none
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, polygon with display: default
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, polygon with display: none
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, polyline with display: default
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, polyline with display: none
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, ellipse with display: default
+Pass SVGGeometryElement.getPointAtLength: 'display' and a valid path, ellipse with display: none
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-05.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-05.txt
new file mode 100644
index 00000000000..4608df75281
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-05.txt
@@ -0,0 +1,17 @@
+Harness status: OK
+
+Found 12 tests
+
+12 Pass
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, path with display: default and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, path with display: none and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, rect with display: default and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, rect with display: none and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, circle with display: default and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, circle with display: none and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, polygon with display: default and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, polygon with display: none and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, polyline with display: default and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, polyline with display: none and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, ellipse with display: default and an empty path
+Pass SVGGeometryElement.getPointAtLength: 'display' and empty path, ellipse with display: none and an empty path
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/path/property/test_style_flush_on_dom_api_with_d_property.html b/Tests/LibWeb/Text/input/wpt-import/svg/path/property/test_style_flush_on_dom_api_with_d_property.html
new file mode 100644
index 00000000000..16cfb8cb5aa
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/path/property/test_style_flush_on_dom_api_with_d_property.html
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<title>Test DOM APIs which flush the style properly, with d property</title>
+<meta charset=utf-8>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<style>
+svg {
+ width: 10%;
+ height: 10%;
+ background: #eee;
+}
+svg path {
+ fill: none;
+ stroke: #000;
+}
+</style>
+
+<div id="log"></div>
+
+<svg viewBox="0 0 20 20" id="svgroot"></svg>
+
+<script>
+'use strict';
+
+function createPath(t) {
+ const target = document.createElementNS("http://www.w3.org/2000/svg", "path");
+ document.getElementById('svgroot').appendChild(target);
+
+ if (t && typeof t.add_cleanup === "function") {
+ t.add_cleanup(function() {
+ target.remove();
+ });
+ }
+
+ // Set an initial d and flush style first to make sure the following DOM APIs
+ // do flush again.
+ target.style.d = 'path("M 0 0")';
+ assert_equals(getComputedStyle(target).d, 'path("M 0 0")', "the initial d");
+ return target;
+}
+
+test(function(t) {
+ const target = createPath(t);
+ target.style.d = 'path("M5,5 L10,5 L10,10")';
+ assert_equals(target.getTotalLength(), 10, "the total length");
+}, "getTotalLength() with d property");
+
+test(function(t) {
+ const target = createPath(t);
+ target.style.d = 'path("M5,5 L10,5 L10,10")';
+ // The first segment of path is (5,5) to (10,5), its length is 5.
+ // The second segment of path is (10,5) to (10,10), its length is 5.
+ // So, the length 8 is on the 2nd segment, at (10,8).
+ const point = target.getPointAtLength(8);
+ assert_equals(point.x, 10, "x-axis position");
+ assert_equals(point.y, 8, "y-axis position");
+}, "getPointAtLength() with d property");
+
+test(function(t) {
+ const target = createPath(t);
+ const svgPoint = document.getElementById("svgroot").createSVGPoint();
+ svgPoint.x = 10;
+ svgPoint.y = 8;
+
+ target.style.d = 'path("M5,5 L10,5 L10,10")';
+ assert_equals(target.isPointInFill(svgPoint), true);
+}, "isPointInFill() with d property");
+
+test(function(t) {
+ const target = createPath(t);
+ const svgPoint = document.getElementById("svgroot").createSVGPoint();
+ svgPoint.x = 10;
+ svgPoint.y = 8;
+
+ target.style.d = 'path("M5,5 L10,5 L10,10")';
+ assert_equals(target.isPointInStroke(svgPoint), true);
+}, "isPointInStroke() with d property");
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/shapes/line-getPointAtLength.svg b/Tests/LibWeb/Text/input/wpt-import/svg/shapes/line-getPointAtLength.svg
new file mode 100644
index 00000000000..c655b21864c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/shapes/line-getPointAtLength.svg
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg"
+ xmlns:h="http://www.w3.org/1999/xhtml">
+ <metadata>
+ <h:link rel="help" href="https://www.w3.org/TR/SVG2/shapes.html#InterfaceSVGLineElement"/>
+ <h:link rel="help" href="https://www.w3.org/TR/SVG2/types.html#InterfaceSVGGeometryElement"/>
+ <h:meta name="assert" content="The line element supports getPointAtLength."/>
+ </metadata>
+ <line id="interval" x1="300" y1="400" x2="500" y2="400"/>
+ <h:script src="../../resources/testharness.js"/>
+ <h:script src="../../resources/testharnessreport.js"/>
+ <script><![CDATA[
+ test(function() {
+ var interval = document.getElementById('interval');
+ assert_not_equals(interval.getTotalLength, undefined, 'getTotalLength is defined for SVGLineElement');
+ assert_not_equals(interval.getPointAtLength, undefined, 'getPointAtLength is defined for SVGLineElement');
+ assert_equals(interval.getTotalLength(), 200, 'total length');
+
+ var point = interval.getPointAtLength(10);
+ assert_equals(point.x, 310, 'x');
+ assert_equals(point.y, 400, 'y');
+ }, 'line supports getPointAtLength');
+
+ test(function() {
+ var interval = document.getElementById('interval');
+ interval.setAttribute('pathLength', '25');
+
+ assert_equals(interval.getTotalLength(), 200, 'total length');
+
+ var point = interval.getPointAtLength(10);
+ assert_equals(point.x, 310, 'x');
+ assert_equals(point.y, 400, 'y');
+ }, 'line getPointAtLength ignores pathLength');
+ ]]></script>
+</svg>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/shapes/scripted/ellipse-auto-radii.svg b/Tests/LibWeb/Text/input/wpt-import/svg/shapes/scripted/ellipse-auto-radii.svg
new file mode 100644
index 00000000000..f7b71895889
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/shapes/scripted/ellipse-auto-radii.svg
@@ -0,0 +1,122 @@
+<svg xmlns="http://www.w3.org/2000/svg"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ viewBox="0 0 200 200">
+ <title>SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods</title>
+ <metadata>
+ <html:link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/shapes.html#EllipseElement"/>
+ <html:link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#InterfaceSVGGeometryElement"/>
+ <html:meta name="assert" content="Per SVG 2 §10.4, an 'auto' value for either rx or ry on an ellipse resolves to the used value of the other property; if both are auto, both used values are 0. This resolution must apply uniformly to every SVGGeometryElement method (getTotalLength, getPointAtLength, isPointInFill, isPointInStroke)."/>
+ </metadata>
+ <html:script src="../../../resources/testharness.js"/>
+ <html:script src="../../../resources/testharnessreport.js"/>
+
+ <ellipse id="auto-rx" cx="50" cy="50" rx="auto" ry="50"/>
+ <ellipse id="auto-ry" cx="50" cy="50" rx="50" ry="auto"/>
+ <ellipse id="auto-both" cx="50" cy="50"/>
+ <ellipse id="explicit" cx="50" cy="50" rx="50" ry="50"/>
+
+ <ellipse id="stroke-auto-rx" cx="100" cy="100" rx="auto" ry="50"
+ stroke="black" stroke-width="4" stroke-dasharray="4 2" fill="none"/>
+ <ellipse id="stroke-auto-ry" cx="100" cy="100" rx="50" ry="auto"
+ stroke="black" stroke-width="4" stroke-dasharray="4 2" fill="none"/>
+ <ellipse id="stroke-explicit" cx="100" cy="100" rx="50" ry="50"
+ stroke="black" stroke-width="4" stroke-dasharray="4 2" fill="none"/>
+
+ <!--
+ Percentage cases. Inner <svg> establishes its own 200x100 viewport so
+ that a percentage on rx resolves against width=200 and a percentage on
+ ry resolves against height=100. With auto on the other axis, the used
+ value of the auto axis equals the resolved (axis-correct) pixel value
+ of the non-auto axis.
+ -->
+ <svg id="pct-viewport" x="0" y="200" width="200" height="100">
+ <ellipse id="pct-auto-rx-50ry" cx="100" cy="50" rx="auto" ry="50%"/>
+ <ellipse id="pct-50rx-auto-ry" cx="100" cy="50" rx="50%" ry="auto"/>
+ <ellipse id="pct-auto-rx-25ry" cx="100" cy="50" rx="auto" ry="25%"/>
+ </svg>
+
+ <script><![CDATA[
+ 'use strict';
+
+ test(function() {
+ const expected = document.getElementById('explicit').getTotalLength();
+ assert_approx_equals(document.getElementById('auto-rx').getTotalLength(),
+ expected, 0.5,
+ 'auto rx should resolve to ry');
+ assert_approx_equals(document.getElementById('auto-ry').getTotalLength(),
+ expected, 0.5,
+ 'auto ry should resolve to rx');
+ }, document.title + ', getTotalLength resolves auto rx/ry.');
+
+ test(function() {
+ assert_equals(document.getElementById('auto-both').getTotalLength(), 0,
+ 'both auto means rendering disabled');
+ }, document.title + ', getTotalLength returns 0 when both rx and ry are auto.');
+
+ test(function() {
+ const expectedPoint = { x: 100, y: 50 };
+ const explicitPt = document.getElementById('explicit').getPointAtLength(0);
+ assert_approx_equals(explicitPt.x, expectedPoint.x, 0.5, 'explicit x');
+ assert_approx_equals(explicitPt.y, expectedPoint.y, 0.5, 'explicit y');
+
+ const autoRxPt = document.getElementById('auto-rx').getPointAtLength(0);
+ assert_approx_equals(autoRxPt.x, expectedPoint.x, 0.5, 'auto-rx x');
+ assert_approx_equals(autoRxPt.y, expectedPoint.y, 0.5, 'auto-rx y');
+
+ const autoRyPt = document.getElementById('auto-ry').getPointAtLength(0);
+ assert_approx_equals(autoRyPt.x, expectedPoint.x, 0.5, 'auto-ry x');
+ assert_approx_equals(autoRyPt.y, expectedPoint.y, 0.5, 'auto-ry y');
+ }, document.title + ', getPointAtLength(0) at the 3 o\'clock starting point.');
+
+ test(function() {
+ const center = { x: 50, y: 50 };
+ const outside = { x: 200, y: 50 };
+ ['auto-rx', 'auto-ry', 'explicit'].forEach(function(id) {
+ const el = document.getElementById(id);
+ assert_true(el.isPointInFill(center),
+ id + ': center is in fill');
+ assert_false(el.isPointInFill(outside),
+ id + ': point outside the resolved ellipse is not in fill');
+ });
+ }, document.title + ', isPointInFill resolves auto rx/ry.');
+
+ test(function() {
+ const onBoundary = { x: 150, y: 100 };
+ assert_true(document.getElementById('stroke-explicit')
+ .isPointInStroke(onBoundary),
+ 'explicit: point on boundary is in stroke');
+ assert_true(document.getElementById('stroke-auto-rx')
+ .isPointInStroke(onBoundary),
+ 'auto-rx: point on boundary is in stroke (auto rx resolves to ry=50)');
+ assert_true(document.getElementById('stroke-auto-ry')
+ .isPointInStroke(onBoundary),
+ 'auto-ry: point on boundary is in stroke (auto ry resolves to rx=50)');
+ }, document.title + ', isPointInStroke with dasharray resolves auto rx/ry.');
+
+ // Inner <svg> viewport is 200x100. Percentages must resolve against the
+ // non-auto axis (a 50% on ry resolves against height=100, not width=200);
+ // the auto axis then takes that resolved pixel value.
+ test(function() {
+ // rx=auto, ry=50% in 200x100 -> ry = 50, rx = 50, perimeter = 2*pi*50.
+ assert_approx_equals(document.getElementById('pct-auto-rx-50ry').getTotalLength(),
+ 2 * Math.PI * 50, 1.0,
+ 'auto rx with ry=50% must resolve via height axis (50), not width axis (100)');
+ // rx=50%, ry=auto in 200x100 -> rx = 100, ry = 100, perimeter = 2*pi*100.
+ assert_approx_equals(document.getElementById('pct-50rx-auto-ry').getTotalLength(),
+ 2 * Math.PI * 100, 1.0,
+ 'auto ry with rx=50% must resolve via width axis (100), not height axis (50)');
+ // rx=auto, ry=25% in 200x100 -> ry = 25, rx = 25, perimeter = 2*pi*25.
+ assert_approx_equals(document.getElementById('pct-auto-rx-25ry').getTotalLength(),
+ 2 * Math.PI * 25, 0.5,
+ 'auto rx with ry=25% must resolve via height axis (25)');
+ }, document.title + ', getTotalLength resolves auto rx/ry against percentage values on the correct axis.');
+
+ test(function() {
+ // Path begins at the 3 o'clock point: (cx + rx, cy).
+ // For rx=auto, ry=50% in 200x100: (100 + 50, 50) = (150, 50).
+ const p = document.getElementById('pct-auto-rx-50ry').getPointAtLength(0);
+ assert_approx_equals(p.x, 150, 0.5, 'auto-rx + ry=50% starting point x');
+ assert_approx_equals(p.y, 50, 0.5, 'auto-rx + ry=50% starting point y');
+ }, document.title + ', getPointAtLength(0) with percentage ry uses height-axis resolution.');
+ ]]></script>
+</svg>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/types/elements/SVGGeometryElement-rect.svg b/Tests/LibWeb/Text/input/wpt-import/svg/types/elements/SVGGeometryElement-rect.svg
new file mode 100644
index 00000000000..a8355d4dd61
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/types/elements/SVGGeometryElement-rect.svg
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg"
+ xmlns:h="http://www.w3.org/1999/xhtml">
+ <metadata>
+ <h:link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/single-page.html#types-InterfaceSVGGeometryElement"/>
+ <h:meta name="assert" content="SVGGeometryElement members work for rect elements."/>
+ </metadata>
+ <style>
+ rect {
+ stroke-width: 10;
+ }
+ </style>
+ <g id="container">
+ <rect id="box" x="50" y="50" width="200" height="100" pathLength="6"/>
+ </g>
+ <h:script src="../../../resources/testharness.js"/>
+ <h:script src="../../../resources/testharnessreport.js"/>
+ <script><![CDATA[
+ var box = document.getElementById('box');
+
+ test(function() {
+ assert_equals(box.pathLength.baseVal, 6);
+
+ assert_equals(box.getTotalLength(), 600);
+
+ assert_equals(box.getPointAtLength(210).x, 250);
+ assert_equals(box.getPointAtLength(210).y, 60);
+ }, 'getTotalLength and getPointAtLength do not take pathLength into account');
+
+ test(function() {
+ assert_true(box.getPointAtLength(210) instanceof SVGPoint);
+ }, 'getPointAtLength() returns instance of SVGPoint');
+
+ test(function() {
+ const container = document.getElementById("container");
+ try {
+ container.style.zoom = 3;
+ assert_equals(box.getTotalLength(), 600);
+
+ assert_equals(box.getPointAtLength(210).x, 250);
+ assert_equals(box.getPointAtLength(210).y, 60);
+ } finally {
+ container.style.zoom = 1;
+ }
+ }, 'getTotalLength and getPointAtLength are not affected by zoom');
+
+ ]]></script>
+</svg>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-01.svg b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-01.svg
new file mode 100644
index 00000000000..42331d13691
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-01.svg
@@ -0,0 +1,44 @@
+<svg xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:html="http://www.w3.org/1999/xhtml">
+ <title>SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length]</title>
+ <metadata>
+ <html:link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#__svg__SVGGeometryElement__getPointAtLength"/>
+ <html:meta name="assert" content="SVGGeometryElement.prototype.getPointAtLength clamps its argument."/>
+ </metadata>
+ <g stroke="blue">
+ <line id="line" x1="50" y1="60" x2="100" y2="60"/>
+ <path id="path" d="M40,70L110,70"/>
+ </g>
+ <html:script src="../../../resources/testharness.js"/>
+ <html:script src="../../../resources/testharnessreport.js"/>
+ <script><![CDATA[
+ test(function() {
+ let line = document.getElementById('line');
+ let point = line.getPointAtLength(-10);
+ assert_equals(point.x, 50, 'starting x');
+ assert_equals(point.y, 60, 'starting y');
+ }, document.title+', less than zero (SVGLineElement).');
+ test(function() {
+ let path = document.getElementById('path');
+ let point = path.getPointAtLength(-10);
+ assert_equals(point.x, 40, 'starting x');
+ assert_equals(point.y, 70, 'starting y');
+ }, document.title+', less than zero (SVGPathElement).');
+
+ test(function() {
+ let line = document.getElementById('line');
+ assert_less_than(line.getTotalLength(), 80);
+ let point = line.getPointAtLength(80);
+ assert_equals(point.x, 100, 'ending x');
+ assert_equals(point.y, 60, 'ending y');
+ }, document.title+', greater than \'length\' (SVGLineElement).');
+ test(function() {
+ let path = document.getElementById('path');
+ assert_less_than(path.getTotalLength(), 80);
+ let point = path.getPointAtLength(80);
+ assert_equals(point.x, 110, 'ending x');
+ assert_equals(point.y, 70, 'ending y');
+ }, document.title+', greater than \'length\' (SVGPathElement).');
+ ]]></script>
+</svg>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-02.svg b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-02.svg
new file mode 100644
index 00000000000..3cc294e477b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-02.svg
@@ -0,0 +1,19 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml">
+ <title>SVGGeometryElement.prototype.getPointAtLength() query with 'pathLength'</title>
+ <h:link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#__svg__SVGGeometryElement__getPointAtLength"/>
+ <path id='pathElement' d='M0,0L100,0L100,100' pathLength="1000"/>
+ <h:script src="../../../resources/testharness.js"/>
+ <h:script src="../../../resources/testharnessreport.js"/>
+ <script>
+test(function() {
+ let path = document.getElementById('pathElement');
+
+ var point = path.getPointAtLength(50);
+ assert_approx_equals(point.x, 50, 1e-5);
+ assert_approx_equals(point.y, 0, 1e-5);
+ var point = path.getPointAtLength(150);
+ assert_approx_equals(point.x, 100, 1e-5);
+ assert_approx_equals(point.y, 50, 1e-5);
+});
+ </script>
+</svg>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-03.svg b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-03.svg
new file mode 100644
index 00000000000..0a1e5fc5a59
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-03.svg
@@ -0,0 +1,41 @@
+<svg xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:html="http://www.w3.org/1999/xhtml">
+ <title>When SVGGeometryElement.getPointAtLength is called with an element that is not in the document, either succeed or throw exception</title>
+ <html:link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#__svg__SVGGeometryElement__getPointAtLength"/>
+ <html:script src="../../../resources/testharness.js"/>
+ <html:script src="../../../resources/testharnessreport.js"/>
+ <script><![CDATA[
+ test(function() {
+ var pathElement = document.createElementNS("http://www.w3.org/2000/svg", "path");
+ assert_throws_dom("InvalidStateError", function() { pathElement.getPointAtLength(700) });
+ }, document.title + " with SVGPathElement");
+
+ test(function() {
+ var rectElement = document.createElementNS("http://www.w3.org/2000/svg", "rect");
+ rectElement.setAttribute("rx", 0);
+ rectElement.setAttribute("ry", 0);
+ rectElement.setAttribute("width", 200);
+ rectElement.setAttribute("height", 300);
+ try {
+ let rectPoint = rectElement.getPointAtLength(300);
+ assert_equals(rectPoint.x, 200, 'unexpected x position');
+ assert_equals(rectPoint.y, 100, 'unexpected y position');
+ } catch (e) {
+ assert_equals(e.name || e.type, 'InvalidStateError', 'Wrong exception, expected InvalidStateError');
+ }
+ }, document.title + " with SVGRectElement");
+
+ test(function() {
+ var circleElement = document.createElementNS("http://www.w3.org/2000/svg", "circle");
+ circleElement.setAttribute("r", 10);
+ try {
+ let circlePoint = circleElement.getPointAtLength(100);
+ assert_approx_equals(circlePoint.x, 10, 0.2, 'unexpected x position');
+ assert_approx_equals(circlePoint.y, 0, 0.2, 'unexpected y position');
+ } catch (e) {
+ assert_equals(e.name || e.type, 'InvalidStateError', 'Wrong exception, expected InvalidStateError');
+ }
+ }, document.title + " with SVGCircleElement");
+ ]]></script>
+</svg>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-04.svg b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-04.svg
new file mode 100644
index 00000000000..f835a122884
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-04.svg
@@ -0,0 +1,80 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml">
+ <title>SVGGeometryElement.getPointAtLength: 'display' and a valid path</title>
+ <h:link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#__svg__SVGGeometryElement__getPointAtLength"/>
+ <h:script src="../../../resources/testharness.js"/>
+ <h:script src="../../../resources/testharnessreport.js"/>
+ <path id='pathElement1' d='M0,0L100,0L100,100' description='path with display: default'/>
+ <path id='pathElement2' style='display:none' d='M0,0L100,0L100,100' description='path with display: none'/>
+ <path id='pathElement3' style='display:none; d:path("M0,0L100,0L100,100");' description='path with display: none and inline style'/>
+ <rect id='rectElement1' x='0' y='0' width='50' height='50' description='rect with display: default'/>
+ <rect id='rectElement2' style='display:none' x='0' y='0' width='50' height='50' description='rect with display: none'/>
+ <circle id='circleElement1' cx='0' cy='0' r='50' description='circle with display: default'/>
+ <circle id='circleElement2' style='display:none' cx='0' cy='0' r='50' description='circle with display: none'/>
+ <polygon id='polygonElement1' points="0,0 50,0 50,50 0,50" description='polygon with display: default'/>
+ <polygon id='polygonElement2' style='display:none' points="0,0 50,0 50,50 0,50" description='polygon with display: none'/>
+ <polyline id='polylineElement1' points="0,0 50,0 50,50 0,50" description='polyline with display: default'/>
+ <polyline id='polylineElement2' style='display:none' points="0,0 50,0 50,50 0,50" description='polyline with display: none'/>
+ <ellipse id='ellipseElement1' cx='0' cy='0' rx='50' ry='50' description='ellipse with display: default'/>
+ <ellipse id='ellipseElement2' style='display:none' cx='0' cy='0' rx='50' ry='50' description='ellipse with display: none'/>
+ <script>
+['pathElement1', 'pathElement2', 'pathElement3'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ var point = element.getPointAtLength(50);
+ assert_approx_equals(point.x, 50, 1e-5);
+ assert_approx_equals(point.y, 0, 1e-5);
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+
+['rectElement1', 'rectElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ var point = element.getPointAtLength(50);
+ assert_approx_equals(point.x, 50, 1e-5);
+ assert_approx_equals(point.y, 0, 1e-5);
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+
+['circleElement1', 'circleElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ var point = element.getPointAtLength(0);
+ assert_approx_equals(point.x, 50, 1e-5);
+ assert_approx_equals(point.y, 0, 1e-5);
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+
+['polygonElement1', 'polygonElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ var point = element.getPointAtLength(50);
+ assert_approx_equals(point.x, 50, 1e-5);
+ assert_approx_equals(point.y, 0, 1e-5);
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+
+['polylineElement1', 'polylineElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ var point = element.getPointAtLength(50);
+ assert_approx_equals(point.x, 50, 1e-5);
+ assert_approx_equals(point.y, 0, 1e-5);
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+
+['ellipseElement1', 'ellipseElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ var point = element.getPointAtLength(0);
+ assert_approx_equals(point.x, 50, 1e-5);
+ assert_approx_equals(point.y, 0, 1e-5);
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+ </script>
+</svg>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-05.svg b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-05.svg
new file mode 100644
index 00000000000..122498f1fbe
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.getPointAtLength-05.svg
@@ -0,0 +1,67 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml">
+ <title>SVGGeometryElement.getPointAtLength: 'display' and empty path</title>
+ <h:link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#__svg__SVGGeometryElement__getPointAtLength"/>
+ <h:script src="../../../resources/testharness.js"/>
+ <h:script src="../../../resources/testharnessreport.js"/>
+ <path id='pathElement1' description='path with display: default and an empty path'/>
+ <path id='pathElement2' style='display:none' description='path with display: none and an empty path'/>
+ <rect id='rectElement1' description='rect with display: default and an empty path'/>
+ <rect id='rectElement2' style='display:none' description='rect with display: none and an empty path'/>
+ <circle id='circleElement1' description='circle with display: default and an empty path'/>
+ <circle id='circleElement2' style='display:none' description='circle with display: none and an empty path'/>
+ <polygon id='polygonElement1' description='polygon with display: default and an empty path'/>
+ <polygon id='polygonElement2' style='display:none' description='polygon with display: none and an empty path'/>
+ <polyline id='polylineElement1' description='polyline with display: default and an empty path'/>
+ <polyline id='polylineElement2' style='display:none' description='polyline with display: none and an empty path'/>
+ <ellipse id='ellipseElement1' description='ellipse with display: default and an empty path'/>
+ <ellipse id='ellipseElement2' style='display:none' description='ellipse with display: none and an empty path'/>
+ <script>
+['pathElement1', 'pathElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ assert_throws_dom("InvalidStateError", function() { element.getPointAtLength(300); });
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+
+['rectElement1', 'rectElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ assert_throws_dom("InvalidStateError", function() { element.getPointAtLength(300); });
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+
+['circleElement1', 'circleElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ assert_throws_dom("InvalidStateError", function() { element.getPointAtLength(300); });
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+
+['polygonElement1', 'polygonElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ assert_throws_dom("InvalidStateError", function() { element.getPointAtLength(300); });
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+
+['polylineElement1', 'polylineElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ assert_throws_dom("InvalidStateError", function() { element.getPointAtLength(300); });
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+
+['ellipseElement1', 'ellipseElement2'].forEach(elementId => {
+ test(function() {
+ let element = document.getElementById(elementId);
+ assert_throws_dom("InvalidStateError", function() { element.getPointAtLength(300); });
+ }, document.title + ', ' +
+ document.getElementById(elementId).getAttribute('description'));
+});
+ </script>
+</svg>