Path Bool library code cleanup (#2000)

* Remove log statements

* Add feature gates to functions in path.rs

* Fix infinite parsing loop and add new test

* License tweaks

* Remove trailing zero in whole number floats

* Flatten visual-tests directory

* Code review

* Clean up printlines

* Add error handling to path parsing

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Dennis Kobert 2024-09-23 12:16:31 +02:00 committed by GitHub
parent 3ddc052538
commit 8a1089938e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
175 changed files with 442 additions and 346 deletions

View file

@ -49,7 +49,7 @@ fn add_network() -> NodeNetwork {
if _global_index.x < i2[2] {{
i0[_global_index.x as usize]
}} else {{
Color::from_rgbaf32_unchecked(0.0, 0.0, 0.0, 0.0)
Color::from_rgbaf32_unchecked(0., 0., 0., 0.)
}},
))"#,
TaggedValue::BlendMode(BlendMode::Normal).to_primitive_string(),

View file

@ -355,7 +355,7 @@ impl Color {
/// let color = Color::from_rgbaf32(0.3, 0.14, 0.15, 0.92).unwrap();
/// assert!(color.components() == (0.3, 0.14, 0.15, 0.92));
///
/// let color = Color::from_rgbaf32(1.0, 1.0, 1.0, f32::NAN);
/// let color = Color::from_rgbaf32(1., 1., 1., f32::NAN);
/// assert!(color == None);
/// ```
#[inline(always)]

View file

@ -56,16 +56,16 @@ const FLOAT_SRGB_LERP: [u32; 27] = [
#[inline]
pub fn float_to_srgb_u8(mut f: f32) -> u8 {
// Clamp f to [0, 1], with a negated condition to handle NaNs as 0.
if !(f >= 0.0) {
f = 0.0;
} else if f > 1.0 {
f = 1.0;
if !(f >= 0.) {
f = 0.;
} else if f > 1. {
f = 1.;
}
// Shift away slightly from 0.0 to reduce exponent range.
const C: f32 = 0.009842521f32;
let u = (f + C).to_bits() - C.to_bits();
if u > (1.0 + C).to_bits() - C.to_bits() {
if u > (1. + C).to_bits() - C.to_bits() {
// We clamped f to [0, 1], and the integer representations
// of the positive finite non-NaN floats are monotonic.
// This makes the later LUT lookup panicless.
@ -144,7 +144,7 @@ mod tests {
} else if f <= 0.0031308f32 {
12.92_f32 * f
} else if f < 1_f32 {
1.055f32 * f.powf(1.0_f32 / 2.4_f32) - 0.055f32
1.055f32 * f.powf(1_f32 / 2.4_f32) - 0.055f32
} else {
1_f32
}
@ -164,7 +164,7 @@ mod tests {
}
fn srgb_u8_to_float_ref(c: u8) -> f32 {
srgb_to_float_ref(c as f32 * (1_f32 / 255.0_f32))
srgb_to_float_ref(c as f32 * (1_f32 / 255_f32))
}
#[test]

View file

@ -239,7 +239,7 @@ fn brush(_footprint: Footprint, image: ImageFrame<Color>, bounds: ImageFrame<Col
// For numerical stability we want to place the first blit point at a stable, integer offset
// in layer space.
let snap_offset = positions[0].floor() - positions[0];
let stroke_origin_in_layer = bbox.start - snap_offset - DVec2::splat(stroke.style.diameter / 2.0);
let stroke_origin_in_layer = bbox.start - snap_offset - DVec2::splat(stroke.style.diameter / 2.);
let stroke_to_layer = DAffine2::from_translation(stroke_origin_in_layer) * DAffine2::from_scale(stroke_size);
let normal_blend = BlendColorPairNode::new(CopiedNode::new(BlendMode::Normal), CopiedNode::new(100.));
@ -297,7 +297,7 @@ fn brush(_footprint: Footprint, image: ImageFrame<Color>, bounds: ImageFrame<Col
}
}
let blend_params = BlendColorPairNode::new(CopiedNode::new(BlendMode::MultiplyAlpha), CopiedNode::new(100.0));
let blend_params = BlendColorPairNode::new(CopiedNode::new(BlendMode::MultiplyAlpha), CopiedNode::new(100.));
let blend_executor = BlendImageTupleNode::new(ValueNode::new(blend_params));
actual_image = blend_executor.eval((actual_image, erase_restore_mask));
}

View file

@ -295,7 +295,7 @@ async fn blend_gpu_image(_: (), foreground: ImageFrame<Color>, background: Image
let fg_point = (*i4) * bg_point + (*i5);
if !((fg_point.cmpge(Vec2::ZERO) & bg_point.cmpge(Vec2::ZERO)) == BVec2::new(true, true)) {{
Color::from_rgbaf32_unchecked(0.0, 0.0, 0.0, 0.0)
Color::from_rgbaf32_unchecked(0., 0., 0., 0.)
}} else {{
i2[((fg_point.y as u32) * i3 + (fg_point.x as u32)) as usize]
}}

View file

@ -22,8 +22,8 @@ async fn image_color_palette<F: 'n + Send>(
let bins = GRID * GRID * GRID;
let mut histogram: Vec<usize> = vec![0; (bins + 1.0) as usize];
let mut colors: Vec<Vec<Color>> = vec![vec![]; (bins + 1.0) as usize];
let mut histogram: Vec<usize> = vec![0; (bins + 1.) as usize];
let mut colors: Vec<Vec<Color>> = vec![vec![]; (bins + 1.) as usize];
let image = image.eval(footprint).await;
for pixel in image.image.data.iter() {
@ -44,10 +44,10 @@ async fn image_color_palette<F: 'n + Send>(
for i in shorted.iter().take(max_size as usize) {
let list = colors[*i].clone();
let mut r = 0.0;
let mut g = 0.0;
let mut b = 0.0;
let mut a = 0.0;
let mut r = 0.;
let mut g = 0.;
let mut b = 0.;
let mut a = 0.;
for color in list.iter() {
r += color.r();
@ -86,7 +86,7 @@ mod test {
image: Image {
width: 100,
height: 100,
data: vec![Color::from_rgbaf32(0.0, 0.0, 0.0, 1.0).unwrap(); 10000],
data: vec![Color::from_rgbaf32(0., 0., 0., 1.).unwrap(); 10000],
base64_string: None,
},
..Default::default()
@ -94,6 +94,6 @@ mod test {
})
}),
};
assert_eq!(futures::executor::block_on(node.eval(())), [Color::from_rgbaf32(0.0, 0.0, 0.0, 1.0).unwrap()]);
assert_eq!(futures::executor::block_on(node.eval(())), [Color::from_rgbaf32(0., 0., 0., 1.).unwrap()]);
}
}

View file

@ -517,10 +517,10 @@ pub fn pick_safe_imaginate_resolution((width, height): (f64, f64)) -> (u64, u64)
let scale = (MAX_RESOLUTION as f64 / resolution as f64).sqrt();
let size = size.as_dvec2() * scale;
if size.x < 64.0 {
if size.x < 64. {
// The image is extremely wide
(64, MAX_DIMENSION)
} else if size.y < 64.0 {
} else if size.y < 64. {
// The image is extremely high
(MAX_DIMENSION, 64)
} else {

View file

@ -309,7 +309,7 @@ fn extend_image_to_bounds(image: ImageFrame<Color>, bounds: DAffine2) -> ImageFr
// Compute new transform.
// let layer_to_new_texture_space = (DAffine2::from_scale(1. / new_scale) * DAffine2::from_translation(new_start) * layer_to_image_space).inverse();
let new_texture_to_layer_space = image.transform * DAffine2::from_scale(1.0 / orig_image_scale) * DAffine2::from_translation(new_start) * DAffine2::from_scale(new_scale);
let new_texture_to_layer_space = image.transform * DAffine2::from_scale(1. / orig_image_scale) * DAffine2::from_translation(new_start) * DAffine2::from_scale(new_scale);
ImageFrame {
image: new_img,
transform: new_texture_to_layer_space,
@ -641,10 +641,10 @@ fn mandelbrot(footprint: Footprint) -> ImageFrame<Color> {
#[inline(always)]
fn mandelbrot_impl(c: Vec2, max_iter: usize) -> usize {
let mut z = Vec2::new(0.0, 0.0);
let mut z = Vec2::new(0., 0.);
for i in 0..max_iter {
z = Vec2::new(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
if z.length_squared() > 4.0 {
z = Vec2::new(z.x * z.x - z.y * z.y, 2. * z.x * z.y) + c;
if z.length_squared() > 4. {
return i;
}
}

View file

@ -45,7 +45,7 @@ async fn draw_image_frame(_: (), image: ImageFrame<graphene_core::raster::SRGBA8
// TODO: replace "2d" with "bitmaprenderer" once we switch to ImageBitmap (lives on gpu) from ImageData (lives on cpu)
let context = canvas.get_context("2d").unwrap().unwrap().dyn_into::<CanvasRenderingContext2d>().unwrap();
let image_data = web_sys::ImageData::new_with_u8_clamped_array_and_sh(array, image.image.width, image.image.height).expect("Failed to construct ImageData");
context.put_image_data(&image_data, 0.0, 0.0).unwrap();
context.put_image_data(&image_data, 0., 0.).unwrap();
}
graphene_core::application_io::SurfaceHandleFrame {
surface_handle,

View file

@ -86,19 +86,19 @@ impl Vertex {
const VERTICES: &[Vertex] = &[
Vertex {
position: [-1., 1., 0.0],
position: [-1., 1., 0.],
tex_coords: [0., 0.],
}, // A
Vertex {
position: [-1., -1., 0.0],
position: [-1., -1., 0.],
tex_coords: [0., 1.],
}, // B
Vertex {
position: [1., 1., 0.0],
position: [1., 1., 0.],
tex_coords: [1., 0.],
}, // C
Vertex {
position: [1., -1., 0.0],
position: [1., -1., 0.],
tex_coords: [1., 1.],
}, // D
];