diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/rust/aa-stroke/src | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-upstream/125.0.1.tar.xz firefox-upstream/125.0.1.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/aa-stroke/src')
-rw-r--r-- | third_party/rust/aa-stroke/src/bezierflattener.rs | 40 | ||||
-rw-r--r-- | third_party/rust/aa-stroke/src/lib.rs | 56 |
2 files changed, 48 insertions, 48 deletions
diff --git a/third_party/rust/aa-stroke/src/bezierflattener.rs b/third_party/rust/aa-stroke/src/bezierflattener.rs index 1a615941b6..ab2f96e4a8 100644 --- a/third_party/rust/aa-stroke/src/bezierflattener.rs +++ b/third_party/rust/aa-stroke/src/bezierflattener.rs @@ -16,8 +16,8 @@ pub type HRESULT = i32; pub const S_OK: i32 = 0; #[derive(Clone, Copy, Debug, PartialEq)] pub struct GpPointR { - pub x: f64, - pub y: f64 + pub x: f32, + pub y: f32 } impl Sub for GpPointR { @@ -48,32 +48,32 @@ impl SubAssign for GpPointR { } } -impl MulAssign<f64> for GpPointR { - fn mul_assign(&mut self, rhs: f64) { +impl MulAssign<f32> for GpPointR { + fn mul_assign(&mut self, rhs: f32) { *self = *self * rhs; } } -impl Mul<f64> for GpPointR { +impl Mul<f32> for GpPointR { type Output = Self; - fn mul(self, rhs: f64) -> Self::Output { + fn mul(self, rhs: f32) -> Self::Output { GpPointR { x: self.x * rhs, y: self.y * rhs } } } -impl Div<f64> for GpPointR { +impl Div<f32> for GpPointR { type Output = Self; - fn div(self, rhs: f64) -> Self::Output { + fn div(self, rhs: f32) -> Self::Output { GpPointR { x: self.x / rhs, y: self.y / rhs } } } impl Mul for GpPointR { - type Output = f64; + type Output = f32; fn mul(self, rhs: Self) -> Self::Output { self.x * rhs.x + self.y * rhs.y @@ -81,17 +81,17 @@ impl Mul for GpPointR { } impl GpPointR { - pub fn ApproxNorm(&self) -> f64 { + pub fn ApproxNorm(&self) -> f32 { self.x.abs().max(self.y.abs()) } - pub fn Norm(&self) -> f64 { + pub fn Norm(&self) -> f32 { self.x.hypot(self.y) } } // Relative to this is relative to the tolerance squared. In other words, a vector // whose length is less than .01*tolerance will be considered 0 -const SQ_LENGTH_FUZZ: f64 = 1.0e-4; +const SQ_LENGTH_FUZZ: f32 = 1.0e-4; // Some of these constants need further thinking @@ -103,7 +103,7 @@ const SQ_LENGTH_FUZZ: f64 = 1.0e-4; const FUZZ_DOUBLE: f64 = 1.0e-12; // Double-precision relative 0 const MIN_TOLERANCE: f64 = 1.0e-6; const DEFAULT_FLATTENING_TOLERANCE: f64 = 0.25;*/ -const TWICE_MIN_BEZIER_STEP_SIZE: f64 = 1.0e-3; // The step size in the Bezier flattener should +const TWICE_MIN_BEZIER_STEP_SIZE: f32 = 1.0e-3; // The step size in the Bezier flattener should // never go below half this amount. //+----------------------------------------------------------------------------- // @@ -318,7 +318,7 @@ pub trait CFlatteningSink { fn AcceptPoint(&mut self, pt: &GpPointR, // The point - t: f64, + t: f32, // Parameter we're at fAborted: &mut bool, lastPoint: bool @@ -339,16 +339,16 @@ pub struct CBezierFlattener<'a> bezier: CBezier, // Flattening defining data m_pSink: &'a mut dyn CFlatteningSink, // The recipient of the flattening data - m_rTolerance: f64, // Prescribed tolerance + m_rTolerance: f32, // Prescribed tolerance m_fWithTangents: bool, // Generate tangent vectors if true - m_rQuarterTolerance: f64,// Prescribed tolerance/4 (for doubling the step) - m_rFuzz: f64, // Computational zero + m_rQuarterTolerance: f32,// Prescribed tolerance/4 (for doubling the step) + m_rFuzz: f32, // Computational zero // Flattening working data m_ptE: [GpPointR; 4], // The moving basis of the curve definition m_cSteps: i32, // The number of steps left to the end of the curve - m_rParameter: f64, // Parameter value - m_rStepSize: f64, // Steps size in parameter domain + m_rParameter: f32, // Parameter value + m_rStepSize: f32, // Steps size in parameter domain } impl<'a> CBezierFlattener<'a> { /*fn new( @@ -449,7 +449,7 @@ impl<'a> CBezierFlattener<'a> { pub fn new(bezier: &CBezier, pSink: &'a mut dyn CFlatteningSink, // The reciptient of the flattened data - rTolerance: f64) // Flattening tolerance + rTolerance: f32) // Flattening tolerance -> Self { let mut result = CBezierFlattener { diff --git a/third_party/rust/aa-stroke/src/lib.rs b/third_party/rust/aa-stroke/src/lib.rs index 38c47312ec..92fcf3bf47 100644 --- a/third_party/rust/aa-stroke/src/lib.rs +++ b/third_party/rust/aa-stroke/src/lib.rs @@ -230,8 +230,8 @@ fn arc_segment_tri(path: &mut PathBuilder, xc: f32, yc: f32, radius: f32, a: Vec let h = (4. / 3.) * dot(perp(a), mid2) / dot(a, mid2); - let last_point = GpPointR { x: (xc + r_cos_a) as f64, y: (yc + r_sin_a) as f64 }; - let initial_normal = GpPointR { x: a.x as f64, y: a.y as f64 }; + let last_point = GpPointR { x: (xc + r_cos_a), y: (yc + r_sin_a) }; + let initial_normal = GpPointR { x: a.x, y: a.y }; struct Target<'a, 'b> { last_point: GpPointR, last_normal: GpPointR, xc: f32, yc: f32, path: &'a mut PathBuilder<'b> } @@ -253,24 +253,24 @@ fn arc_segment_tri(path: &mut PathBuilder, xc: f32, yc: f32, radius: f32, a: Vec let width = 0.5; self.path.ramp( - (pt.x - normal.x * width) as f32, - (pt.y - normal.y * width) as f32, - (pt.x + normal.x * width) as f32, - (pt.y + normal.y * width) as f32, - (self.last_point.x + self.last_normal.x * width) as f32, - (self.last_point.y + self.last_normal.y * width) as f32, - (self.last_point.x - self.last_normal.x * width) as f32, - (self.last_point.y - self.last_normal.y * width) as f32, ); + pt.x - normal.x * width, + pt.y - normal.y * width, + pt.x + normal.x * width, + pt.y + normal.y * width, + self.last_point.x + self.last_normal.x * width, + self.last_point.y + self.last_normal.y * width, + self.last_point.x - self.last_normal.x * width, + self.last_point.y - self.last_normal.y * width, ); self.path.push_tri( - (self.last_point.x - self.last_normal.x * 0.5) as f32, - (self.last_point.y - self.last_normal.y * 0.5) as f32, - (pt.x - normal.x * 0.5) as f32, - (pt.y - normal.y * 0.5) as f32, + self.last_point.x - self.last_normal.x * 0.5, + self.last_point.y - self.last_normal.y * 0.5, + pt.x - normal.x * 0.5, + pt.y - normal.y * 0.5, self.xc, self.yc); self.last_normal = normal; } else { - self.path.push_tri(self.last_point.x as f32, self.last_point.y as f32, pt.x as f32, pt.y as f32, self.xc, self.yc); + self.path.push_tri(self.last_point.x, self.last_point.y, pt.x, pt.y, self.xc, self.yc); } self.last_point = pt.clone(); return S_OK; @@ -279,19 +279,19 @@ fn arc_segment_tri(path: &mut PathBuilder, xc: f32, yc: f32, radius: f32, a: Vec fn AcceptPoint(&mut self, pt: &GpPointR, // The point - _t: f64, + _t: f32, // Parameter we're at _aborted: &mut bool, _last_point: bool) -> HRESULT { - self.path.push_tri(self.last_point.x as f32, self.last_point.y as f32, pt.x as f32, pt.y as f32, self.xc, self.yc); + self.path.push_tri(self.last_point.x, self.last_point.y, pt.x, pt.y, self.xc, self.yc); self.last_point = pt.clone(); return S_OK; } } - let bezier = CBezier::new([GpPointR { x: (xc + r_cos_a) as f64, y: (yc + r_sin_a) as f64, }, - GpPointR { x: (xc + r_cos_a - h * r_sin_a) as f64, y: (yc + r_sin_a + h * r_cos_a) as f64, }, - GpPointR { x: (xc + r_cos_b + h * r_sin_b) as f64, y: (yc + r_sin_b - h * r_cos_b) as f64, }, - GpPointR { x: (xc + r_cos_b) as f64, y: (yc + r_sin_b) as f64, }]); + let bezier = CBezier::new([GpPointR { x: (xc + r_cos_a), y: (yc + r_sin_a), }, + GpPointR { x: (xc + r_cos_a - h * r_sin_a), y: (yc + r_sin_a + h * r_cos_a), }, + GpPointR { x: (xc + r_cos_b + h * r_sin_b), y: (yc + r_sin_b - h * r_cos_b), }, + GpPointR { x: (xc + r_cos_b), y: (yc + r_sin_b), }]); if bezier.is_degenerate() { return; } @@ -810,23 +810,23 @@ impl<'z> Stroker<'z> { fn AcceptPoint(&mut self, pt: &GpPointR, // The point - _t: f64, + _t: f32, // Parameter we're at _aborted: &mut bool, last_point: bool) -> HRESULT { if last_point && self.end { - self.stroker.line_to_capped(Point::new(pt.x as f32, pt.y as f32)); + self.stroker.line_to_capped(Point::new(pt.x, pt.y)); } else { - self.stroker.line_to(Point::new(pt.x as f32, pt.y as f32)); + self.stroker.line_to(Point::new(pt.x, pt.y)); } return S_OK; } } let cur_pt = self.cur_pt.unwrap_or(cx1); - let bezier = CBezier::new([GpPointR { x: cur_pt.x as f64, y: cur_pt.y as f64, }, - GpPointR { x: cx1.x as f64, y: cx1.y as f64, }, - GpPointR { x: cx2.x as f64, y: cx2.y as f64, }, - GpPointR { x: pt.x as f64, y: pt.y as f64, }]); + let bezier = CBezier::new([GpPointR { x: cur_pt.x, y: cur_pt.y, }, + GpPointR { x: cx1.x, y: cx1.y, }, + GpPointR { x: cx2.x, y: cx2.y, }, + GpPointR { x: pt.x, y: pt.y, }]); let mut t = Target{ stroker: self, end }; let mut f = CBezierFlattener::new(&bezier, &mut t, 0.25); f.Flatten(false); |