mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Use NaN-safe comparisons in DOMQuad::GetBounds (#33794)
* Use nan-safe comparison in DOMQuad::GetBounds This fixes at least the following WPT test: * css/geometry/DOMQuad-nan.html Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Update WPT expectations Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
f15da16da4
commit
fc2c77be83
3 changed files with 52 additions and 54 deletions
|
@ -16,7 +16,7 @@ use crate::dom::domrect::DOMRect;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::script_runtime::CanGc;
|
use crate::script_runtime::CanGc;
|
||||||
|
|
||||||
// https://drafts.fxtf.org/geometry/#DOMQuad
|
/// <https://drafts.fxtf.org/geometry/#DOMQuad>
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct DOMQuad {
|
pub struct DOMQuad {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
@ -137,31 +137,58 @@ impl DOMQuadMethods for DOMQuad {
|
||||||
|
|
||||||
// https://drafts.fxtf.org/geometry/#dom-domquad-getbounds
|
// https://drafts.fxtf.org/geometry/#dom-domquad-getbounds
|
||||||
fn GetBounds(&self) -> DomRoot<DOMRect> {
|
fn GetBounds(&self) -> DomRoot<DOMRect> {
|
||||||
let left = self
|
// https://drafts.fxtf.org/geometry/#nan-safe-minimum
|
||||||
.p1
|
let nan_safe_minimum = |a: f64, b: f64| {
|
||||||
.X()
|
if a.is_nan() || b.is_nan() {
|
||||||
.min(self.p2.X())
|
f64::NAN
|
||||||
.min(self.p3.X())
|
} else {
|
||||||
.min(self.p4.X());
|
a.min(b)
|
||||||
let top = self
|
}
|
||||||
.p1
|
};
|
||||||
.Y()
|
|
||||||
.min(self.p2.Y())
|
|
||||||
.min(self.p3.Y())
|
|
||||||
.min(self.p4.Y());
|
|
||||||
let right = self
|
|
||||||
.p1
|
|
||||||
.X()
|
|
||||||
.max(self.p2.X())
|
|
||||||
.max(self.p3.X())
|
|
||||||
.max(self.p4.X());
|
|
||||||
let bottom = self
|
|
||||||
.p1
|
|
||||||
.Y()
|
|
||||||
.max(self.p2.Y())
|
|
||||||
.max(self.p3.Y())
|
|
||||||
.max(self.p4.Y());
|
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#nan-safe-maximum
|
||||||
|
let nan_safe_maximum = |a: f64, b: f64| {
|
||||||
|
if a.is_nan() || b.is_nan() {
|
||||||
|
f64::NAN
|
||||||
|
} else {
|
||||||
|
a.max(b)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Step 1. Let bounds be a DOMRect object.
|
||||||
|
// NOTE: We construct the object at the end
|
||||||
|
|
||||||
|
// Step 2. Let left be the NaN-safe minimum of point 1’s x coordinate,
|
||||||
|
// point 2’s x coordinate, point 3’s x coordinate and point 4’s x coordinate.
|
||||||
|
let left = nan_safe_minimum(
|
||||||
|
nan_safe_minimum(self.p1.X(), self.p2.X()),
|
||||||
|
nan_safe_minimum(self.p3.X(), self.p4.X()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Step 3. Let top be the NaN-safe minimum of point 1’s y coordinate,
|
||||||
|
// point 2’s y coordinate, point 3’s y coordinate and point 4’s y coordinate.
|
||||||
|
let top = nan_safe_minimum(
|
||||||
|
nan_safe_minimum(self.p1.Y(), self.p2.Y()),
|
||||||
|
nan_safe_minimum(self.p3.Y(), self.p4.Y()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Step 4. Let right be the NaN-safe maximum of point 1’s x coordinate,
|
||||||
|
// point 2’s x coordinate, point 3’s x coordinate and point 4’s x coordinate.
|
||||||
|
let right = nan_safe_maximum(
|
||||||
|
nan_safe_maximum(self.p1.X(), self.p2.X()),
|
||||||
|
nan_safe_maximum(self.p3.X(), self.p4.X()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Step 5. Let bottom be the NaN-safe maximum of point 1’s y coordinate,
|
||||||
|
// point 2’s y coordinate, point 3’s y coordinate and point 4’s y coordinate.
|
||||||
|
let bottom = nan_safe_maximum(
|
||||||
|
nan_safe_maximum(self.p1.Y(), self.p2.Y()),
|
||||||
|
nan_safe_maximum(self.p3.Y(), self.p4.Y()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Step 6. Set x coordinate of bounds to left, y coordinate of bounds to top,
|
||||||
|
// width dimension of bounds to right - left and height dimension of bounds to bottom - top.
|
||||||
|
// NOTE: Combined with Step 1.
|
||||||
DOMRect::new(
|
DOMRect::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
left,
|
left,
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
[DOMQuad-001.html]
|
|
||||||
[fromRect() method on DOMQuad with Infinity: bounds]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
25
tests/wpt/meta/css/geometry/DOMQuad-nan.html.ini
vendored
25
tests/wpt/meta/css/geometry/DOMQuad-nan.html.ini
vendored
|
@ -1,25 +0,0 @@
|
||||||
[DOMQuad-nan.html]
|
|
||||||
[Setting DOMQuad's p1.x to NaN]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Setting DOMQuad's p2.y to NaN]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Setting DOMQuad's p2.x to NaN]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Setting DOMQuad's p4.x to NaN]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Setting DOMQuad's p3.x to NaN]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Setting DOMQuad's p3.y to NaN]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Setting DOMQuad's p4.y to NaN]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Setting DOMQuad's p1.y to NaN]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue