Bug 1843143 - Update aa-stroke to improve handling of round joins. r=lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D183415
This commit is contained in:
Jeff Muizelaar 2023-07-13 11:44:29 +00:00
Родитель 6ca892ce83
Коммит 70883a5bcd
6 изменённых файлов: 39 добавлений и 13 удалений

Просмотреть файл

@ -5,9 +5,9 @@
[source.crates-io]
replace-with = "vendored-sources"
[source."git+https://github.com/FirefoxGraphics/aa-stroke?rev=07d3c25322518f294300e96246e09b95e118555d"]
[source."git+https://github.com/FirefoxGraphics/aa-stroke?rev=cfe9ee39f5af56ae26004835d90c4bb2973ce519"]
git = "https://github.com/FirefoxGraphics/aa-stroke"
rev = "07d3c25322518f294300e96246e09b95e118555d"
rev = "cfe9ee39f5af56ae26004835d90c4bb2973ce519"
replace-with = "vendored-sources"
[source."git+https://github.com/FirefoxGraphics/wpf-gpu-raster?rev=5ab6fe33d00021325ee920b3c10526dc8301cf46"]

2
Cargo.lock сгенерированный
Просмотреть файл

@ -5,7 +5,7 @@ version = 3
[[package]]
name = "aa-stroke"
version = "0.1.0"
source = "git+https://github.com/FirefoxGraphics/aa-stroke?rev=07d3c25322518f294300e96246e09b95e118555d#07d3c25322518f294300e96246e09b95e118555d"
source = "git+https://github.com/FirefoxGraphics/aa-stroke?rev=cfe9ee39f5af56ae26004835d90c4bb2973ce519#cfe9ee39f5af56ae26004835d90c4bb2973ce519"
dependencies = [
"euclid",
]

Просмотреть файл

@ -1 +1 @@
{"files":{".github/workflows/rust.yml":"e859b12cfed145b66e4fbf1571dde15880359717ca5b0a9720341229183f2c6f","Cargo.toml":"f507cac11c3c26af28420d68ec3748a5453322d51ef1379a340fdd3b1c9b187a","README.md":"60b34cfa653114d5054009696df2ed2ea1d4926a6bc312d0cac4b84845c2beff","examples/simple.rs":"c196e79568fe4be31a08374aa451c70c9377db5428aef924a985e069c12ed91e","src/bezierflattener.rs":"4268d18ef80899d4b5d1fdbb0ed23fb4a4f9a6197b0796cb7a5e55194437a67b","src/c_bindings.rs":"23890f7bb5d40d87d72b28842821ada7b2e1509a3b37c9af8ed0055036ceadcc","src/lib.rs":"fb46f09d8ed2a53d4a6770a6f1bb2ff1a9df736c5c6d390ba159fefafbeec308","src/tri_rasterize.rs":"fb6f595ab9340d8ea6429b41638c378bbd772c8e4d8f7793e225624c12cd3a21"},"package":null}
{"files":{".github/workflows/rust.yml":"e859b12cfed145b66e4fbf1571dde15880359717ca5b0a9720341229183f2c6f","Cargo.toml":"f507cac11c3c26af28420d68ec3748a5453322d51ef1379a340fdd3b1c9b187a","README.md":"60b34cfa653114d5054009696df2ed2ea1d4926a6bc312d0cac4b84845c2beff","examples/simple.rs":"c196e79568fe4be31a08374aa451c70c9377db5428aef924a985e069c12ed91e","src/bezierflattener.rs":"61687da22490cb1bd901d0b5eb1de3a98802b46c03719ded4163c7a4997f0ad9","src/c_bindings.rs":"23890f7bb5d40d87d72b28842821ada7b2e1509a3b37c9af8ed0055036ceadcc","src/lib.rs":"21d02fdcc8491a03b19ec90dfeae05fb569f73500cf1bb89ba71d6e838dc0b0d","src/tri_rasterize.rs":"fb6f595ab9340d8ea6429b41638c378bbd772c8e4d8f7793e225624c12cd3a21"},"package":null}

Просмотреть файл

@ -826,3 +826,5 @@ fn GetLastTangent(&self) -> GpPointR
return vecTangent;
}
}

40
third_party/rust/aa-stroke/src/lib.rs поставляемый
Просмотреть файл

@ -75,9 +75,9 @@ impl Default for StrokeStyle {
}
#[derive(Debug)]
pub struct Vertex {
x: f32,
y: f32,
coverage: f32
pub x: f32,
pub y: f32,
pub coverage: f32
}
/// A helper struct used for constructing a `Path`.
@ -323,13 +323,22 @@ fn bisect(a: Vector, b: Vector) -> Vector {
return mid / len;
}
/* The angle between the vectors must be <= 180 degrees */
fn arc(path: &mut PathBuilder, xc: f32, yc: f32, radius: f32, a: Vector, b: Vector) {
/* find a vector that bisects the angle between a and b */
let mid_v = bisect(a, b);
// Depending on the magnitude of the angle use 0, 1 or 2 arc segments.
if dot(a, b) == 1.0 {
// the angle is 0 degrees, do nothing
} else if dot(a, b) >= 0. {
// the angle is less than 90 degrees
arc_segment_tri(path, xc, yc, radius, a, b);
} else {
/* find a vector that bisects the angle between a and b */
let mid_v = bisect(a, b);
/* construct the arc using two curve segments */
arc_segment_tri(path, xc, yc, radius, a, mid_v);
arc_segment_tri(path, xc, yc, radius, mid_v, b);
/* construct the arc using two curve segments */
arc_segment_tri(path, xc, yc, radius, a, mid_v);
arc_segment_tri(path, xc, yc, radius, mid_v, b);
}
}
/*
@ -423,6 +432,8 @@ fn cap_line(dest: &mut PathBuilder, style: &StrokeStyle, pt: Point, normal: Vect
end.x + normal.x * (half_width - 0.5),
end.y + normal.y * (half_width - 0.5),
);
// corners
dest.tri_ramp(
end.x + v.x - normal.x * (half_width - 0.5),
end.y + v.y - normal.y * (half_width - 0.5),
@ -891,6 +902,19 @@ fn width_one_radius_arc() {
stroker.finish();
}
#[test]
fn round_join_less_than_90deg() {
let mut stroker = Stroker::new(&StrokeStyle{
cap: LineCap::Round,
join: LineJoin::Round,
width: 1.,
..Default::default()});
stroker.move_to(Point::new(20., 20.), false);
stroker.line_to(Point::new(20., 40.));
stroker.line_to_capped(Point::new(30., 50.));
assert_eq!(stroker.finish().len(), 81);
}
#[test]
fn parallel_line_join() {
// ensure line joins of almost parallel lines don't cause math to fail

Просмотреть файл

@ -95,7 +95,7 @@ processtools = { path = "../../../components/processtools" }
qcms = { path = "../../../../gfx/qcms", features = ["c_bindings", "neon"], default-features = false }
wpf-gpu-raster = { git = "https://github.com/FirefoxGraphics/wpf-gpu-raster", rev = "5ab6fe33d00021325ee920b3c10526dc8301cf46" }
aa-stroke = { git = "https://github.com/FirefoxGraphics/aa-stroke", rev = "07d3c25322518f294300e96246e09b95e118555d" }
aa-stroke = { git = "https://github.com/FirefoxGraphics/aa-stroke", rev = "cfe9ee39f5af56ae26004835d90c4bb2973ce519" }
# Force url to stay at 2.1.0. See bug 1734538.
url = "=2.1.0"