From e1bcc11ace29965162cfd8ccf9c4e9ada5be0ecd Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 29 May 2019 19:13:42 -0700 Subject: [PATCH] Change the `F32` and `I32` suffixes to `F` and `I` to match the C API. They're shorter and less noisy. --- c/src/lib.rs | 20 +-- canvas/src/lib.rs | 44 +++--- demo/android/rust/src/lib.rs | 24 +-- demo/common/src/camera.rs | 50 +++---- demo/common/src/lib.rs | 34 ++--- demo/common/src/renderer.rs | 8 +- demo/common/src/ui.rs | 112 +++++++------- demo/common/src/window.rs | 22 +-- demo/native/src/main.rs | 16 +- examples/canvas_minimal/src/main.rs | 16 +- examples/canvas_moire/src/main.rs | 18 +-- examples/canvas_text/src/main.rs | 8 +- geometry/src/basic/line_segment.rs | 78 +++++----- geometry/src/basic/point.rs | 200 ++++++++++++------------- geometry/src/basic/rect.rs | 108 ++++++------- geometry/src/basic/transform2d.rs | 176 +++++++++++----------- geometry/src/basic/transform3d.rs | 156 +++++++++---------- geometry/src/clip.rs | 44 +++--- geometry/src/dilation.rs | 12 +- geometry/src/outline.rs | 112 +++++++------- geometry/src/segment.rs | 56 +++---- geometry/src/stroke.rs | 60 ++++---- geometry/src/unit_vector.rs | 12 +- gl/src/lib.rs | 18 +-- gpu/src/lib.rs | 24 +-- renderer/src/builder.rs | 44 +++--- renderer/src/concurrent/scene_proxy.rs | 6 +- renderer/src/gpu/debug.rs | 34 ++--- renderer/src/gpu/renderer.rs | 36 ++--- renderer/src/gpu_data.rs | 8 +- renderer/src/options.rs | 28 ++-- renderer/src/paint.rs | 10 +- renderer/src/scene.rs | 30 ++-- renderer/src/tile_map.rs | 18 +-- renderer/src/tiles.rs | 38 ++--- renderer/src/z_buffer.rs | 12 +- simd/src/x86/mod.rs | 2 +- svg/src/lib.rs | 52 +++---- text/src/lib.rs | 30 ++-- ui/src/lib.rs | 126 ++++++++-------- 40 files changed, 951 insertions(+), 951 deletions(-) diff --git a/c/src/lib.rs b/c/src/lib.rs index 72475994..c529ba58 100644 --- a/c/src/lib.rs +++ b/c/src/lib.rs @@ -12,8 +12,8 @@ use gl; use pathfinder_canvas::{CanvasRenderingContext2D, Path2D}; -use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; -use pathfinder_geometry::basic::rect::{RectF32, RectI32}; +use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::rect::{RectF, RectI}; use pathfinder_geometry::color::ColorF; use pathfinder_gl::{GLDevice, GLVersion}; use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader}; @@ -296,29 +296,29 @@ impl PFColorF { impl PFRectF { #[inline] - pub fn to_rust(&self) -> RectF32 { - RectF32::from_points(self.origin.to_rust(), self.lower_right.to_rust()) + pub fn to_rust(&self) -> RectF { + RectF::from_points(self.origin.to_rust(), self.lower_right.to_rust()) } } impl PFRectI { #[inline] - pub fn to_rust(&self) -> RectI32 { - RectI32::from_points(self.origin.to_rust(), self.lower_right.to_rust()) + pub fn to_rust(&self) -> RectI { + RectI::from_points(self.origin.to_rust(), self.lower_right.to_rust()) } } impl PFPoint2DF { #[inline] - pub fn to_rust(&self) -> Point2DF32 { - Point2DF32::new(self.x, self.y) + pub fn to_rust(&self) -> Point2DF { + Point2DF::new(self.x, self.y) } } impl PFPoint2DI { #[inline] - pub fn to_rust(&self) -> Point2DI32 { - Point2DI32::new(self.x, self.y) + pub fn to_rust(&self) -> Point2DI { + Point2DI::new(self.x, self.y) } } diff --git a/canvas/src/lib.rs b/canvas/src/lib.rs index 123dc100..2c0e25a0 100644 --- a/canvas/src/lib.rs +++ b/canvas/src/lib.rs @@ -14,9 +14,9 @@ use font_kit::family_name::FamilyName; use font_kit::hinting::HintingOptions; use font_kit::properties::Properties; use font_kit::source::SystemSource; -use pathfinder_geometry::basic::point::Point2DF32; -use pathfinder_geometry::basic::rect::RectF32; -use pathfinder_geometry::basic::transform2d::Transform2DF32; +use pathfinder_geometry::basic::point::Point2DF; +use pathfinder_geometry::basic::rect::RectF; +use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::color::ColorU; use pathfinder_geometry::outline::{Contour, Outline}; use pathfinder_geometry::stroke::{LineCap, LineJoin, OutlineStrokeToFill, StrokeStyle}; @@ -44,9 +44,9 @@ pub struct CanvasRenderingContext2D { impl CanvasRenderingContext2D { #[inline] - pub fn new(size: Point2DF32) -> CanvasRenderingContext2D { + pub fn new(size: Point2DF) -> CanvasRenderingContext2D { let mut scene = Scene::new(); - scene.set_view_box(RectF32::new(Point2DF32::default(), size)); + scene.set_view_box(RectF::new(Point2DF::default(), size)); CanvasRenderingContext2D::from_scene(scene) } @@ -79,23 +79,23 @@ impl CanvasRenderingContext2D { } #[inline] - pub fn fill_rect(&mut self, rect: RectF32) { + pub fn fill_rect(&mut self, rect: RectF) { let mut path = Path2D::new(); path.rect(rect); self.fill_path(path); } #[inline] - pub fn stroke_rect(&mut self, rect: RectF32) { + pub fn stroke_rect(&mut self, rect: RectF) { let mut path = Path2D::new(); path.rect(rect); self.stroke_path(path); } - pub fn fill_text(&mut self, string: &str, position: Point2DF32) { + pub fn fill_text(&mut self, string: &str, position: Point2DF) { // TODO(pcwalton): Report errors. let paint_id = self.scene.push_paint(&self.current_state.fill_paint); - let transform = Transform2DF32::from_translation(position).post_mul(&self.current_state + let transform = Transform2DF::from_translation(position).post_mul(&self.current_state .transform); drop(self.scene.push_text(string, &TextStyle { size: self.current_state.font_size }, @@ -106,10 +106,10 @@ impl CanvasRenderingContext2D { paint_id)); } - pub fn stroke_text(&mut self, string: &str, position: Point2DF32) { + pub fn stroke_text(&mut self, string: &str, position: Point2DF) { // TODO(pcwalton): Report errors. let paint_id = self.scene.push_paint(&self.current_state.stroke_paint); - let transform = Transform2DF32::from_translation(position).post_mul(&self.current_state + let transform = Transform2DF::from_translation(position).post_mul(&self.current_state .transform); drop(self.scene.push_text(string, &TextStyle { size: self.current_state.font_size }, @@ -186,18 +186,18 @@ impl CanvasRenderingContext2D { // Transformations #[inline] - pub fn current_transform(&self) -> Transform2DF32 { + pub fn current_transform(&self) -> Transform2DF { self.current_state.transform } #[inline] - pub fn set_current_transform(&mut self, new_transform: &Transform2DF32) { + pub fn set_current_transform(&mut self, new_transform: &Transform2DF) { self.current_state.transform = *new_transform; } #[inline] pub fn reset_transform(&mut self) { - self.current_state.transform = Transform2DF32::default(); + self.current_state.transform = Transform2DF::default(); } // Compositing @@ -229,7 +229,7 @@ impl CanvasRenderingContext2D { #[derive(Clone)] pub struct State { - transform: Transform2DF32, + transform: Transform2DF, font_collection: Arc, font_size: f32, fill_paint: Paint, @@ -241,7 +241,7 @@ pub struct State { impl State { fn default(default_font_collection: Arc) -> State { State { - transform: Transform2DF32::default(), + transform: Transform2DF::default(), font_collection: default_font_collection, font_size: DEFAULT_FONT_SIZE, fill_paint: Paint { color: ColorU::black() }, @@ -276,33 +276,33 @@ impl Path2D { } #[inline] - pub fn move_to(&mut self, to: Point2DF32) { + pub fn move_to(&mut self, to: Point2DF) { // TODO(pcwalton): Cull degenerate contours. self.flush_current_contour(); self.current_contour.push_endpoint(to); } #[inline] - pub fn line_to(&mut self, to: Point2DF32) { + pub fn line_to(&mut self, to: Point2DF) { self.current_contour.push_endpoint(to); } #[inline] - pub fn quadratic_curve_to(&mut self, ctrl: Point2DF32, to: Point2DF32) { + pub fn quadratic_curve_to(&mut self, ctrl: Point2DF, to: Point2DF) { self.current_contour.push_quadratic(ctrl, to); } #[inline] - pub fn bezier_curve_to(&mut self, ctrl0: Point2DF32, ctrl1: Point2DF32, to: Point2DF32) { + pub fn bezier_curve_to(&mut self, ctrl0: Point2DF, ctrl1: Point2DF, to: Point2DF) { self.current_contour.push_cubic(ctrl0, ctrl1, to); } #[inline] - pub fn arc(&mut self, center: Point2DF32, radius: f32, start_angle: f32, end_angle: f32) { + pub fn arc(&mut self, center: Point2DF, radius: f32, start_angle: f32, end_angle: f32) { self.current_contour.push_arc(center, radius, start_angle, end_angle); } - pub fn rect(&mut self, rect: RectF32) { + pub fn rect(&mut self, rect: RectF) { self.flush_current_contour(); self.current_contour.push_endpoint(rect.origin()); self.current_contour.push_endpoint(rect.upper_right()); diff --git a/demo/android/rust/src/lib.rs b/demo/android/rust/src/lib.rs index f0667ae4..7dadd259 100644 --- a/demo/android/rust/src/lib.rs +++ b/demo/android/rust/src/lib.rs @@ -16,8 +16,8 @@ use jni::{JNIEnv, JavaVM}; use pathfinder_demo::window::{Event, SVGPath, View, Window, WindowSize}; use pathfinder_demo::DemoApp; use pathfinder_demo::Options; -use pathfinder_geometry::basic::point::Point2DI32; -use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::rect::RectI; use pathfinder_gl::GLVersion; use pathfinder_gpu::resources::ResourceLoader; use std::cell::RefCell; @@ -48,7 +48,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder width: i32, height: i32, ) { - let logical_size = Point2DI32::new(width, height); + let logical_size = Point2DI::new(width, height); let window_size = WindowSize { logical_size, backing_scale_factor: 1.0, @@ -119,7 +119,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder .lock() .unwrap() .push(Event::WindowResized(WindowSize { - logical_size: Point2DI32::new(width, height), + logical_size: Point2DI::new(width, height), backing_scale_factor: 1.0, })) } @@ -134,7 +134,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder EVENT_QUEUE .lock() .unwrap() - .push(Event::MouseDown(Point2DI32::new(x, y))) + .push(Event::MouseDown(Point2DI::new(x, y))) } #[no_mangle] @@ -147,7 +147,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder EVENT_QUEUE .lock() .unwrap() - .push(Event::MouseDragged(Point2DI32::new(x, y))) + .push(Event::MouseDragged(Point2DI::new(x, y))) } #[no_mangle] @@ -161,7 +161,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder EVENT_QUEUE .lock() .unwrap() - .push(Event::Zoom(factor, Point2DI32::new(center_x, center_y))) + .push(Event::Zoom(factor, Point2DI::new(center_x, center_y))) } #[no_mangle] @@ -188,7 +188,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder } struct WindowImpl { - size: Point2DI32, + size: Point2DI, } impl Window for WindowImpl { @@ -196,7 +196,7 @@ impl Window for WindowImpl { GLVersion::GLES3 } - fn viewport(&self, view: View) -> RectI32 { + fn viewport(&self, view: View) -> RectI { let mut width = self.size.x(); let mut offset_x = 0; let height = self.size.y(); @@ -204,9 +204,9 @@ impl Window for WindowImpl { width = width / 2; offset_x = (index as i32) * width; } - let size = Point2DI32::new(width, height); - let offset = Point2DI32::new(offset_x, 0); - RectI32::new(offset, size) + let size = Point2DI::new(width, height); + let offset = Point2DI::new(offset_x, 0); + RectI::new(offset, size) } fn make_current(&mut self, _view: View) {} diff --git a/demo/common/src/camera.rs b/demo/common/src/camera.rs index 2121d8bd..7f80a334 100644 --- a/demo/common/src/camera.rs +++ b/demo/common/src/camera.rs @@ -14,10 +14,10 @@ // proper. use crate::window::{OcularTransform, View}; -use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32, Point3DF32}; -use pathfinder_geometry::basic::rect::RectF32; -use pathfinder_geometry::basic::transform2d::Transform2DF32; -use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF32}; +use pathfinder_geometry::basic::point::{Point2DF, Point2DI, Point3DF}; +use pathfinder_geometry::basic::rect::RectF; +use pathfinder_geometry::basic::transform2d::Transform2DF; +use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF}; use std::f32::consts::FRAC_PI_4; const NEAR_CLIP_PLANE: f32 = 0.01; @@ -27,7 +27,7 @@ const FAR_CLIP_PLANE: f32 = 10.0; const DEFAULT_EYE_OFFSET: f32 = 0.025; pub enum Camera { - TwoD(Transform2DF32), + TwoD(Transform2DF), ThreeD { // The ocular transform used for rendering of the scene to the scene framebuffer. If we are // performing stereoscopic rendering, this is then reprojected according to the eye @@ -39,12 +39,12 @@ pub enum Camera { // The modelview transform from world coordinates to SVG coordinates modelview_transform: CameraTransform3D, // The camera's velocity (in world coordinates) - velocity: Point3DF32, + velocity: Point3DF, }, } impl Camera { - pub fn new(mode: Mode, view_box: RectF32, viewport_size: Point2DI32) -> Camera { + pub fn new(mode: Mode, view_box: RectF, viewport_size: Point2DI) -> Camera { if mode == Mode::TwoD { Camera::new_2d(view_box, viewport_size) } else { @@ -52,20 +52,20 @@ impl Camera { } } - fn new_2d(view_box: RectF32, viewport_size: Point2DI32) -> Camera { + fn new_2d(view_box: RectF, viewport_size: Point2DI) -> Camera { let scale = i32::min(viewport_size.x(), viewport_size.y()) as f32 * scale_factor_for_view_box(view_box); let origin = viewport_size.to_f32().scale(0.5) - view_box.size().scale(scale * 0.5); - Camera::TwoD(Transform2DF32::from_scale(Point2DF32::splat(scale)).post_translate(origin)) + Camera::TwoD(Transform2DF::from_scale(Point2DF::splat(scale)).post_translate(origin)) } - fn new_3d(mode: Mode, view_box: RectF32, viewport_size: Point2DI32) -> Camera { + fn new_3d(mode: Mode, view_box: RectF, viewport_size: Point2DI) -> Camera { let viewport_count = mode.viewport_count(); let fov_y = FRAC_PI_4; let aspect = viewport_size.x() as f32 / viewport_size.y() as f32; let projection = - Transform3DF32::from_perspective(fov_y, aspect, NEAR_CLIP_PLANE, FAR_CLIP_PLANE); + Transform3DF::from_perspective(fov_y, aspect, NEAR_CLIP_PLANE, FAR_CLIP_PLANE); let perspective = Perspective::new(&projection, viewport_size); // Create a scene transform by moving the camera back from the center of the eyes so that @@ -73,7 +73,7 @@ impl Camera { let z_offset = -DEFAULT_EYE_OFFSET * projection.c0.x(); let scene_transform = OcularTransform { perspective, - modelview_to_eye: Transform3DF32::from_translation(0.0, 0.0, z_offset), + modelview_to_eye: Transform3DF::from_translation(0.0, 0.0, z_offset), }; // For now, initialize the eye transforms as copies of the scene transform. @@ -87,7 +87,7 @@ impl Camera { }; OcularTransform { perspective, - modelview_to_eye: Transform3DF32::from_translation(this_eye_offset, 0.0, 0.0), + modelview_to_eye: Transform3DF::from_translation(this_eye_offset, 0.0, 0.0), } }) .collect(); @@ -96,7 +96,7 @@ impl Camera { scene_transform, eye_transforms, modelview_transform: CameraTransform3D::new(view_box), - velocity: Point3DF32::default(), + velocity: Point3DF::default(), } } @@ -120,17 +120,17 @@ impl Camera { #[derive(Clone, Copy, Debug)] pub struct CameraTransform3D { - position: Point3DF32, + position: Point3DF, pub yaw: f32, pub pitch: f32, scale: f32, } impl CameraTransform3D { - fn new(view_box: RectF32) -> CameraTransform3D { + fn new(view_box: RectF) -> CameraTransform3D { let scale = scale_factor_for_view_box(view_box); CameraTransform3D { - position: Point3DF32::new( + position: Point3DF::new( 0.5 * view_box.max_x(), -0.5 * view_box.max_y(), 1.5 / scale, @@ -142,26 +142,26 @@ impl CameraTransform3D { } } - pub fn offset(&mut self, vector: Point3DF32) -> bool { + pub fn offset(&mut self, vector: Point3DF) -> bool { let update = !vector.is_zero(); if update { - let rotation = Transform3DF32::from_rotation(-self.yaw, -self.pitch, 0.0); + let rotation = Transform3DF::from_rotation(-self.yaw, -self.pitch, 0.0); self.position = self.position + rotation.transform_point(vector); } update } - pub fn to_transform(&self) -> Transform3DF32 { - let mut transform = Transform3DF32::from_rotation(self.yaw, self.pitch, 0.0); - transform = transform.post_mul(&Transform3DF32::from_uniform_scale(2.0 * self.scale)); - transform = transform.post_mul(&Transform3DF32::from_translation( + pub fn to_transform(&self) -> Transform3DF { + let mut transform = Transform3DF::from_rotation(self.yaw, self.pitch, 0.0); + transform = transform.post_mul(&Transform3DF::from_uniform_scale(2.0 * self.scale)); + transform = transform.post_mul(&Transform3DF::from_translation( -self.position.x(), -self.position.y(), -self.position.z(), )); // Flip Y. - transform = transform.post_mul(&Transform3DF32::from_scale(1.0, -1.0, 1.0)); + transform = transform.post_mul(&Transform3DF::from_scale(1.0, -1.0, 1.0)); transform } @@ -190,6 +190,6 @@ impl Mode { } } -pub fn scale_factor_for_view_box(view_box: RectF32) -> f32 { +pub fn scale_factor_for_view_box(view_box: RectF) -> f32 { 1.0 / f32::min(view_box.size().x(), view_box.size().y()) } diff --git a/demo/common/src/lib.rs b/demo/common/src/lib.rs index fc946316..0a3c0eba 100644 --- a/demo/common/src/lib.rs +++ b/demo/common/src/lib.rs @@ -19,9 +19,9 @@ use crate::device::{GroundProgram, GroundVertexArray}; use crate::ui::{DemoUIModel, DemoUIPresenter, ScreenshotInfo, ScreenshotType, UIAction}; use crate::window::{Event, Keycode, SVGPath, Window, WindowSize}; use clap::{App, Arg}; -use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; -use pathfinder_geometry::basic::rect::RectF32; -use pathfinder_geometry::basic::transform2d::Transform2DF32; +use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::rect::RectF; +use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::color::ColorU; use pathfinder_gl::GLDevice; use pathfinder_gpu::Device; @@ -99,7 +99,7 @@ pub struct DemoApp where W: Window { pub dirty: bool, expire_message_event_id: u32, message_epoch: u32, - last_mouse_position: Point2DI32, + last_mouse_position: Point2DI, current_frame: Option, build_time: Option, @@ -181,7 +181,7 @@ impl DemoApp where W: Window { dirty: true, expire_message_event_id, message_epoch, - last_mouse_position: Point2DI32::default(), + last_mouse_position: Point2DI::default(), current_frame: None, build_time: None, @@ -244,9 +244,9 @@ impl DemoApp where W: Window { dilation: if self.ui_model.stem_darkening_effect_enabled { let font_size = APPROX_FONT_SIZE * self.window_size.backing_scale_factor; let (x, y) = (STEM_DARKENING_FACTORS[0], STEM_DARKENING_FACTORS[1]); - Point2DF32::new(x, y).scale(font_size) + Point2DF::new(x, y).scale(font_size) } else { - Point2DF32::default() + Point2DF::default() }, subpixel_aa_enabled: self.ui_model.subpixel_aa_effect_enabled, }; @@ -267,7 +267,7 @@ impl DemoApp where W: Window { Event::WindowResized(new_size) => { self.window_size = new_size; let viewport = self.window.viewport(self.ui_model.mode.view(0)); - self.scene_proxy.set_view_box(RectF32::new(Point2DF32::default(), + self.scene_proxy.set_view_box(RectF::new(Point2DF::default(), viewport.size().to_f32())); self.renderer .set_main_framebuffer_size(self.window_size.device_size()); @@ -304,7 +304,7 @@ impl DemoApp where W: Window { let position = position.to_f32().scale(backing_scale_factor); *transform = transform.post_translate(-position); let scale_delta = 1.0 + d_dist * CAMERA_SCALE_SPEED_2D; - *transform = transform.post_scale(Point2DF32::splat(scale_delta)); + *transform = transform.post_scale(Point2DF::splat(scale_delta)); *transform = transform.post_translate(position); } } @@ -431,7 +431,7 @@ impl DemoApp where W: Window { ui_events } - fn process_mouse_position(&mut self, new_position: Point2DI32) -> MousePosition { + fn process_mouse_position(&mut self, new_position: Point2DI) -> MousePosition { let absolute = new_position.scale(self.window_size.backing_scale_factor as i32); let relative = absolute - self.last_mouse_position; self.last_mouse_position = absolute; @@ -557,7 +557,7 @@ impl DemoApp where W: Window { } UIAction::ZoomIn => { if let Camera::TwoD(ref mut transform) = self.camera { - let scale = Point2DF32::splat(1.0 + CAMERA_ZOOM_AMOUNT_2D); + let scale = Point2DF::splat(1.0 + CAMERA_ZOOM_AMOUNT_2D); let center = center_of_window(&self.window_size); *transform = transform .post_translate(-center) @@ -568,7 +568,7 @@ impl DemoApp where W: Window { } UIAction::ZoomOut => { if let Camera::TwoD(ref mut transform) = self.camera { - let scale = Point2DF32::splat(1.0 - CAMERA_ZOOM_AMOUNT_2D); + let scale = Point2DF::splat(1.0 - CAMERA_ZOOM_AMOUNT_2D); let center = center_of_window(&self.window_size); *transform = transform .post_translate(-center) @@ -579,7 +579,7 @@ impl DemoApp where W: Window { } UIAction::ZoomActualSize => { if let Camera::TwoD(ref mut transform) = self.camera { - *transform = Transform2DF32::default(); + *transform = Transform2DF::default(); self.dirty = true; } } @@ -729,7 +729,7 @@ fn load_scene(resource_loader: &dyn ResourceLoader, input_path: &SVGPath) -> Bui BuiltSVG::from_tree(Tree::from_data(&data, &UsvgOptions::default()).unwrap()) } -fn center_of_window(window_size: &WindowSize) -> Point2DF32 { +fn center_of_window(window_size: &WindowSize) -> Point2DF { window_size.device_size().to_f32().scale(0.5) } @@ -800,17 +800,17 @@ impl BackgroundColor { } struct SceneMetadata { - view_box: RectF32, + view_box: RectF, monochrome_color: Option, } impl SceneMetadata { // FIXME(pcwalton): The fact that this mutates the scene is really ugly! // Can we simplify this? - fn new_clipping_view_box(scene: &mut Scene, viewport_size: Point2DI32) -> SceneMetadata { + fn new_clipping_view_box(scene: &mut Scene, viewport_size: Point2DI) -> SceneMetadata { let view_box = scene.view_box(); let monochrome_color = scene.monochrome_color(); - scene.set_view_box(RectF32::new(Point2DF32::default(), viewport_size.to_f32())); + scene.set_view_box(RectF::new(Point2DF::default(), viewport_size.to_f32())); SceneMetadata { view_box, monochrome_color } } } diff --git a/demo/common/src/renderer.rs b/demo/common/src/renderer.rs index 01df38c5..a85f1524 100644 --- a/demo/common/src/renderer.rs +++ b/demo/common/src/renderer.rs @@ -17,7 +17,7 @@ use image::ColorType; use pathfinder_geometry::color::{ColorF, ColorU}; use pathfinder_gpu::{ClearParams, DepthFunc, DepthState, Device, Primitive, RenderState}; use pathfinder_gpu::{TextureFormat, UniformData}; -use pathfinder_geometry::basic::transform3d::Transform3DF32; +use pathfinder_geometry::basic::transform3d::Transform3DF; use pathfinder_renderer::gpu::renderer::{DestFramebuffer, RenderMode}; use pathfinder_renderer::gpu_data::RenderCommand; use pathfinder_renderer::options::RenderTransform; @@ -168,7 +168,7 @@ impl DemoApp where W: Window { let scene_framebuffer = self.scene_framebuffer.as_ref().unwrap(); let scene_texture = self.renderer.device.framebuffer_texture(scene_framebuffer); - let quad_scale_transform = Transform3DF32::from_scale( + let quad_scale_transform = Transform3DF::from_scale( self.scene_metadata.view_box.size().x(), self.scene_metadata.view_box.size().y(), 1.0, @@ -220,7 +220,7 @@ impl DemoApp where W: Window { let ground_scale = self.scene_metadata.view_box.max_x() * 2.0; let mut base_transform = perspective.transform; - base_transform = base_transform.post_mul(&Transform3DF32::from_translation( + base_transform = base_transform.post_mul(&Transform3DF::from_translation( -0.5 * self.scene_metadata.view_box.max_x(), self.scene_metadata.view_box.max_y(), -0.5 * ground_scale, @@ -229,7 +229,7 @@ impl DemoApp where W: Window { // Fill ground. let mut transform = base_transform; transform = - transform.post_mul(&Transform3DF32::from_scale(ground_scale, 1.0, ground_scale)); + transform.post_mul(&Transform3DF::from_scale(ground_scale, 1.0, ground_scale)); let device = &self.renderer.device; device.bind_vertex_array(&self.ground_vertex_array.vertex_array); diff --git a/demo/common/src/ui.rs b/demo/common/src/ui.rs index c308a88b..a857abc6 100644 --- a/demo/common/src/ui.rs +++ b/demo/common/src/ui.rs @@ -11,8 +11,8 @@ use crate::camera::Mode; use crate::window::Window; use crate::{BackgroundColor, Options}; -use pathfinder_geometry::basic::point::Point2DI32; -use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::rect::RectI; use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::Device; use pathfinder_renderer::gpu::debug::DebugUIPresenter; @@ -152,9 +152,9 @@ where // Draw button strip. let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING; - let mut position = Point2DI32::new(PADDING, bottom - BUTTON_HEIGHT); + let mut position = Point2DI::new(PADDING, bottom - BUTTON_HEIGHT); - let button_size = Point2DI32::new(BUTTON_WIDTH, BUTTON_HEIGHT); + let button_size = Point2DI::new(BUTTON_WIDTH, BUTTON_HEIGHT); // Draw text effects button. if self.show_text_effects { @@ -167,10 +167,10 @@ where debug_ui_presenter.ui_presenter.draw_tooltip( device, "Text Effects", - RectI32::new(position, button_size), + RectI::new(position, button_size), ); } - position += Point2DI32::new(button_size.x() + PADDING, 0); + position += Point2DI::new(button_size.x() + PADDING, 0); } // Draw open button. @@ -181,8 +181,8 @@ where } debug_ui_presenter.ui_presenter.draw_tooltip(device, "Open SVG", - RectI32::new(position, button_size)); - position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0); + RectI::new(position, button_size)); + position += Point2DI::new(BUTTON_WIDTH + PADDING, 0); // Draw screenshot button. if debug_ui_presenter.ui_presenter.draw_button(device, @@ -194,13 +194,13 @@ where debug_ui_presenter.ui_presenter.draw_tooltip( device, "Take Screenshot", - RectI32::new(position, button_size), + RectI::new(position, button_size), ); } // Draw screenshot panel, if necessary. self.draw_screenshot_panel(device, window, debug_ui_presenter, position.x(), action); - position += Point2DI32::new(button_size.x() + PADDING, 0); + position += Point2DI::new(button_size.x() + PADDING, 0); // Draw mode switch. let new_mode = debug_ui_presenter.ui_presenter.draw_text_switch( @@ -218,13 +218,13 @@ where } let mode_switch_width = debug_ui_presenter.ui_presenter.measure_segmented_control(3); - let mode_switch_size = Point2DI32::new(mode_switch_width, BUTTON_HEIGHT); + let mode_switch_size = Point2DI::new(mode_switch_width, BUTTON_HEIGHT); debug_ui_presenter.ui_presenter.draw_tooltip( device, "2D/3D/VR Mode", - RectI32::new(position, mode_switch_size), + RectI::new(position, mode_switch_size), ); - position += Point2DI32::new(mode_switch_width + PADDING, 0); + position += Point2DI::new(mode_switch_width + PADDING, 0); // Draw background switch. if debug_ui_presenter.ui_presenter.draw_button(device, @@ -236,13 +236,13 @@ where debug_ui_presenter.ui_presenter.draw_tooltip( device, "Background Color", - RectI32::new(position, button_size), + RectI::new(position, button_size), ); } // Draw background panel, if necessary. self.draw_background_panel(device, debug_ui_presenter, position.x(), action, model); - position += Point2DI32::new(button_size.x() + PADDING, 0); + position += Point2DI::new(button_size.x() + PADDING, 0); // Draw effects panel, if necessary. self.draw_effects_panel(device, debug_ui_presenter, model); @@ -258,10 +258,10 @@ where if !self.rotate_panel_visible { debug_ui_presenter.ui_presenter.draw_tooltip(device, "Rotate", - RectI32::new(position, button_size)); + RectI::new(position, button_size)); } self.draw_rotate_panel(device, debug_ui_presenter, position.x(), action, model); - position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0); + position += Point2DI::new(BUTTON_WIDTH + PADDING, 0); // Draw zoom control. self.draw_zoom_control(device, debug_ui_presenter, position, action); @@ -271,13 +271,13 @@ where &mut self, device: &D, debug_ui_presenter: &mut DebugUIPresenter, - position: Point2DI32, + position: Point2DI, action: &mut UIAction, ) { let zoom_segmented_control_width = debug_ui_presenter.ui_presenter.measure_segmented_control(3); let zoom_segmented_control_rect = - RectI32::new(position, Point2DI32::new(zoom_segmented_control_width, BUTTON_HEIGHT)); + RectI::new(position, Point2DI::new(zoom_segmented_control_width, BUTTON_HEIGHT)); debug_ui_presenter.ui_presenter.draw_tooltip(device, "Zoom", zoom_segmented_control_rect); let zoom_textures = &[ @@ -306,17 +306,17 @@ where } let message_size = debug_ui_presenter.ui_presenter.measure_text(&model.message); - let window_origin = Point2DI32::new(PADDING, PADDING); - let window_size = Point2DI32::new(PADDING * 2 + message_size, TOOLTIP_HEIGHT); + let window_origin = Point2DI::new(PADDING, PADDING); + let window_size = Point2DI::new(PADDING * 2 + message_size, TOOLTIP_HEIGHT); debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( device, - RectI32::new(window_origin, window_size), + RectI::new(window_origin, window_size), WINDOW_COLOR, ); debug_ui_presenter.ui_presenter.draw_text( device, &model.message, - window_origin + Point2DI32::new(PADDING, PADDING + FONT_ASCENT), + window_origin + Point2DI::new(PADDING, PADDING + FONT_ASCENT), false, ); } @@ -333,9 +333,9 @@ where let effects_panel_y = bottom - (BUTTON_HEIGHT + PADDING + EFFECTS_PANEL_HEIGHT); debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( device, - RectI32::new( - Point2DI32::new(PADDING, effects_panel_y), - Point2DI32::new(EFFECTS_PANEL_WIDTH, EFFECTS_PANEL_HEIGHT), + RectI::new( + Point2DI::new(PADDING, effects_panel_y), + Point2DI::new(EFFECTS_PANEL_WIDTH, EFFECTS_PANEL_HEIGHT), ), WINDOW_COLOR, ); @@ -380,12 +380,12 @@ where let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING; let panel_y = bottom - (BUTTON_HEIGHT + PADDING + SCREENSHOT_PANEL_HEIGHT); - let panel_position = Point2DI32::new(panel_x, panel_y); + let panel_position = Point2DI::new(panel_x, panel_y); debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( device, - RectI32::new( + RectI::new( panel_position, - Point2DI32::new(SCREENSHOT_PANEL_WIDTH, SCREENSHOT_PANEL_HEIGHT), + Point2DI::new(SCREENSHOT_PANEL_WIDTH, SCREENSHOT_PANEL_HEIGHT), ), WINDOW_COLOR, ); @@ -422,12 +422,12 @@ where let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING; let panel_y = bottom - (BUTTON_HEIGHT + PADDING + BACKGROUND_PANEL_HEIGHT); - let panel_position = Point2DI32::new(panel_x, panel_y); + let panel_position = Point2DI::new(panel_x, panel_y); debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( device, - RectI32::new( + RectI::new( panel_position, - Point2DI32::new(BACKGROUND_PANEL_WIDTH, BACKGROUND_PANEL_HEIGHT), + Point2DI::new(BACKGROUND_PANEL_WIDTH, BACKGROUND_PANEL_HEIGHT), ), WINDOW_COLOR, ); @@ -472,18 +472,18 @@ where let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING; let rotate_panel_y = bottom - (BUTTON_HEIGHT + PADDING + ROTATE_PANEL_HEIGHT); - let rotate_panel_origin = Point2DI32::new(rotate_panel_x, rotate_panel_y); - let rotate_panel_size = Point2DI32::new(ROTATE_PANEL_WIDTH, ROTATE_PANEL_HEIGHT); + let rotate_panel_origin = Point2DI::new(rotate_panel_x, rotate_panel_y); + let rotate_panel_size = Point2DI::new(ROTATE_PANEL_WIDTH, ROTATE_PANEL_HEIGHT); debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( device, - RectI32::new(rotate_panel_origin, rotate_panel_size), + RectI::new(rotate_panel_origin, rotate_panel_size), WINDOW_COLOR, ); let (widget_x, widget_y) = (rotate_panel_x + PADDING, rotate_panel_y + PADDING); - let widget_rect = RectI32::new( - Point2DI32::new(widget_x, widget_y), - Point2DI32::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT), + let widget_rect = RectI::new( + Point2DI::new(widget_x, widget_y), + Point2DI::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT), ); if let Some(position) = debug_ui_presenter .ui_presenter @@ -496,18 +496,18 @@ where let slider_track_y = rotate_panel_y + PADDING + SLIDER_KNOB_HEIGHT / 2 - SLIDER_TRACK_HEIGHT / 2; - let slider_track_rect = RectI32::new( - Point2DI32::new(widget_x, slider_track_y), - Point2DI32::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT), + let slider_track_rect = RectI::new( + Point2DI::new(widget_x, slider_track_y), + Point2DI::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT), ); debug_ui_presenter .ui_presenter .draw_rect_outline(device, slider_track_rect, TEXT_COLOR); let slider_knob_x = widget_x + model.rotation - SLIDER_KNOB_WIDTH / 2; - let slider_knob_rect = RectI32::new( - Point2DI32::new(slider_knob_x, widget_y), - Point2DI32::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT), + let slider_knob_rect = RectI::new( + Point2DI::new(slider_knob_x, widget_y), + Point2DI::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT), ); debug_ui_presenter.ui_presenter.draw_solid_rect(device, slider_knob_rect, TEXT_COLOR); } @@ -518,15 +518,15 @@ where window: &mut W, debug_ui_presenter: &mut DebugUIPresenter, screenshot_type: ScreenshotType, - panel_position: Point2DI32, + panel_position: Point2DI, action: &mut UIAction, ) where W: Window { let index = screenshot_type as i32; let text = format!("Save as {}...", screenshot_type.as_str()); - let widget_size = Point2DI32::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); - let widget_origin = panel_position + Point2DI32::new(0, widget_size.y() * index); - let widget_rect = RectI32::new(widget_origin, widget_size); + let widget_size = Point2DI::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); + let widget_origin = panel_position + Point2DI::new(0, widget_size.y() * index); + let widget_rect = RectI::new(widget_origin, widget_size); if self.draw_menu_item(device, debug_ui_presenter, &text, widget_rect, false) { // FIXME(pcwalton): This is not sufficient for Android, where we will need to take in @@ -543,15 +543,15 @@ where device: &D, debug_ui_presenter: &mut DebugUIPresenter, color: BackgroundColor, - panel_position: Point2DI32, + panel_position: Point2DI, action: &mut UIAction, model: &mut DemoUIModel, ) { let (text, index) = (color.as_str(), color as i32); - let widget_size = Point2DI32::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); - let widget_origin = panel_position + Point2DI32::new(0, widget_size.y() * index); - let widget_rect = RectI32::new(widget_origin, widget_size); + let widget_size = Point2DI::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); + let widget_origin = panel_position + Point2DI::new(0, widget_size.y() * index); + let widget_rect = RectI::new(widget_origin, widget_size); let selected = color == model.background_color; if self.draw_menu_item(device, debug_ui_presenter, text, widget_rect, selected) { @@ -564,7 +564,7 @@ where device: &D, debug_ui_presenter: &mut DebugUIPresenter, text: &str, - widget_rect: RectI32, + widget_rect: RectI, selected: bool) -> bool { if selected { @@ -574,7 +574,7 @@ where } let (text_x, text_y) = (PADDING * 2, BUTTON_TEXT_OFFSET); - let text_position = widget_rect.origin() + Point2DI32::new(text_x, text_y); + let text_position = widget_rect.origin() + Point2DI::new(text_x, text_y); debug_ui_presenter.ui_presenter.draw_text(device, text, text_position, selected); debug_ui_presenter.ui_presenter @@ -596,12 +596,12 @@ where let text_y = window_y + PADDING + BUTTON_TEXT_OFFSET + (BUTTON_HEIGHT + PADDING) * index; debug_ui_presenter .ui_presenter - .draw_text(device, text, Point2DI32::new(text_x, text_y), false); + .draw_text(device, text, Point2DI::new(text_x, text_y), false); let switch_width = debug_ui_presenter.ui_presenter.measure_segmented_control(2); let switch_x = PADDING + EFFECTS_PANEL_WIDTH - (switch_width + PADDING); let switch_y = window_y + PADDING + (BUTTON_HEIGHT + PADDING) * index; - let switch_position = Point2DI32::new(switch_x, switch_y); + let switch_position = Point2DI::new(switch_x, switch_y); debug_ui_presenter .ui_presenter .draw_text_switch(device, switch_position, &["Off", "On"], value as u8) diff --git a/demo/common/src/window.rs b/demo/common/src/window.rs index 44bda124..b38f4fcf 100644 --- a/demo/common/src/window.rs +++ b/demo/common/src/window.rs @@ -11,9 +11,9 @@ //! A minimal cross-platform windowing layer. use gl::types::GLuint; -use pathfinder_geometry::basic::point::Point2DI32; -use pathfinder_geometry::basic::rect::RectI32; -use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF32}; +use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::rect::RectI; +use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF}; use pathfinder_gl::GLVersion; use pathfinder_gpu::resources::ResourceLoader; use rayon::ThreadPoolBuilder; @@ -25,7 +25,7 @@ pub trait Window { 0 } - fn viewport(&self, view: View) -> RectI32; + fn viewport(&self, view: View) -> RectI; fn make_current(&mut self, view: View); fn present(&mut self); fn resource_loader(&self) -> &dyn ResourceLoader; @@ -42,10 +42,10 @@ pub enum Event { WindowResized(WindowSize), KeyDown(Keycode), KeyUp(Keycode), - MouseDown(Point2DI32), - MouseMoved(Point2DI32), - MouseDragged(Point2DI32), - Zoom(f32, Point2DI32), + MouseDown(Point2DI), + MouseMoved(Point2DI), + MouseDragged(Point2DI), + Zoom(f32, Point2DI), Look { pitch: f32, yaw: f32, @@ -67,13 +67,13 @@ pub enum Keycode { #[derive(Clone, Copy, Debug)] pub struct WindowSize { - pub logical_size: Point2DI32, + pub logical_size: Point2DI, pub backing_scale_factor: f32, } impl WindowSize { #[inline] - pub fn device_size(&self) -> Point2DI32 { + pub fn device_size(&self) -> Point2DI { self.logical_size .to_f32() .scale(self.backing_scale_factor) @@ -93,7 +93,7 @@ pub struct OcularTransform { pub perspective: Perspective, // The view transform which converts from world coordinates to camera coordinates - pub modelview_to_eye: Transform3DF32, + pub modelview_to_eye: Transform3DF, } #[derive(Clone)] diff --git a/demo/native/src/main.rs b/demo/native/src/main.rs index d0d97497..d8981cc3 100644 --- a/demo/native/src/main.rs +++ b/demo/native/src/main.rs @@ -13,8 +13,8 @@ use nfd::Response; use pathfinder_demo::window::{Event, Keycode, SVGPath, View, Window, WindowSize}; use pathfinder_demo::{DemoApp, Options}; -use pathfinder_geometry::basic::point::Point2DI32; -use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::rect::RectI; use pathfinder_gl::GLVersion; use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader}; use sdl2::event::{Event as SDLEvent, WindowEvent}; @@ -83,7 +83,7 @@ impl Window for WindowImpl { GLVersion::GL3 } - fn viewport(&self, view: View) -> RectI32 { + fn viewport(&self, view: View) -> RectI { let (width, height) = self.window.drawable_size(); let mut width = width as i32; let height = height as i32; @@ -92,7 +92,7 @@ impl Window for WindowImpl { width = width / 2; x_offset = width * (index as i32); } - RectI32::new(Point2DI32::new(x_offset, 0), Point2DI32::new(width, height)) + RectI::new(Point2DI::new(x_offset, 0), Point2DI::new(width, height)) } fn make_current(&mut self, _view: View) { @@ -189,7 +189,7 @@ impl WindowImpl { let (logical_width, logical_height) = self.window.size(); let (drawable_width, _) = self.window.drawable_size(); WindowSize { - logical_size: Point2DI32::new(logical_width as i32, logical_height as i32), + logical_size: Point2DI::new(logical_width as i32, logical_height as i32), backing_scale_factor: drawable_width as f32 / logical_width as f32, } } @@ -221,11 +221,11 @@ impl WindowImpl { message_type: type_, message_data: code as u32, }), - SDLEvent::MouseButtonDown { x, y, .. } => Some(Event::MouseDown(Point2DI32::new(x, y))), + SDLEvent::MouseButtonDown { x, y, .. } => Some(Event::MouseDown(Point2DI::new(x, y))), SDLEvent::MouseMotion { x, y, mousestate, .. } => { - let position = Point2DI32::new(x, y); + let position = Point2DI::new(x, y); if mousestate.left() { Some(Event::MouseDragged(position)) } else { @@ -247,7 +247,7 @@ impl WindowImpl { } => self.convert_sdl_keycode(sdl_keycode).map(Event::KeyUp), SDLEvent::MultiGesture { d_dist, .. } => { let mouse_state = self.event_pump.mouse_state(); - let center = Point2DI32::new(mouse_state.x(), mouse_state.y()); + let center = Point2DI::new(mouse_state.x(), mouse_state.y()); Some(Event::Zoom(d_dist, center)) } _ => None, diff --git a/examples/canvas_minimal/src/main.rs b/examples/canvas_minimal/src/main.rs index 76393a5e..786151b3 100644 --- a/examples/canvas_minimal/src/main.rs +++ b/examples/canvas_minimal/src/main.rs @@ -9,8 +9,8 @@ // except according to those terms. use pathfinder_canvas::{CanvasRenderingContext2D, Path2D}; -use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; -use pathfinder_geometry::basic::rect::RectF32; +use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::color::ColorF; use pathfinder_geometry::stroke::LineJoin; use pathfinder_gl::{GLDevice, GLVersion}; @@ -35,7 +35,7 @@ fn main() { gl_attributes.set_context_version(3, 3); // Open a window. - let window_size = Point2DI32::new(640, 480); + let window_size = Point2DI::new(640, 480); let window = video.window("Minimal example", window_size.x() as u32, window_size.y() as u32) .opengl() .build() @@ -61,16 +61,16 @@ fn main() { canvas.set_line_width(10.0); // Draw walls. - canvas.stroke_rect(RectF32::new(Point2DF32::new(75.0, 140.0), Point2DF32::new(150.0, 110.0))); + canvas.stroke_rect(RectF::new(Point2DF::new(75.0, 140.0), Point2DF::new(150.0, 110.0))); // Draw door. - canvas.fill_rect(RectF32::new(Point2DF32::new(130.0, 190.0), Point2DF32::new(40.0, 60.0))); + canvas.fill_rect(RectF::new(Point2DF::new(130.0, 190.0), Point2DF::new(40.0, 60.0))); // Draw roof. let mut path = Path2D::new(); - path.move_to(Point2DF32::new(50.0, 140.0)); - path.line_to(Point2DF32::new(150.0, 60.0)); - path.line_to(Point2DF32::new(250.0, 140.0)); + path.move_to(Point2DF::new(50.0, 140.0)); + path.line_to(Point2DF::new(150.0, 60.0)); + path.line_to(Point2DF::new(250.0, 140.0)); path.close_path(); canvas.stroke_path(path); diff --git a/examples/canvas_moire/src/main.rs b/examples/canvas_moire/src/main.rs index 2d0152d2..bd72423a 100644 --- a/examples/canvas_moire/src/main.rs +++ b/examples/canvas_moire/src/main.rs @@ -9,7 +9,7 @@ // except according to those terms. use pathfinder_canvas::{CanvasRenderingContext2D, FillStyle, Path2D}; -use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; +use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; use pathfinder_geometry::color::{ColorF, ColorU}; use pathfinder_gl::{GLDevice, GLVersion}; use pathfinder_gpu::resources::FilesystemResourceLoader; @@ -47,7 +47,7 @@ fn main() { gl_attributes.set_context_version(3, 3); // Open a window. - let window_size = Point2DI32::new(1067, 800); + let window_size = Point2DI::new(1067, 800); let window = video.window("Moire example", window_size.x() as u32, window_size.y() as u32) .opengl() .allow_highdpi() @@ -57,7 +57,7 @@ fn main() { // Get the real window size (for HiDPI). let (drawable_width, drawable_height) = window.drawable_size(); - let drawable_size = Point2DI32::new(drawable_width as i32, drawable_height as i32); + let drawable_size = Point2DI::new(drawable_width as i32, drawable_height as i32); // Create the GL context, and make it current. let gl_context = window.gl_create_context().unwrap(); @@ -87,14 +87,14 @@ struct MoireRenderer { renderer: Renderer, scene: SceneProxy, frame: i32, - window_size: Point2DI32, - drawable_size: Point2DI32, + window_size: Point2DI, + drawable_size: Point2DI, device_pixel_ratio: f32, colors: ColorGradient, } impl MoireRenderer { - fn new(renderer: Renderer, window_size: Point2DI32, drawable_size: Point2DI32) + fn new(renderer: Renderer, window_size: Point2DI, drawable_size: Point2DI) -> MoireRenderer { MoireRenderer { renderer, @@ -117,9 +117,9 @@ impl MoireRenderer { // Calculate outer and inner circle centers (circle and Leminscate of Gerono respectively). let window_center = self.window_size.to_f32().scale(0.5); - let outer_center = window_center + Point2DF32::new(sin_time, cos_time).scale(OUTER_RADIUS); + let outer_center = window_center + Point2DF::new(sin_time, cos_time).scale(OUTER_RADIUS); let inner_center = window_center + - Point2DF32::new(1.0, sin_time).scale(cos_time * INNER_RADIUS); + Point2DF::new(1.0, sin_time).scale(cos_time * INNER_RADIUS); // Clear to background color. self.renderer.device.clear(&ClearParams { @@ -144,7 +144,7 @@ impl MoireRenderer { self.frame += 1; } - fn draw_circles(&self, canvas: &mut CanvasRenderingContext2D, center: Point2DF32) { + fn draw_circles(&self, canvas: &mut CanvasRenderingContext2D, center: Point2DF) { let center = center.scale(self.device_pixel_ratio); for index in 0..CIRCLE_COUNT { let radius = (index + 1) as f32 * CIRCLE_SPACING * self.device_pixel_ratio; diff --git a/examples/canvas_text/src/main.rs b/examples/canvas_text/src/main.rs index 8894e776..93871097 100644 --- a/examples/canvas_text/src/main.rs +++ b/examples/canvas_text/src/main.rs @@ -9,7 +9,7 @@ // except according to those terms. use pathfinder_canvas::CanvasRenderingContext2D; -use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; +use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; use pathfinder_geometry::color::ColorF; use pathfinder_gl::{GLDevice, GLVersion}; use pathfinder_gpu::resources::FilesystemResourceLoader; @@ -33,7 +33,7 @@ fn main() { gl_attributes.set_context_version(3, 3); // Open a window. - let window_size = Point2DI32::new(640, 480); + let window_size = Point2DI::new(640, 480); let window = video.window("Text example", window_size.x() as u32, window_size.y() as u32) .opengl() .build() @@ -57,8 +57,8 @@ fn main() { // Draw the text. canvas.set_font_size(32.0); - canvas.fill_text("Hello Pathfinder!", Point2DF32::new(32.0, 48.0)); - canvas.stroke_text("Goodbye Pathfinder!", Point2DF32::new(32.0, 96.0)); + canvas.fill_text("Hello Pathfinder!", Point2DF::new(32.0, 48.0)); + canvas.stroke_text("Goodbye Pathfinder!", Point2DF::new(32.0, 96.0)); // Render the canvas to screen. let scene = SceneProxy::from_scene(canvas.into_scene(), RayonExecutor); diff --git a/geometry/src/basic/line_segment.rs b/geometry/src/basic/line_segment.rs index d6a900b1..5c45f880 100644 --- a/geometry/src/basic/line_segment.rs +++ b/geometry/src/basic/line_segment.rs @@ -10,38 +10,38 @@ //! Line segment types, optimized with SIMD. -use crate::basic::point::Point2DF32; -use crate::basic::transform2d::Matrix2x2F32; +use crate::basic::point::Point2DF; +use crate::basic::transform2d::Matrix2x2F; use crate::util; use pathfinder_simd::default::F32x4; use std::ops::{Add, Sub}; #[derive(Clone, Copy, Debug, PartialEq, Default)] -pub struct LineSegmentF32(pub F32x4); +pub struct LineSegmentF(pub F32x4); -impl LineSegmentF32 { +impl LineSegmentF { #[inline] - pub fn new(from: Point2DF32, to: Point2DF32) -> LineSegmentF32 { - LineSegmentF32(from.0.concat_xy_xy(to.0)) + pub fn new(from: Point2DF, to: Point2DF) -> LineSegmentF { + LineSegmentF(from.0.concat_xy_xy(to.0)) } #[inline] - pub fn from(&self) -> Point2DF32 { - Point2DF32(self.0) + pub fn from(&self) -> Point2DF { + Point2DF(self.0) } #[inline] - pub fn to(&self) -> Point2DF32 { - Point2DF32(self.0.zwxy()) + pub fn to(&self) -> Point2DF { + Point2DF(self.0.zwxy()) } #[inline] - pub fn set_from(&mut self, point: &Point2DF32) { + pub fn set_from(&mut self, point: &Point2DF) { self.0 = point.0.concat_xy_zw(self.0) } #[inline] - pub fn set_to(&mut self, point: &Point2DF32) { + pub fn set_to(&mut self, point: &Point2DF) { self.0 = self.0.concat_xy_xy(point.0) } @@ -88,30 +88,30 @@ impl LineSegmentF32 { } #[inline] - pub fn translate(&self, offset: Point2DF32) -> LineSegmentF32 { - LineSegmentF32(self.0 + offset.0.xyxy()) + pub fn translate(&self, offset: Point2DF) -> LineSegmentF { + LineSegmentF(self.0 + offset.0.xyxy()) } #[inline] - pub fn scale(&self, factor: f32) -> LineSegmentF32 { - LineSegmentF32(self.0 * F32x4::splat(factor)) + pub fn scale(&self, factor: f32) -> LineSegmentF { + LineSegmentF(self.0 * F32x4::splat(factor)) } #[inline] - pub fn split(&self, t: f32) -> (LineSegmentF32, LineSegmentF32) { + pub fn split(&self, t: f32) -> (LineSegmentF, LineSegmentF) { debug_assert!(t >= 0.0 && t <= 1.0); let (from_from, to_to) = (self.0.xyxy(), self.0.zwzw()); let d_d = to_to - from_from; let mid_mid = from_from + d_d * F32x4::splat(t); ( - LineSegmentF32(from_from.concat_xy_xy(mid_mid)), - LineSegmentF32(mid_mid.concat_xy_xy(to_to)), + LineSegmentF(from_from.concat_xy_xy(mid_mid)), + LineSegmentF(mid_mid.concat_xy_xy(to_to)), ) } // Returns the left segment first, followed by the right segment. #[inline] - pub fn split_at_x(&self, x: f32) -> (LineSegmentF32, LineSegmentF32) { + pub fn split_at_x(&self, x: f32) -> (LineSegmentF, LineSegmentF) { let (min_part, max_part) = self.split(self.solve_t_for_x(x)); if min_part.from_x() < max_part.from_x() { (min_part, max_part) @@ -122,7 +122,7 @@ impl LineSegmentF32 { // Returns the upper segment first, followed by the lower segment. #[inline] - pub fn split_at_y(&self, y: f32) -> (LineSegmentF32, LineSegmentF32) { + pub fn split_at_y(&self, y: f32) -> (LineSegmentF, LineSegmentF) { let (min_part, max_part) = self.split(self.solve_t_for_y(y)); // Make sure we compare `from_y` and `to_y` to properly handle the case in which one of the @@ -155,12 +155,12 @@ impl LineSegmentF32 { } #[inline] - pub fn reversed(&self) -> LineSegmentF32 { - LineSegmentF32(self.0.zwxy()) + pub fn reversed(&self) -> LineSegmentF { + LineSegmentF(self.0.zwxy()) } #[inline] - pub fn upper_point(&self) -> Point2DF32 { + pub fn upper_point(&self) -> Point2DF { if self.from_y() < self.to_y() { self.from() } else { @@ -200,7 +200,7 @@ impl LineSegmentF32 { // Reverses if necessary so that the from point is above the to point. Calling this method // again will undo the transformation. #[inline] - pub fn orient(&self, y_winding: i32) -> LineSegmentF32 { + pub fn orient(&self, y_winding: i32) -> LineSegmentF { if y_winding >= 0 { *self } else { @@ -227,14 +227,14 @@ impl LineSegmentF32 { } #[inline] - pub fn vector(&self) -> Point2DF32 { + pub fn vector(&self) -> Point2DF { self.to() - self.from() } // http://www.cs.swan.ac.uk/~cssimon/line_intersection.html - pub fn intersection_t(&self, other: &LineSegmentF32) -> Option { + pub fn intersection_t(&self, other: &LineSegmentF) -> Option { let p0p1 = self.vector(); - let matrix = Matrix2x2F32(other.vector().0.concat_xy_xy((-p0p1).0)); + let matrix = Matrix2x2F(other.vector().0.concat_xy_xy((-p0p1).0)); if f32::abs(matrix.det()) < EPSILON { return None; } @@ -244,12 +244,12 @@ impl LineSegmentF32 { } #[inline] - pub fn sample(&self, t: f32) -> Point2DF32 { + pub fn sample(&self, t: f32) -> Point2DF { self.from() + self.vector().scale(t) } #[inline] - pub fn offset(&self, distance: f32) -> LineSegmentF32 { + pub fn offset(&self, distance: f32) -> LineSegmentF { if self.is_zero_length() { *self } else { @@ -258,7 +258,7 @@ impl LineSegmentF32 { .vector() .yx() .normalize() - .scale_xy(Point2DF32::new(-distance, distance)) + .scale_xy(Point2DF::new(-distance, distance)) } } @@ -268,19 +268,19 @@ impl LineSegmentF32 { } } -impl Add for LineSegmentF32 { - type Output = LineSegmentF32; +impl Add for LineSegmentF { + type Output = LineSegmentF; #[inline] - fn add(self, point: Point2DF32) -> LineSegmentF32 { - LineSegmentF32(self.0 + point.0.xyxy()) + fn add(self, point: Point2DF) -> LineSegmentF { + LineSegmentF(self.0 + point.0.xyxy()) } } -impl Sub for LineSegmentF32 { - type Output = LineSegmentF32; +impl Sub for LineSegmentF { + type Output = LineSegmentF; #[inline] - fn sub(self, point: Point2DF32) -> LineSegmentF32 { - LineSegmentF32(self.0 - point.0.xyxy()) + fn sub(self, point: Point2DF) -> LineSegmentF { + LineSegmentF(self.0 - point.0.xyxy()) } } diff --git a/geometry/src/basic/point.rs b/geometry/src/basic/point.rs index ec56ebba..e098e44e 100644 --- a/geometry/src/basic/point.rs +++ b/geometry/src/basic/point.rs @@ -15,22 +15,22 @@ use std::ops::{Add, AddAssign, Mul, Neg, Sub}; /// 2D points with 32-bit floating point coordinates. #[derive(Clone, Copy, Debug, Default)] -pub struct Point2DF32(pub F32x4); +pub struct Point2DF(pub F32x4); -impl Point2DF32 { +impl Point2DF { #[inline] - pub fn new(x: f32, y: f32) -> Point2DF32 { - Point2DF32(F32x4::new(x, y, 0.0, 0.0)) + pub fn new(x: f32, y: f32) -> Point2DF { + Point2DF(F32x4::new(x, y, 0.0, 0.0)) } #[inline] - pub fn splat(value: f32) -> Point2DF32 { - Point2DF32(F32x4::splat(value)) + pub fn splat(value: f32) -> Point2DF { + Point2DF(F32x4::splat(value)) } #[inline] - pub fn to_3d(self) -> Point3DF32 { - Point3DF32(self.0.concat_xy_xy(F32x4::new(0.0, 1.0, 0.0, 0.0))) + pub fn to_3d(self) -> Point3DF { + Point3DF(self.0.concat_xy_xy(F32x4::new(0.0, 1.0, 0.0, 0.0))) } #[inline] @@ -54,49 +54,49 @@ impl Point2DF32 { } #[inline] - pub fn min(&self, other: Point2DF32) -> Point2DF32 { - Point2DF32(self.0.min(other.0)) + pub fn min(&self, other: Point2DF) -> Point2DF { + Point2DF(self.0.min(other.0)) } #[inline] - pub fn max(&self, other: Point2DF32) -> Point2DF32 { - Point2DF32(self.0.max(other.0)) + pub fn max(&self, other: Point2DF) -> Point2DF { + Point2DF(self.0.max(other.0)) } #[inline] - pub fn clamp(&self, min_val: Point2DF32, max_val: Point2DF32) -> Point2DF32 { + pub fn clamp(&self, min_val: Point2DF, max_val: Point2DF) -> Point2DF { self.max(min_val).min(max_val) } #[inline] - pub fn det(&self, other: Point2DF32) -> f32 { + pub fn det(&self, other: Point2DF) -> f32 { self.x() * other.y() - self.y() * other.x() } #[inline] - pub fn dot(&self, other: Point2DF32) -> f32 { + pub fn dot(&self, other: Point2DF) -> f32 { let xy = self.0 * other.0; xy.x() + xy.y() } #[inline] - pub fn scale(&self, x: f32) -> Point2DF32 { - Point2DF32(self.0 * F32x4::splat(x)) + pub fn scale(&self, x: f32) -> Point2DF { + Point2DF(self.0 * F32x4::splat(x)) } #[inline] - pub fn scale_xy(&self, factors: Point2DF32) -> Point2DF32 { - Point2DF32(self.0 * factors.0) + pub fn scale_xy(&self, factors: Point2DF) -> Point2DF { + Point2DF(self.0 * factors.0) } #[inline] - pub fn floor(&self) -> Point2DF32 { - Point2DF32(self.0.floor()) + pub fn floor(&self) -> Point2DF { + Point2DF(self.0.floor()) } #[inline] - pub fn ceil(&self) -> Point2DF32 { - Point2DF32(self.0.ceil()) + pub fn ceil(&self) -> Point2DF { + Point2DF(self.0.ceil()) } /// Treats this point as a vector and calculates its squared length. @@ -114,85 +114,85 @@ impl Point2DF32 { /// Treats this point as a vector and normalizes it. #[inline] - pub fn normalize(&self) -> Point2DF32 { + pub fn normalize(&self) -> Point2DF { self.scale(1.0 / self.length()) } /// Swaps y and x. #[inline] - pub fn yx(&self) -> Point2DF32 { - Point2DF32(self.0.yxwz()) + pub fn yx(&self) -> Point2DF { + Point2DF(self.0.yxwz()) } #[inline] pub fn is_zero(&self) -> bool { - *self == Point2DF32::default() + *self == Point2DF::default() } #[inline] - pub fn lerp(&self, other: Point2DF32, t: f32) -> Point2DF32 { + pub fn lerp(&self, other: Point2DF, t: f32) -> Point2DF { *self + (other - *self).scale(t) } #[inline] - pub fn to_i32(&self) -> Point2DI32 { - Point2DI32(self.0.to_i32x4()) + pub fn to_i32(&self) -> Point2DI { + Point2DI(self.0.to_i32x4()) } } -impl PartialEq for Point2DF32 { +impl PartialEq for Point2DF { #[inline] - fn eq(&self, other: &Point2DF32) -> bool { + fn eq(&self, other: &Point2DF) -> bool { let results = self.0.packed_eq(other.0); results[0] != 0 && results[1] != 0 } } -impl Add for Point2DF32 { - type Output = Point2DF32; +impl Add for Point2DF { + type Output = Point2DF; #[inline] - fn add(self, other: Point2DF32) -> Point2DF32 { - Point2DF32(self.0 + other.0) + fn add(self, other: Point2DF) -> Point2DF { + Point2DF(self.0 + other.0) } } -impl Sub for Point2DF32 { - type Output = Point2DF32; +impl Sub for Point2DF { + type Output = Point2DF; #[inline] - fn sub(self, other: Point2DF32) -> Point2DF32 { - Point2DF32(self.0 - other.0) + fn sub(self, other: Point2DF) -> Point2DF { + Point2DF(self.0 - other.0) } } -impl Mul for Point2DF32 { - type Output = Point2DF32; +impl Mul for Point2DF { + type Output = Point2DF; #[inline] - fn mul(self, other: Point2DF32) -> Point2DF32 { - Point2DF32(self.0 * other.0) + fn mul(self, other: Point2DF) -> Point2DF { + Point2DF(self.0 * other.0) } } -impl Neg for Point2DF32 { - type Output = Point2DF32; +impl Neg for Point2DF { + type Output = Point2DF; #[inline] - fn neg(self) -> Point2DF32 { - Point2DF32(-self.0) + fn neg(self) -> Point2DF { + Point2DF(-self.0) } } /// 2D points with 32-bit signed integer coordinates. #[derive(Clone, Copy, Debug, Default)] -pub struct Point2DI32(pub I32x4); +pub struct Point2DI(pub I32x4); -impl Point2DI32 { +impl Point2DI { #[inline] - pub fn new(x: i32, y: i32) -> Point2DI32 { - Point2DI32(I32x4::new(x, y, 0, 0)) + pub fn new(x: i32, y: i32) -> Point2DI { + Point2DI(I32x4::new(x, y, 0, 0)) } #[inline] - pub fn splat(value: i32) -> Point2DI32 { - Point2DI32(I32x4::splat(value)) + pub fn splat(value: i32) -> Point2DI { + Point2DI(I32x4::splat(value)) } #[inline] @@ -216,47 +216,47 @@ impl Point2DI32 { } #[inline] - pub fn scale(&self, factor: i32) -> Point2DI32 { - Point2DI32(self.0 * I32x4::splat(factor)) + pub fn scale(&self, factor: i32) -> Point2DI { + Point2DI(self.0 * I32x4::splat(factor)) } #[inline] - pub fn scale_xy(&self, factors: Point2DI32) -> Point2DI32 { - Point2DI32(self.0 * factors.0) + pub fn scale_xy(&self, factors: Point2DI) -> Point2DI { + Point2DI(self.0 * factors.0) } #[inline] - pub fn to_f32(&self) -> Point2DF32 { - Point2DF32(self.0.to_f32x4()) + pub fn to_f32(&self) -> Point2DF { + Point2DF(self.0.to_f32x4()) } } -impl Add for Point2DI32 { - type Output = Point2DI32; +impl Add for Point2DI { + type Output = Point2DI; #[inline] - fn add(self, other: Point2DI32) -> Point2DI32 { - Point2DI32(self.0 + other.0) + fn add(self, other: Point2DI) -> Point2DI { + Point2DI(self.0 + other.0) } } -impl AddAssign for Point2DI32 { +impl AddAssign for Point2DI { #[inline] - fn add_assign(&mut self, other: Point2DI32) { + fn add_assign(&mut self, other: Point2DI) { self.0 += other.0 } } -impl Sub for Point2DI32 { - type Output = Point2DI32; +impl Sub for Point2DI { + type Output = Point2DI; #[inline] - fn sub(self, other: Point2DI32) -> Point2DI32 { - Point2DI32(self.0 - other.0) + fn sub(self, other: Point2DI) -> Point2DI { + Point2DI(self.0 - other.0) } } -impl PartialEq for Point2DI32 { +impl PartialEq for Point2DI { #[inline] - fn eq(&self, other: &Point2DI32) -> bool { + fn eq(&self, other: &Point2DI) -> bool { let results = self.0.packed_eq(other.0); results[0] != 0 && results[1] != 0 } @@ -264,22 +264,22 @@ impl PartialEq for Point2DI32 { /// 3D homogeneous points. #[derive(Clone, Copy, Debug, PartialEq)] -pub struct Point3DF32(pub F32x4); +pub struct Point3DF(pub F32x4); -impl Point3DF32 { +impl Point3DF { #[inline] - pub fn new(x: f32, y: f32, z: f32, w: f32) -> Point3DF32 { - Point3DF32(F32x4::new(x, y, z, w)) + pub fn new(x: f32, y: f32, z: f32, w: f32) -> Point3DF { + Point3DF(F32x4::new(x, y, z, w)) } #[inline] - pub fn splat(value: f32) -> Point3DF32 { - Point3DF32(F32x4::splat(value)) + pub fn splat(value: f32) -> Point3DF { + Point3DF(F32x4::splat(value)) } #[inline] - pub fn to_2d(self) -> Point2DF32 { - Point2DF32(self.0) + pub fn to_2d(self) -> Point2DF { + Point2DF(self.0) } #[inline] @@ -303,10 +303,10 @@ impl Point3DF32 { } #[inline] - pub fn scale(&self, x: f32) -> Point3DF32 { + pub fn scale(&self, x: f32) -> Point3DF { let mut factors = F32x4::splat(x); factors[3] = 1.0; - Point3DF32(self.0 * factors) + Point3DF(self.0 * factors) } #[inline] @@ -330,12 +330,12 @@ impl Point3DF32 { } #[inline] - pub fn perspective_divide(self) -> Point3DF32 { - Point3DF32(self.0 * F32x4::splat(1.0 / self.w())) + pub fn perspective_divide(self) -> Point3DF { + Point3DF(self.0 * F32x4::splat(1.0 / self.w())) } #[inline] - pub fn approx_eq(&self, other: &Point3DF32, epsilon: f32) -> bool { + pub fn approx_eq(&self, other: &Point3DF, epsilon: f32) -> bool { self.0.approx_eq(other.0, epsilon) } @@ -349,39 +349,39 @@ impl Point3DF32 { } #[inline] - pub fn lerp(self, other: Point3DF32, t: f32) -> Point3DF32 { - Point3DF32(self.0 + (other.0 - self.0) * F32x4::splat(t)) + pub fn lerp(self, other: Point3DF, t: f32) -> Point3DF { + Point3DF(self.0 + (other.0 - self.0) * F32x4::splat(t)) } } -impl Add for Point3DF32 { - type Output = Point3DF32; +impl Add for Point3DF { + type Output = Point3DF; #[inline] - fn add(self, other: Point3DF32) -> Point3DF32 { - Point3DF32(self.0 + other.0) + fn add(self, other: Point3DF) -> Point3DF { + Point3DF(self.0 + other.0) } } -impl AddAssign for Point3DF32 { +impl AddAssign for Point3DF { #[inline] - fn add_assign(&mut self, other: Point3DF32) { + fn add_assign(&mut self, other: Point3DF) { self.0 += other.0 } } -impl Mul for Point3DF32 { - type Output = Point3DF32; +impl Mul for Point3DF { + type Output = Point3DF; #[inline] - fn mul(self, other: Point3DF32) -> Point3DF32 { - Point3DF32(self.0 * other.0) + fn mul(self, other: Point3DF) -> Point3DF { + Point3DF(self.0 * other.0) } } -impl Default for Point3DF32 { +impl Default for Point3DF { #[inline] - fn default() -> Point3DF32 { + fn default() -> Point3DF { let mut point = F32x4::default(); point.set_w(1.0); - Point3DF32(point) + Point3DF(point) } } diff --git a/geometry/src/basic/rect.rs b/geometry/src/basic/rect.rs index 701c6d00..95b9f752 100644 --- a/geometry/src/basic/rect.rs +++ b/geometry/src/basic/rect.rs @@ -10,50 +10,50 @@ //! 2D axis-aligned rectangles, optimized with SIMD. -use crate::basic::point::{Point2DF32, Point2DI32}; +use crate::basic::point::{Point2DF, Point2DI}; use pathfinder_simd::default::{F32x4, I32x4}; #[derive(Clone, Copy, Debug, PartialEq, Default)] -pub struct RectF32(pub F32x4); +pub struct RectF(pub F32x4); -impl RectF32 { +impl RectF { #[inline] - pub fn new(origin: Point2DF32, size: Point2DF32) -> RectF32 { - RectF32(origin.0.concat_xy_xy(origin.0 + size.0)) + pub fn new(origin: Point2DF, size: Point2DF) -> RectF { + RectF(origin.0.concat_xy_xy(origin.0 + size.0)) } #[inline] - pub fn from_points(origin: Point2DF32, lower_right: Point2DF32) -> RectF32 { - RectF32(origin.0.concat_xy_xy(lower_right.0)) + pub fn from_points(origin: Point2DF, lower_right: Point2DF) -> RectF { + RectF(origin.0.concat_xy_xy(lower_right.0)) } #[inline] - pub fn origin(&self) -> Point2DF32 { - Point2DF32(self.0) + pub fn origin(&self) -> Point2DF { + Point2DF(self.0) } #[inline] - pub fn size(&self) -> Point2DF32 { - Point2DF32(self.0.zwxy() - self.0.xyxy()) + pub fn size(&self) -> Point2DF { + Point2DF(self.0.zwxy() - self.0.xyxy()) } #[inline] - pub fn upper_right(&self) -> Point2DF32 { - Point2DF32(self.0.zyxw()) + pub fn upper_right(&self) -> Point2DF { + Point2DF(self.0.zyxw()) } #[inline] - pub fn lower_left(&self) -> Point2DF32 { - Point2DF32(self.0.xwzy()) + pub fn lower_left(&self) -> Point2DF { + Point2DF(self.0.xwzy()) } #[inline] - pub fn lower_right(&self) -> Point2DF32 { - Point2DF32(self.0.zwxy()) + pub fn lower_right(&self) -> Point2DF { + Point2DF(self.0.zwxy()) } #[inline] - pub fn contains_point(&self, point: Point2DF32) -> bool { + pub fn contains_point(&self, point: Point2DF) -> bool { // self.origin <= point && point <= self.lower_right self.0 .concat_xy_xy(point.0) @@ -62,7 +62,7 @@ impl RectF32 { } #[inline] - pub fn contains_rect(&self, other: RectF32) -> bool { + pub fn contains_rect(&self, other: RectF) -> bool { // self.origin <= other.origin && other.lower_right <= self.lower_right self.0 .concat_xy_zw(other.0) @@ -76,20 +76,20 @@ impl RectF32 { } #[inline] - pub fn union_point(&self, point: Point2DF32) -> RectF32 { - RectF32::from_points(self.origin().min(point), self.lower_right().max(point)) + pub fn union_point(&self, point: Point2DF) -> RectF { + RectF::from_points(self.origin().min(point), self.lower_right().max(point)) } #[inline] - pub fn union_rect(&self, other: RectF32) -> RectF32 { - RectF32::from_points( + pub fn union_rect(&self, other: RectF) -> RectF { + RectF::from_points( self.origin().min(other.origin()), self.lower_right().max(other.lower_right()), ) } #[inline] - pub fn intersects(&self, other: RectF32) -> bool { + pub fn intersects(&self, other: RectF) -> bool { // self.origin < other.lower_right && other.origin < self.lower_right self.0 .concat_xy_xy(other.0) @@ -98,11 +98,11 @@ impl RectF32 { } #[inline] - pub fn intersection(&self, other: RectF32) -> Option { + pub fn intersection(&self, other: RectF) -> Option { if !self.intersects(other) { None } else { - Some(RectF32::from_points( + Some(RectF::from_points( self.origin().max(other.origin()), self.lower_right().min(other.lower_right()), )) @@ -130,63 +130,63 @@ impl RectF32 { } #[inline] - pub fn scale_xy(self, factors: Point2DF32) -> RectF32 { - RectF32(self.0 * factors.0.concat_xy_xy(factors.0)) + pub fn scale_xy(self, factors: Point2DF) -> RectF { + RectF(self.0 * factors.0.concat_xy_xy(factors.0)) } #[inline] - pub fn round_out(self) -> RectF32 { - RectF32::from_points(self.origin().floor(), self.lower_right().ceil()) + pub fn round_out(self) -> RectF { + RectF::from_points(self.origin().floor(), self.lower_right().ceil()) } #[inline] - pub fn dilate(self, amount: Point2DF32) -> RectF32 { - RectF32::from_points(self.origin() - amount, self.lower_right() + amount) + pub fn dilate(self, amount: Point2DF) -> RectF { + RectF::from_points(self.origin() - amount, self.lower_right() + amount) } #[inline] - pub fn to_i32(&self) -> RectI32 { - RectI32(self.0.to_i32x4()) + pub fn to_i32(&self) -> RectI { + RectI(self.0.to_i32x4()) } } #[derive(Clone, Copy, Debug, PartialEq, Default)] -pub struct RectI32(pub I32x4); +pub struct RectI(pub I32x4); -impl RectI32 { +impl RectI { #[inline] - pub fn new(origin: Point2DI32, size: Point2DI32) -> RectI32 { - RectI32(origin.0.concat_xy_xy(origin.0 + size.0)) + pub fn new(origin: Point2DI, size: Point2DI) -> RectI { + RectI(origin.0.concat_xy_xy(origin.0 + size.0)) } #[inline] - pub fn from_points(origin: Point2DI32, lower_right: Point2DI32) -> RectI32 { - RectI32(origin.0.concat_xy_xy(lower_right.0)) + pub fn from_points(origin: Point2DI, lower_right: Point2DI) -> RectI { + RectI(origin.0.concat_xy_xy(lower_right.0)) } #[inline] - pub fn origin(&self) -> Point2DI32 { - Point2DI32(self.0) + pub fn origin(&self) -> Point2DI { + Point2DI(self.0) } #[inline] - pub fn size(&self) -> Point2DI32 { - Point2DI32(self.0.zwxy() - self.0.xyxy()) + pub fn size(&self) -> Point2DI { + Point2DI(self.0.zwxy() - self.0.xyxy()) } #[inline] - pub fn upper_right(&self) -> Point2DI32 { - Point2DI32(self.0.zyxw()) + pub fn upper_right(&self) -> Point2DI { + Point2DI(self.0.zyxw()) } #[inline] - pub fn lower_left(&self) -> Point2DI32 { - Point2DI32(self.0.xwzy()) + pub fn lower_left(&self) -> Point2DI { + Point2DI(self.0.xwzy()) } #[inline] - pub fn lower_right(&self) -> Point2DI32 { - Point2DI32(self.0.zwxy()) + pub fn lower_right(&self) -> Point2DI { + Point2DI(self.0.zwxy()) } #[inline] @@ -210,9 +210,9 @@ impl RectI32 { } #[inline] - pub fn contains_point(&self, point: Point2DI32) -> bool { + pub fn contains_point(&self, point: Point2DI) -> bool { // self.origin <= point && point <= self.lower_right - 1 - let lower_right = self.lower_right() - Point2DI32::splat(1); + let lower_right = self.lower_right() - Point2DI::splat(1); self.0 .concat_xy_xy(point.0) .packed_le(point.0.concat_xy_xy(lower_right.0)) @@ -220,7 +220,7 @@ impl RectI32 { } #[inline] - pub fn to_f32(&self) -> RectF32 { - RectF32(self.0.to_f32x4()) + pub fn to_f32(&self) -> RectF { + RectF(self.0.to_f32x4()) } } diff --git a/geometry/src/basic/transform2d.rs b/geometry/src/basic/transform2d.rs index e4c36b21..ab428e07 100644 --- a/geometry/src/basic/transform2d.rs +++ b/geometry/src/basic/transform2d.rs @@ -10,10 +10,10 @@ //! 2D affine transforms. -use crate::basic::line_segment::LineSegmentF32; -use crate::basic::point::Point2DF32; -use crate::basic::rect::RectF32; -use crate::basic::transform3d::Transform3DF32; +use crate::basic::line_segment::LineSegmentF; +use crate::basic::point::Point2DF; +use crate::basic::rect::RectF; +use crate::basic::transform3d::Transform3DF; use crate::segment::Segment; use crate::unit_vector::UnitVector; use pathfinder_simd::default::F32x4; @@ -21,60 +21,60 @@ use std::ops::Sub; /// A 2x2 matrix, optimized with SIMD, in column-major order. #[derive(Clone, Copy, Debug, PartialEq)] -pub struct Matrix2x2F32(pub F32x4); +pub struct Matrix2x2F(pub F32x4); -impl Default for Matrix2x2F32 { +impl Default for Matrix2x2F { #[inline] - fn default() -> Matrix2x2F32 { - Self::from_scale(Point2DF32::splat(1.0)) + fn default() -> Matrix2x2F { + Self::from_scale(Point2DF::splat(1.0)) } } -impl Matrix2x2F32 { +impl Matrix2x2F { #[inline] - pub fn from_scale(scale: Point2DF32) -> Matrix2x2F32 { - Matrix2x2F32(F32x4::new(scale.x(), 0.0, 0.0, scale.y())) + pub fn from_scale(scale: Point2DF) -> Matrix2x2F { + Matrix2x2F(F32x4::new(scale.x(), 0.0, 0.0, scale.y())) } #[inline] - pub fn from_rotation(theta: f32) -> Matrix2x2F32 { - Matrix2x2F32::from_rotation_vector(UnitVector::from_angle(theta)) + pub fn from_rotation(theta: f32) -> Matrix2x2F { + Matrix2x2F::from_rotation_vector(UnitVector::from_angle(theta)) } #[inline] - pub fn from_rotation_vector(vector: UnitVector) -> Matrix2x2F32 { - Matrix2x2F32((vector.0).0.xyyx() * F32x4::new(1.0, 1.0, -1.0, 1.0)) + pub fn from_rotation_vector(vector: UnitVector) -> Matrix2x2F { + Matrix2x2F((vector.0).0.xyyx() * F32x4::new(1.0, 1.0, -1.0, 1.0)) } #[inline] - pub fn row_major(m11: f32, m12: f32, m21: f32, m22: f32) -> Matrix2x2F32 { - Matrix2x2F32(F32x4::new(m11, m21, m12, m22)) + pub fn row_major(m11: f32, m12: f32, m21: f32, m22: f32) -> Matrix2x2F { + Matrix2x2F(F32x4::new(m11, m21, m12, m22)) } #[inline] - pub fn post_mul(&self, other: &Matrix2x2F32) -> Matrix2x2F32 { - Matrix2x2F32(self.0.xyxy() * other.0.xxzz() + self.0.zwzw() * other.0.yyww()) + pub fn post_mul(&self, other: &Matrix2x2F) -> Matrix2x2F { + Matrix2x2F(self.0.xyxy() * other.0.xxzz() + self.0.zwzw() * other.0.yyww()) } #[inline] - pub fn pre_mul(&self, other: &Matrix2x2F32) -> Matrix2x2F32 { + pub fn pre_mul(&self, other: &Matrix2x2F) -> Matrix2x2F { other.post_mul(self) } #[inline] - pub fn entrywise_mul(&self, other: &Matrix2x2F32) -> Matrix2x2F32 { - Matrix2x2F32(self.0 * other.0) + pub fn entrywise_mul(&self, other: &Matrix2x2F) -> Matrix2x2F { + Matrix2x2F(self.0 * other.0) } #[inline] - pub fn adjugate(&self) -> Matrix2x2F32 { - Matrix2x2F32(self.0.wyzx() * F32x4::new(1.0, -1.0, -1.0, 1.0)) + pub fn adjugate(&self) -> Matrix2x2F { + Matrix2x2F(self.0.wyzx() * F32x4::new(1.0, -1.0, -1.0, 1.0)) } #[inline] - pub fn transform_point(&self, point: Point2DF32) -> Point2DF32 { + pub fn transform_point(&self, point: Point2DF) -> Point2DF { let halves = self.0 * point.0.xxyy(); - Point2DF32(halves + halves.zwzw()) + Point2DF(halves + halves.zwzw()) } #[inline] @@ -83,8 +83,8 @@ impl Matrix2x2F32 { } #[inline] - pub fn inverse(&self) -> Matrix2x2F32 { - Matrix2x2F32(F32x4::splat(1.0 / self.det()) * self.adjugate().0) + pub fn inverse(&self) -> Matrix2x2F { + Matrix2x2F(F32x4::splat(1.0 / self.det()) * self.adjugate().0) } #[inline] @@ -105,116 +105,116 @@ impl Matrix2x2F32 { } } -impl Sub for Matrix2x2F32 { - type Output = Matrix2x2F32; +impl Sub for Matrix2x2F { + type Output = Matrix2x2F; #[inline] - fn sub(self, other: Matrix2x2F32) -> Matrix2x2F32 { - Matrix2x2F32(self.0 - other.0) + fn sub(self, other: Matrix2x2F) -> Matrix2x2F { + Matrix2x2F(self.0 - other.0) } } /// An affine transform, optimized with SIMD. #[derive(Clone, Copy, Debug, PartialEq)] -pub struct Transform2DF32 { +pub struct Transform2DF { // Row-major order. - matrix: Matrix2x2F32, - vector: Point2DF32, + matrix: Matrix2x2F, + vector: Point2DF, } -impl Default for Transform2DF32 { +impl Default for Transform2DF { #[inline] - fn default() -> Transform2DF32 { - Self::from_scale(Point2DF32::splat(1.0)) + fn default() -> Transform2DF { + Self::from_scale(Point2DF::splat(1.0)) } } -impl Transform2DF32 { +impl Transform2DF { #[inline] - pub fn from_scale(scale: Point2DF32) -> Transform2DF32 { - Transform2DF32 { - matrix: Matrix2x2F32::from_scale(scale), - vector: Point2DF32::default(), + pub fn from_scale(scale: Point2DF) -> Transform2DF { + Transform2DF { + matrix: Matrix2x2F::from_scale(scale), + vector: Point2DF::default(), } } #[inline] - pub fn from_rotation(theta: f32) -> Transform2DF32 { - Transform2DF32 { - matrix: Matrix2x2F32::from_rotation(theta), - vector: Point2DF32::default(), + pub fn from_rotation(theta: f32) -> Transform2DF { + Transform2DF { + matrix: Matrix2x2F::from_rotation(theta), + vector: Point2DF::default(), } } #[inline] - pub fn from_rotation_vector(vector: UnitVector) -> Transform2DF32 { - Transform2DF32 { - matrix: Matrix2x2F32::from_rotation_vector(vector), - vector: Point2DF32::default(), + pub fn from_rotation_vector(vector: UnitVector) -> Transform2DF { + Transform2DF { + matrix: Matrix2x2F::from_rotation_vector(vector), + vector: Point2DF::default(), } } #[inline] - pub fn from_translation(vector: Point2DF32) -> Transform2DF32 { - Transform2DF32 { matrix: Matrix2x2F32::default(), vector } + pub fn from_translation(vector: Point2DF) -> Transform2DF { + Transform2DF { matrix: Matrix2x2F::default(), vector } } #[inline] pub fn from_scale_rotation_translation( - scale: Point2DF32, + scale: Point2DF, theta: f32, - translation: Point2DF32, - ) -> Transform2DF32 { - let rotation = Transform2DF32::from_rotation(theta); - let translation = Transform2DF32::from_translation(translation); - Transform2DF32::from_scale(scale).post_mul(&rotation).post_mul(&translation) + translation: Point2DF, + ) -> Transform2DF { + let rotation = Transform2DF::from_rotation(theta); + let translation = Transform2DF::from_translation(translation); + Transform2DF::from_scale(scale).post_mul(&rotation).post_mul(&translation) } #[inline] - pub fn row_major(m11: f32, m12: f32, m21: f32, m22: f32, m31: f32, m32: f32) -> Transform2DF32 { - Transform2DF32 { - matrix: Matrix2x2F32::row_major(m11, m12, m21, m22), - vector: Point2DF32::new(m31, m32), + pub fn row_major(m11: f32, m12: f32, m21: f32, m22: f32, m31: f32, m32: f32) -> Transform2DF { + Transform2DF { + matrix: Matrix2x2F::row_major(m11, m12, m21, m22), + vector: Point2DF::new(m31, m32), } } #[inline] - pub fn transform_point(&self, point: Point2DF32) -> Point2DF32 { + pub fn transform_point(&self, point: Point2DF) -> Point2DF { self.matrix.transform_point(point) + self.vector } #[inline] - pub fn transform_line_segment(&self, line_segment: &LineSegmentF32) -> LineSegmentF32 { - LineSegmentF32::new(self.transform_point(line_segment.from()), + pub fn transform_line_segment(&self, line_segment: &LineSegmentF) -> LineSegmentF { + LineSegmentF::new(self.transform_point(line_segment.from()), self.transform_point(line_segment.to())) } #[inline] - pub fn transform_rect(&self, rect: &RectF32) -> RectF32 { + pub fn transform_rect(&self, rect: &RectF) -> RectF { let upper_left = self.transform_point(rect.origin()); let upper_right = self.transform_point(rect.upper_right()); let lower_left = self.transform_point(rect.lower_left()); let lower_right = self.transform_point(rect.lower_right()); let min_point = upper_left.min(upper_right).min(lower_left).min(lower_right); let max_point = upper_left.max(upper_right).max(lower_left).max(lower_right); - RectF32::from_points(min_point, max_point) + RectF::from_points(min_point, max_point) } #[inline] - pub fn post_mul(&self, other: &Transform2DF32) -> Transform2DF32 { + pub fn post_mul(&self, other: &Transform2DF) -> Transform2DF { let matrix = self.matrix.post_mul(&other.matrix); let vector = other.transform_point(self.vector); - Transform2DF32 { matrix, vector } + Transform2DF { matrix, vector } } #[inline] - pub fn pre_mul(&self, other: &Transform2DF32) -> Transform2DF32 { + pub fn pre_mul(&self, other: &Transform2DF) -> Transform2DF { other.post_mul(self) } // TODO(pcwalton): Optimize better with SIMD. #[inline] - pub fn to_3d(&self) -> Transform3DF32 { - Transform3DF32::row_major( + pub fn to_3d(&self) -> Transform3DF { + Transform3DF::row_major( self.matrix.0[0], self.matrix.0[1], 0.0, @@ -236,7 +236,7 @@ impl Transform2DF32 { #[inline] pub fn is_identity(&self) -> bool { - *self == Transform2DF32::default() + *self == Transform2DF::default() } #[inline] @@ -257,25 +257,25 @@ impl Transform2DF32 { } #[inline] - pub fn post_translate(&self, vector: Point2DF32) -> Transform2DF32 { - self.post_mul(&Transform2DF32::from_translation(vector)) + pub fn post_translate(&self, vector: Point2DF) -> Transform2DF { + self.post_mul(&Transform2DF::from_translation(vector)) } #[inline] - pub fn post_rotate(&self, theta: f32) -> Transform2DF32 { - self.post_mul(&Transform2DF32::from_rotation(theta)) + pub fn post_rotate(&self, theta: f32) -> Transform2DF { + self.post_mul(&Transform2DF::from_rotation(theta)) } #[inline] - pub fn post_scale(&self, scale: Point2DF32) -> Transform2DF32 { - self.post_mul(&Transform2DF32::from_scale(scale)) + pub fn post_scale(&self, scale: Point2DF) -> Transform2DF { + self.post_mul(&Transform2DF::from_scale(scale)) } /// Returns the translation part of this matrix. /// /// This decomposition assumes that scale, rotation, and translation are applied in that order. #[inline] - pub fn translation(&self) -> Point2DF32 { + pub fn translation(&self) -> Point2DF { self.vector } @@ -292,20 +292,20 @@ impl Transform2DF32 { /// This decomposition assumes that scale, rotation, and translation are applied in that order. #[inline] pub fn scale_factor(&self) -> f32 { - Point2DF32(self.matrix.0.zwxy()).length() + Point2DF(self.matrix.0.zwxy()).length() } } /// Transforms a path with a SIMD 2D transform. -pub struct Transform2DF32PathIter +pub struct Transform2DFPathIter where I: Iterator, { iter: I, - transform: Transform2DF32, + transform: Transform2DF, } -impl Iterator for Transform2DF32PathIter +impl Iterator for Transform2DFPathIter where I: Iterator, { @@ -337,13 +337,13 @@ where } } -impl Transform2DF32PathIter +impl Transform2DFPathIter where I: Iterator, { #[inline] - pub fn new(iter: I, transform: &Transform2DF32) -> Transform2DF32PathIter { - Transform2DF32PathIter { + pub fn new(iter: I, transform: &Transform2DF) -> Transform2DFPathIter { + Transform2DFPathIter { iter, transform: *transform, } diff --git a/geometry/src/basic/transform3d.rs b/geometry/src/basic/transform3d.rs index d5222d86..191e159c 100644 --- a/geometry/src/basic/transform3d.rs +++ b/geometry/src/basic/transform3d.rs @@ -10,9 +10,9 @@ //! 3D transforms that can be applied to paths. -use crate::basic::point::{Point2DF32, Point2DI32, Point3DF32}; -use crate::basic::rect::RectF32; -use crate::basic::transform2d::Matrix2x2F32; +use crate::basic::point::{Point2DF, Point2DI, Point3DF}; +use crate::basic::rect::RectF; +use crate::basic::transform2d::Matrix2x2F; use crate::segment::Segment; use pathfinder_simd::default::F32x4; use std::ops::{Add, Neg}; @@ -22,17 +22,17 @@ use std::ops::{Add, Neg}; /// In column-major order. #[derive(Clone, Copy, Debug, PartialEq)] #[repr(C)] -pub struct Transform3DF32 { +pub struct Transform3DF { pub c0: F32x4, pub c1: F32x4, pub c2: F32x4, pub c3: F32x4, } -impl Default for Transform3DF32 { +impl Default for Transform3DF { #[inline] - fn default() -> Transform3DF32 { - Transform3DF32 { + fn default() -> Transform3DF { + Transform3DF { c0: F32x4::new(1.0, 0.0, 0.0, 0.0), c1: F32x4::new(0.0, 1.0, 0.0, 0.0), c2: F32x4::new(0.0, 0.0, 1.0, 0.0), @@ -41,7 +41,7 @@ impl Default for Transform3DF32 { } } -impl Transform3DF32 { +impl Transform3DF { #[inline] pub fn row_major( m00: f32, @@ -60,8 +60,8 @@ impl Transform3DF32 { m31: f32, m32: f32, m33: f32, - ) -> Transform3DF32 { - Transform3DF32 { + ) -> Transform3DF { + Transform3DF { c0: F32x4::new(m00, m10, m20, m30), c1: F32x4::new(m01, m11, m21, m31), c2: F32x4::new(m02, m12, m22, m32), @@ -70,26 +70,26 @@ impl Transform3DF32 { } #[inline] - pub fn from_scale(x: f32, y: f32, z: f32) -> Transform3DF32 { - Transform3DF32::row_major( + pub fn from_scale(x: f32, y: f32, z: f32) -> Transform3DF { + Transform3DF::row_major( x, 0.0, 0.0, 0.0, 0.0, y, 0.0, 0.0, 0.0, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, ) } #[inline] - pub fn from_uniform_scale(factor: f32) -> Transform3DF32 { - Transform3DF32::from_scale(factor, factor, factor) + pub fn from_uniform_scale(factor: f32) -> Transform3DF { + Transform3DF::from_scale(factor, factor, factor) } #[inline] - pub fn from_translation(x: f32, y: f32, z: f32) -> Transform3DF32 { - Transform3DF32::row_major( + pub fn from_translation(x: f32, y: f32, z: f32) -> Transform3DF { + Transform3DF::row_major( 1.0, 0.0, 0.0, x, 0.0, 1.0, 0.0, y, 0.0, 0.0, 1.0, z, 0.0, 0.0, 0.0, 1.0, ) } // TODO(pcwalton): Optimize. - pub fn from_rotation(yaw: f32, pitch: f32, roll: f32) -> Transform3DF32 { + pub fn from_rotation(yaw: f32, pitch: f32, roll: f32) -> Transform3DF { let (cos_b, sin_b) = (yaw.cos(), yaw.sin()); let (cos_c, sin_c) = (pitch.cos(), pitch.sin()); let (cos_a, sin_a) = (roll.cos(), roll.sin()); @@ -102,7 +102,7 @@ impl Transform3DF32 { let m20 = -sin_b; let m21 = cos_b * sin_c; let m22 = cos_b * cos_c; - Transform3DF32::row_major( + Transform3DF::row_major( m00, m01, m02, 0.0, m10, m11, m12, 0.0, m20, m21, m22, 0.0, 0.0, 0.0, 0.0, 1.0, ) } @@ -111,7 +111,7 @@ impl Transform3DF32 { /// /// The quaternion is expected to be packed into a SIMD type (x, y, z, w) corresponding to /// x + yi + zj + wk. - pub fn from_rotation_quaternion(q: F32x4) -> Transform3DF32 { + pub fn from_rotation_quaternion(q: F32x4) -> Transform3DF { // TODO(pcwalton): Optimize better with more shuffles. let (mut sq, mut w, mut xy_xz_yz) = (q * q, q.wwww() * q, q.xxyy() * q.yzzy()); sq += sq; @@ -120,7 +120,7 @@ impl Transform3DF32 { let diag = F32x4::splat(1.0) - (sq.yxxy() + sq.zzyy()); let (wx2, wy2, wz2) = (w.x(), w.y(), w.z()); let (xy2, xz2, yz2) = (xy_xz_yz.x(), xy_xz_yz.y(), xy_xz_yz.z()); - Transform3DF32::row_major( + Transform3DF::row_major( diag.x(), xy2 - wz2, xz2 + wy2, @@ -149,14 +149,14 @@ impl Transform3DF32 { top: f32, near_val: f32, far_val: f32, - ) -> Transform3DF32 { + ) -> Transform3DF { let x_inv = 1.0 / (right - left); let y_inv = 1.0 / (top - bottom); let z_inv = 1.0 / (far_val - near_val); let tx = -(right + left) * x_inv; let ty = -(top + bottom) * y_inv; let tz = -(far_val + near_val) * z_inv; - Transform3DF32::row_major( + Transform3DF::row_major( 2.0 * x_inv, 0.0, 0.0, @@ -178,7 +178,7 @@ impl Transform3DF32 { /// Just like `gluPerspective()`. #[inline] - pub fn from_perspective(fov_y: f32, aspect: f32, z_near: f32, z_far: f32) -> Transform3DF32 { + pub fn from_perspective(fov_y: f32, aspect: f32, z_near: f32, z_far: f32) -> Transform3DF { let f = 1.0 / (fov_y * 0.5).tan(); let z_denom = 1.0 / (z_near - z_far); let m00 = f / aspect; @@ -186,7 +186,7 @@ impl Transform3DF32 { let m22 = (z_far + z_near) * z_denom; let m23 = 2.0 * z_far * z_near * z_denom; let m32 = -1.0; - Transform3DF32::row_major( + Transform3DF::row_major( m00, 0.0, 0.0, 0.0, 0.0, m11, 0.0, 0.0, 0.0, 0.0, m22, m23, 0.0, 0.0, m32, 0.0, ) } @@ -197,12 +197,12 @@ impl Transform3DF32 { // +- -+ #[inline] pub fn from_submatrices( - a: Matrix2x2F32, - b: Matrix2x2F32, - c: Matrix2x2F32, - d: Matrix2x2F32, - ) -> Transform3DF32 { - Transform3DF32 { + a: Matrix2x2F, + b: Matrix2x2F, + c: Matrix2x2F, + d: Matrix2x2F, + ) -> Transform3DF { + Transform3DF { c0: a.0.concat_xy_xy(c.0), c1: a.0.concat_zw_zw(c.0), c2: b.0.concat_xy_xy(d.0), @@ -215,15 +215,15 @@ impl Transform3DF32 { // // https://stackoverflow.com/a/18508113 #[inline] - pub fn pre_mul(&self, other: &Transform3DF32) -> Transform3DF32 { - return Transform3DF32 { + pub fn pre_mul(&self, other: &Transform3DF) -> Transform3DF { + return Transform3DF { c0: mul_col(self.c0, other), c1: mul_col(self.c1, other), c2: mul_col(self.c2, other), c3: mul_col(self.c3, other), }; - fn mul_col(a_col: F32x4, b: &Transform3DF32) -> F32x4 { + fn mul_col(a_col: F32x4, b: &Transform3DF) -> F32x4 { let (a0, a1) = (F32x4::splat(a_col[0]), F32x4::splat(a_col[1])); let (a2, a3) = (F32x4::splat(a_col[2]), F32x4::splat(a_col[3])); a0 * b.c0 + a1 * b.c1 + a2 * b.c2 + a3 * b.c3 @@ -231,44 +231,44 @@ impl Transform3DF32 { } #[inline] - pub fn post_mul(&self, other: &Transform3DF32) -> Transform3DF32 { + pub fn post_mul(&self, other: &Transform3DF) -> Transform3DF { other.pre_mul(self) } #[inline] - pub fn transform_point(&self, point: Point3DF32) -> Point3DF32 { + pub fn transform_point(&self, point: Point3DF) -> Point3DF { let term0 = self.c0 * F32x4::splat(point.x()); let term1 = self.c1 * F32x4::splat(point.y()); let term2 = self.c2 * F32x4::splat(point.z()); let term3 = self.c3 * F32x4::splat(point.w()); - Point3DF32(term0 + term1 + term2 + term3) + Point3DF(term0 + term1 + term2 + term3) } #[inline] - pub fn upper_left(&self) -> Matrix2x2F32 { - Matrix2x2F32(self.c0.concat_xy_xy(self.c1)) + pub fn upper_left(&self) -> Matrix2x2F { + Matrix2x2F(self.c0.concat_xy_xy(self.c1)) } #[inline] - pub fn upper_right(&self) -> Matrix2x2F32 { - Matrix2x2F32(self.c2.concat_xy_xy(self.c3)) + pub fn upper_right(&self) -> Matrix2x2F { + Matrix2x2F(self.c2.concat_xy_xy(self.c3)) } #[inline] - pub fn lower_left(&self) -> Matrix2x2F32 { - Matrix2x2F32(self.c0.concat_zw_zw(self.c1)) + pub fn lower_left(&self) -> Matrix2x2F { + Matrix2x2F(self.c0.concat_zw_zw(self.c1)) } #[inline] - pub fn lower_right(&self) -> Matrix2x2F32 { - Matrix2x2F32(self.c2.concat_zw_zw(self.c3)) + pub fn lower_right(&self) -> Matrix2x2F { + Matrix2x2F(self.c2.concat_zw_zw(self.c3)) } // https://en.wikipedia.org/wiki/Invertible_matrix#Blockwise_inversion // // If A is the upper left submatrix of this matrix, this method assumes that A and the Schur // complement of A are invertible. - pub fn inverse(&self) -> Transform3DF32 { + pub fn inverse(&self) -> Transform3DF { // Extract submatrices. let (a, b) = (self.upper_left(), self.upper_right()); let (c, d) = (self.lower_left(), self.lower_right()); @@ -284,10 +284,10 @@ impl Transform3DF32 { let (c_new, d_new) = ((-y).post_mul(&x), y); // Construct inverse. - Transform3DF32::from_submatrices(a_new, b_new, c_new, d_new) + Transform3DF::from_submatrices(a_new, b_new, c_new, d_new) } - pub fn approx_eq(&self, other: &Transform3DF32, epsilon: f32) -> bool { + pub fn approx_eq(&self, other: &Transform3DF, epsilon: f32) -> bool { self.c0.approx_eq(other.c0, epsilon) && self.c1.approx_eq(other.c1, epsilon) && self.c2.approx_eq(other.c2, epsilon) @@ -300,31 +300,31 @@ impl Transform3DF32 { } } -impl Add for Matrix2x2F32 { - type Output = Matrix2x2F32; +impl Add for Matrix2x2F { + type Output = Matrix2x2F; #[inline] - fn add(self, other: Matrix2x2F32) -> Matrix2x2F32 { - Matrix2x2F32(self.0 + other.0) + fn add(self, other: Matrix2x2F) -> Matrix2x2F { + Matrix2x2F(self.0 + other.0) } } -impl Neg for Matrix2x2F32 { - type Output = Matrix2x2F32; +impl Neg for Matrix2x2F { + type Output = Matrix2x2F; #[inline] - fn neg(self) -> Matrix2x2F32 { - Matrix2x2F32(-self.0) + fn neg(self) -> Matrix2x2F { + Matrix2x2F(-self.0) } } #[derive(Clone, Copy, Debug)] pub struct Perspective { - pub transform: Transform3DF32, - pub window_size: Point2DI32, + pub transform: Transform3DF, + pub window_size: Point2DI, } impl Perspective { #[inline] - pub fn new(transform: &Transform3DF32, window_size: Point2DI32) -> Perspective { + pub fn new(transform: &Transform3DF, window_size: Point2DI) -> Perspective { Perspective { transform: *transform, window_size, @@ -332,30 +332,30 @@ impl Perspective { } #[inline] - pub fn transform_point_2d(&self, point: &Point2DF32) -> Point2DF32 { + pub fn transform_point_2d(&self, point: &Point2DF) -> Point2DF { let point = self .transform .transform_point(point.to_3d()) .perspective_divide() .to_2d() - * Point2DF32::new(1.0, -1.0); - (point + Point2DF32::splat(1.0)) * self.window_size.to_f32().scale(0.5) + * Point2DF::new(1.0, -1.0); + (point + Point2DF::splat(1.0)) * self.window_size.to_f32().scale(0.5) } // TODO(pcwalton): SIMD? #[inline] - pub fn transform_rect(&self, rect: RectF32) -> RectF32 { + pub fn transform_rect(&self, rect: RectF) -> RectF { let upper_left = self.transform_point_2d(&rect.origin()); let upper_right = self.transform_point_2d(&rect.upper_right()); let lower_left = self.transform_point_2d(&rect.lower_left()); let lower_right = self.transform_point_2d(&rect.lower_right()); let min_point = upper_left.min(upper_right).min(lower_left).min(lower_right); let max_point = upper_left.max(upper_right).max(lower_left).max(lower_right); - RectF32::from_points(min_point, max_point) + RectF::from_points(min_point, max_point) } #[inline] - pub fn post_mul(&self, other: &Transform3DF32) -> Perspective { + pub fn post_mul(&self, other: &Transform3DF) -> Perspective { Perspective { transform: self.transform.post_mul(other), window_size: self.window_size, @@ -420,18 +420,18 @@ where #[cfg(test)] mod test { - use crate::basic::point::Point3DF32; - use crate::basic::transform3d::Transform3DF32; + use crate::basic::point::Point3DF; + use crate::basic::transform3d::Transform3DF; #[test] fn test_post_mul() { - let a = Transform3DF32::row_major( + let a = Transform3DF::row_major( 3.0, 1.0, 4.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0, 8.0, 9.0, 7.0, 9.0, 3.0, 2.0, ); - let b = Transform3DF32::row_major( + let b = Transform3DF::row_major( 3.0, 8.0, 4.0, 6.0, 2.0, 6.0, 4.0, 3.0, 3.0, 8.0, 3.0, 2.0, 7.0, 9.0, 5.0, 0.0, ); - let c = Transform3DF32::row_major( + let c = Transform3DF::row_major( 58.0, 107.0, 53.0, 29.0, 84.0, 177.0, 87.0, 72.0, 106.0, 199.0, 101.0, 49.0, 62.0, 152.0, 83.0, 75.0, ); @@ -440,13 +440,13 @@ mod test { #[test] fn test_pre_mul() { - let a = Transform3DF32::row_major( + let a = Transform3DF::row_major( 3.0, 1.0, 4.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0, 8.0, 9.0, 7.0, 9.0, 3.0, 2.0, ); - let b = Transform3DF32::row_major( + let b = Transform3DF::row_major( 3.0, 8.0, 4.0, 6.0, 2.0, 6.0, 4.0, 3.0, 3.0, 8.0, 3.0, 2.0, 7.0, 9.0, 5.0, 0.0, ); - let c = Transform3DF32::row_major( + let c = Transform3DF::row_major( 135.0, 93.0, 110.0, 103.0, 93.0, 61.0, 85.0, 82.0, 104.0, 52.0, 90.0, 86.0, 117.0, 50.0, 122.0, 125.0, ); @@ -455,26 +455,26 @@ mod test { #[test] fn test_transform_point() { - let a = Transform3DF32::row_major( + let a = Transform3DF::row_major( 3.0, 1.0, 4.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0, 8.0, 9.0, 7.0, 9.0, 3.0, 2.0, ); - let p = Point3DF32::new(3.0, 8.0, 4.0, 6.0); - let q = Point3DF32::new(63.0, 97.0, 135.0, 117.0); + let p = Point3DF::new(3.0, 8.0, 4.0, 6.0); + let q = Point3DF::new(63.0, 97.0, 135.0, 117.0); assert_eq!(a.transform_point(p), q); } #[test] fn test_inverse() { // Random matrix. - let m = Transform3DF32::row_major( + let m = Transform3DF::row_major( 0.86277982, 0.15986552, 0.90739898, 0.60066808, 0.17386167, 0.016353, 0.8535783, 0.12969608, 0.0946466, 0.43248631, 0.63480505, 0.08154603, 0.50305436, 0.48359687, 0.51057162, 0.24812012, ); - let p0 = Point3DF32::new(0.95536648, 0.80633691, 0.16357357, 0.5477598); + let p0 = Point3DF::new(0.95536648, 0.80633691, 0.16357357, 0.5477598); let p1 = m.transform_point(p0); let m_inv = m.inverse(); - let m_inv_exp = Transform3DF32::row_major( + let m_inv_exp = Transform3DF::row_major( -2.47290136, 3.48865688, -6.12298336, diff --git a/geometry/src/clip.rs b/geometry/src/clip.rs index 315b8bd9..576dfc2d 100644 --- a/geometry/src/clip.rs +++ b/geometry/src/clip.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use crate::basic::line_segment::LineSegmentF32; -use crate::basic::point::{Point2DF32, Point3DF32}; -use crate::basic::rect::RectF32; +use crate::basic::line_segment::LineSegmentF; +use crate::basic::point::{Point2DF, Point3DF}; +use crate::basic::rect::RectF; use crate::outline::{Contour, PointFlags}; use crate::segment::{CubicSegment, Segment}; use crate::util::lerp; @@ -20,17 +20,17 @@ use std::fmt::Debug; use std::mem; #[derive(Clone, Copy, Debug)] -struct Edge(LineSegmentF32); +struct Edge(LineSegmentF); impl TEdge for Edge { #[inline] - fn point_is_inside(&self, point: &Point2DF32) -> bool { + fn point_is_inside(&self, point: &Point2DF) -> bool { let area = (self.0.to() - self.0.from()).det(*point - self.0.from()); debug!("point_is_inside({:?}, {:?}), area={}", self, point, area); area >= 0.0 } - fn intersect_line_segment(&self, segment: &LineSegmentF32) -> ArrayVec<[f32; 3]> { + fn intersect_line_segment(&self, segment: &LineSegmentF) -> ArrayVec<[f32; 3]> { let mut results = ArrayVec::new(); if let Some(t) = segment.intersection_t(&self.0) { if t >= 0.0 && t <= 1.0 { @@ -51,7 +51,7 @@ enum AxisAlignedEdge { impl TEdge for AxisAlignedEdge { #[inline] - fn point_is_inside(&self, point: &Point2DF32) -> bool { + fn point_is_inside(&self, point: &Point2DF) -> bool { match *self { AxisAlignedEdge::Left(x) => point.x() >= x, AxisAlignedEdge::Top(y) => point.y() >= y, @@ -60,7 +60,7 @@ impl TEdge for AxisAlignedEdge { } } - fn intersect_line_segment(&self, segment: &LineSegmentF32) -> ArrayVec<[f32; 3]> { + fn intersect_line_segment(&self, segment: &LineSegmentF) -> ArrayVec<[f32; 3]> { let mut results = ArrayVec::new(); let t = match *self { AxisAlignedEdge::Left(x) | AxisAlignedEdge::Right(x) => segment.solve_t_for_x(x), @@ -74,8 +74,8 @@ impl TEdge for AxisAlignedEdge { } trait TEdge: Debug { - fn point_is_inside(&self, point: &Point2DF32) -> bool; - fn intersect_line_segment(&self, segment: &LineSegmentF32) -> ArrayVec<[f32; 3]>; + fn point_is_inside(&self, point: &Point2DF) -> bool; + fn intersect_line_segment(&self, segment: &LineSegmentF) -> ArrayVec<[f32; 3]>; fn trivially_test_segment(&self, segment: &Segment) -> EdgeRelativeLocation { let from_inside = self.point_is_inside(&segment.baseline.from()); @@ -294,7 +294,7 @@ enum FastClipResult { // General convex polygon clipping in 2D pub(crate) struct ContourPolygonClipper { - clip_polygon: SmallVec<[Point2DF32; 4]>, + clip_polygon: SmallVec<[Point2DF; 4]>, contour: Contour, } @@ -309,7 +309,7 @@ impl ContourClipper for ContourPolygonClipper { impl ContourPolygonClipper { #[inline] - pub(crate) fn new(clip_polygon: &[Point2DF32], contour: Contour) -> ContourPolygonClipper { + pub(crate) fn new(clip_polygon: &[Point2DF], contour: Contour) -> ContourPolygonClipper { ContourPolygonClipper { clip_polygon: SmallVec::from_slice(clip_polygon), contour, @@ -325,7 +325,7 @@ impl ContourPolygonClipper { Some(prev) => *prev, }; for &next in &clip_polygon { - self.clip_against(Edge(LineSegmentF32::new(prev, next))); + self.clip_against(Edge(LineSegmentF::new(prev, next))); prev = next; } @@ -343,7 +343,7 @@ enum EdgeRelativeLocation { // Fast axis-aligned box 2D clipping pub(crate) struct ContourRectClipper { - clip_rect: RectF32, + clip_rect: RectF, contour: Contour, } @@ -358,7 +358,7 @@ impl ContourClipper for ContourRectClipper { impl ContourRectClipper { #[inline] - pub(crate) fn new(clip_rect: RectF32, contour: Contour) -> ContourRectClipper { + pub(crate) fn new(clip_rect: RectF, contour: Contour) -> ContourRectClipper { ContourRectClipper { clip_rect, contour } } @@ -379,16 +379,16 @@ impl ContourRectClipper { // 3D quad clipping pub struct PolygonClipper3D { - subject: Vec, + subject: Vec, } impl PolygonClipper3D { #[inline] - pub fn new(subject: Vec) -> PolygonClipper3D { + pub fn new(subject: Vec) -> PolygonClipper3D { PolygonClipper3D { subject } } - pub fn clip(mut self) -> Vec { + pub fn clip(mut self) -> Vec { // TODO(pcwalton): Fast path for completely contained polygon? debug!("before clipping against bottom: {:?}", self.subject); @@ -440,7 +440,7 @@ enum Edge3D { impl Edge3D { #[inline] - fn point_is_inside(self, point: Point3DF32) -> bool { + fn point_is_inside(self, point: Point3DF) -> bool { let w = point.w(); match self { Edge3D::Left => point.x() >= -w, @@ -453,7 +453,7 @@ impl Edge3D { } // Blinn & Newell, "Clipping using homogeneous coordinates", SIGGRAPH 1978. - fn line_intersection(self, prev: Point3DF32, next: Point3DF32) -> Point3DF32 { + fn line_intersection(self, prev: Point3DF, next: Point3DF) -> Point3DF { let (x0, x1) = match self { Edge3D::Left | Edge3D::Right => (prev.x(), next.x()), Edge3D::Bottom | Edge3D::Top => (prev.y(), next.y()), @@ -472,7 +472,7 @@ impl Edge3D { /// Coarse collision detection // Separating axis theorem. Requires that the polygon be convex. -pub(crate) fn rect_is_outside_polygon(rect: RectF32, polygon_points: &[Point2DF32]) -> bool { +pub(crate) fn rect_is_outside_polygon(rect: RectF, polygon_points: &[Point2DF]) -> bool { let mut outcode = Outcode::all(); for point in polygon_points { if point.x() > rect.min_x() { @@ -519,7 +519,7 @@ pub(crate) fn rect_is_outside_polygon(rect: RectF32, polygon_points: &[Point2DF3 } // Edge equation method. Requires that the polygon be convex. -pub(crate) fn rect_is_inside_polygon(rect: RectF32, polygon_points: &[Point2DF32]) -> bool { +pub(crate) fn rect_is_inside_polygon(rect: RectF, polygon_points: &[Point2DF]) -> bool { // FIXME(pcwalton): Check winding! let rect_points = [ rect.origin(), diff --git a/geometry/src/dilation.rs b/geometry/src/dilation.rs index beeac163..961f687f 100644 --- a/geometry/src/dilation.rs +++ b/geometry/src/dilation.rs @@ -8,20 +8,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use crate::basic::point::Point2DF32; +use crate::basic::point::Point2DF; use crate::orientation::Orientation; use crate::outline::Contour; pub struct ContourDilator<'a> { contour: &'a mut Contour, - amount: Point2DF32, + amount: Point2DF, orientation: Orientation, } impl<'a> ContourDilator<'a> { pub fn new( contour: &'a mut Contour, - amount: Point2DF32, + amount: Point2DF, orientation: Orientation, ) -> ContourDilator<'a> { ContourDilator { @@ -34,8 +34,8 @@ impl<'a> ContourDilator<'a> { pub fn dilate(&mut self) { // Determine orientation. let scale = self.amount.scale_xy(match self.orientation { - Orientation::Ccw => Point2DF32::new(1.0, -1.0), - Orientation::Cw => Point2DF32::new(-1.0, 1.0), + Orientation::Ccw => Point2DF::new(1.0, -1.0), + Orientation::Cw => Point2DF::new(-1.0, 1.0), }); // Find the starting and previous positions. @@ -84,7 +84,7 @@ impl<'a> ContourDilator<'a> { let bisector = prev_vector.yx() + next_vector.yx(); let bisector_length = bisector.length(); let scaled_bisector = if bisector_length == 0.0 { - Point2DF32::default() + Point2DF::default() } else { bisector.scale_xy(scale).scale(1.0 / bisector_length) }; diff --git a/geometry/src/outline.rs b/geometry/src/outline.rs index aced08ef..ab668e7d 100644 --- a/geometry/src/outline.rs +++ b/geometry/src/outline.rs @@ -10,10 +10,10 @@ //! A compressed in-memory representation of paths. -use crate::basic::line_segment::LineSegmentF32; -use crate::basic::point::Point2DF32; -use crate::basic::rect::RectF32; -use crate::basic::transform2d::Transform2DF32; +use crate::basic::line_segment::LineSegmentF; +use crate::basic::point::Point2DF; +use crate::basic::rect::RectF; +use crate::basic::transform2d::Transform2DF; use crate::basic::transform3d::Perspective; use crate::clip::{self, ContourPolygonClipper, ContourRectClipper}; use crate::dilation::ContourDilator; @@ -27,14 +27,14 @@ use std::mem; #[derive(Clone)] pub struct Outline { pub(crate) contours: Vec, - pub(crate) bounds: RectF32, + pub(crate) bounds: RectF, } #[derive(Clone)] pub struct Contour { - pub(crate) points: Vec, + pub(crate) points: Vec, pub(crate) flags: Vec, - pub(crate) bounds: RectF32, + pub(crate) bounds: RectF, pub(crate) closed: bool, } @@ -50,7 +50,7 @@ impl Outline { pub fn new() -> Outline { Outline { contours: vec![], - bounds: RectF32::default(), + bounds: RectF::default(), } } @@ -104,7 +104,7 @@ impl Outline { } #[inline] - pub fn bounds(&self) -> RectF32 { + pub fn bounds(&self) -> RectF { self.bounds } @@ -127,7 +127,7 @@ impl Outline { self.contours.push(contour); } - pub fn transform(&mut self, transform: &Transform2DF32) { + pub fn transform(&mut self, transform: &Transform2DF) { if transform.is_identity() { return; } @@ -137,7 +137,7 @@ impl Outline { contour.transform(transform); contour.update_bounds(&mut new_bounds); } - self.bounds = new_bounds.unwrap_or_else(|| RectF32::default()); + self.bounds = new_bounds.unwrap_or_else(|| RectF::default()); } pub fn apply_perspective(&mut self, perspective: &Perspective) { @@ -146,10 +146,10 @@ impl Outline { contour.apply_perspective(perspective); contour.update_bounds(&mut new_bounds); } - self.bounds = new_bounds.unwrap_or_else(|| RectF32::default()); + self.bounds = new_bounds.unwrap_or_else(|| RectF::default()); } - pub fn dilate(&mut self, amount: Point2DF32) { + pub fn dilate(&mut self, amount: Point2DF) { let orientation = Orientation::from_outline(self); self.contours .iter_mut() @@ -157,25 +157,25 @@ impl Outline { self.bounds = self.bounds.dilate(amount); } - pub fn prepare_for_tiling(&mut self, view_box: RectF32) { + pub fn prepare_for_tiling(&mut self, view_box: RectF) { self.contours .iter_mut() .for_each(|contour| contour.prepare_for_tiling(view_box)); self.bounds = self .bounds .intersection(view_box) - .unwrap_or_else(|| RectF32::default()); + .unwrap_or_else(|| RectF::default()); } - pub fn is_outside_polygon(&self, clip_polygon: &[Point2DF32]) -> bool { + pub fn is_outside_polygon(&self, clip_polygon: &[Point2DF]) -> bool { clip::rect_is_outside_polygon(self.bounds, clip_polygon) } - fn is_inside_polygon(&self, clip_polygon: &[Point2DF32]) -> bool { + fn is_inside_polygon(&self, clip_polygon: &[Point2DF]) -> bool { clip::rect_is_inside_polygon(self.bounds, clip_polygon) } - pub fn clip_against_polygon(&mut self, clip_polygon: &[Point2DF32]) { + pub fn clip_against_polygon(&mut self, clip_polygon: &[Point2DF]) { // Quick check. if self.is_inside_polygon(clip_polygon) { return; @@ -186,7 +186,7 @@ impl Outline { } } - pub fn clip_against_rect(&mut self, clip_rect: RectF32) { + pub fn clip_against_rect(&mut self, clip_rect: RectF) { if clip_rect.contains_rect(self.bounds) { return; } @@ -215,7 +215,7 @@ impl Contour { Contour { points: vec![], flags: vec![], - bounds: RectF32::default(), + bounds: RectF::default(), closed: false, } } @@ -229,7 +229,7 @@ impl Contour { Contour { points: Vec::with_capacity(length), flags: Vec::with_capacity(length), - bounds: RectF32::default(), + bounds: RectF::default(), closed: false, }, ) @@ -254,7 +254,7 @@ impl Contour { } #[inline] - pub fn bounds(&self) -> RectF32 { + pub fn bounds(&self) -> RectF { self.bounds } @@ -264,33 +264,33 @@ impl Contour { } #[inline] - pub fn position_of(&self, index: u32) -> Point2DF32 { + pub fn position_of(&self, index: u32) -> Point2DF { self.points[index as usize] } #[inline] - pub(crate) fn position_of_last(&self, index: u32) -> Point2DF32 { + pub(crate) fn position_of_last(&self, index: u32) -> Point2DF { self.points[self.points.len() - index as usize] } #[inline] - pub(crate) fn last_position(&self) -> Option { + pub(crate) fn last_position(&self) -> Option { self.points.last().cloned() } #[inline] - pub fn push_endpoint(&mut self, point: Point2DF32) { + pub fn push_endpoint(&mut self, point: Point2DF) { self.push_point(point, PointFlags::empty(), true); } #[inline] - pub fn push_quadratic(&mut self, ctrl: Point2DF32, point: Point2DF32) { + pub fn push_quadratic(&mut self, ctrl: Point2DF, point: Point2DF) { self.push_point(ctrl, PointFlags::CONTROL_POINT_0, true); self.push_point(point, PointFlags::empty(), true); } #[inline] - pub fn push_cubic(&mut self, ctrl0: Point2DF32, ctrl1: Point2DF32, point: Point2DF32) { + pub fn push_cubic(&mut self, ctrl0: Point2DF, ctrl1: Point2DF, point: Point2DF) { self.push_point(ctrl0, PointFlags::CONTROL_POINT_0, true); self.push_point(ctrl1, PointFlags::CONTROL_POINT_1, true); self.push_point(point, PointFlags::empty(), true); @@ -304,7 +304,7 @@ impl Contour { // TODO(pcwalton): SIMD. #[inline] pub(crate) fn push_point(&mut self, - point: Point2DF32, + point: Point2DF, flags: PointFlags, update_bounds: bool) { debug_assert!(!point.x().is_nan() && !point.y().is_nan()); @@ -368,22 +368,22 @@ impl Contour { self.push_point(segment.baseline.to(), PointFlags::empty(), update_bounds); } - pub fn push_arc(&mut self, center: Point2DF32, radius: f32, start_angle: f32, end_angle: f32) { - let start = Point2DF32::new(f32::cos(start_angle), f32::sin(start_angle)).scale(radius); - let end = Point2DF32::new(f32::cos(end_angle), f32::sin(end_angle)).scale(radius); - let chord = LineSegmentF32::new(start, end).translate(center); + pub fn push_arc(&mut self, center: Point2DF, radius: f32, start_angle: f32, end_angle: f32) { + let start = Point2DF::new(f32::cos(start_angle), f32::sin(start_angle)).scale(radius); + let end = Point2DF::new(f32::cos(end_angle), f32::sin(end_angle)).scale(radius); + let chord = LineSegmentF::new(start, end).translate(center); let full_circle = end_angle - start_angle >= PI * 2.0; self.push_arc_from_chord_full(center, chord, full_circle); } #[inline] - pub fn push_arc_from_chord(&mut self, center: Point2DF32, chord: LineSegmentF32) { + pub fn push_arc_from_chord(&mut self, center: Point2DF, chord: LineSegmentF) { self.push_arc_from_chord_full(center, chord, false); } fn push_arc_from_chord_full(&mut self, - center: Point2DF32, - mut chord: LineSegmentF32, + center: Point2DF, + mut chord: LineSegmentF, full_circle: bool) { chord = chord.translate(-center); let radius = chord.from().length(); @@ -393,8 +393,8 @@ impl Contour { debug_assert!(f32::abs(vector.0.length() - 1.0) < EPSILON); debug_assert!(f32::abs(end_vector.0.length() - 1.0) < EPSILON); - let scale = Transform2DF32::from_scale(Point2DF32::splat(radius)); - let translation = Transform2DF32::from_translation(center); + let scale = Transform2DF::from_scale(Point2DF::splat(radius)); + let translation = Transform2DF::from_translation(center); let mut first_segment = true; loop { @@ -402,12 +402,12 @@ impl Contour { let last = !(full_circle && first_segment) && sweep_vector.0.x() >= -EPSILON && sweep_vector.0.y() >= -EPSILON; if !last { - sweep_vector = UnitVector(Point2DF32::new(0.0, 1.0)); + sweep_vector = UnitVector(Point2DF::new(0.0, 1.0)); } let mut segment = Segment::arc_from_cos(sweep_vector.0.x()); let rotation = - Transform2DF32::from_rotation_vector(sweep_vector.halve_angle().rotate_by(vector)); + Transform2DF::from_rotation_vector(sweep_vector.halve_angle().rotate_by(vector)); segment = segment.transform(&scale.post_mul(&rotation).post_mul(&translation)); if first_segment { @@ -458,9 +458,9 @@ impl Contour { } #[inline] - pub fn hull_segment_after(&self, prev_point_index: u32) -> LineSegmentF32 { + pub fn hull_segment_after(&self, prev_point_index: u32) -> LineSegmentF { let next_point_index = self.next_point_index_of(prev_point_index); - LineSegmentF32::new( + LineSegmentF::new( self.points[prev_point_index as usize], self.points[next_point_index as usize], ) @@ -526,7 +526,7 @@ impl Contour { } } - pub fn transform(&mut self, transform: &Transform2DF32) { + pub fn transform(&mut self, transform: &Transform2DF) { if transform.is_identity() { return; } @@ -544,12 +544,12 @@ impl Contour { } } - pub fn dilate(&mut self, amount: Point2DF32, orientation: Orientation) { + pub fn dilate(&mut self, amount: Point2DF, orientation: Orientation) { ContourDilator::new(self, amount, orientation).dilate(); self.bounds = self.bounds.dilate(amount); } - fn prepare_for_tiling(&mut self, view_box: RectF32) { + fn prepare_for_tiling(&mut self, view_box: RectF) { // Snap points to the view box bounds. This mops up floating point error from the clipping // process. let (mut last_endpoint_index, mut contour_is_monotonic) = (None, true); @@ -576,7 +576,7 @@ impl Contour { self.bounds = self .bounds .intersection(view_box) - .unwrap_or_else(|| RectF32::default()); + .unwrap_or_else(|| RectF::default()); } fn make_monotonic(&mut self) { @@ -598,7 +598,7 @@ impl Contour { } else { point_index }; - let baseline = LineSegmentF32::new( + let baseline = LineSegmentF::new( contour.points[last_endpoint_index as usize], contour.points[position_index as usize], ); @@ -614,7 +614,7 @@ impl Contour { let first_ctrl_point_index = last_endpoint_index as usize + 1; let ctrl_position_0 = &contour.points[first_ctrl_point_index + 0]; let ctrl_position_1 = &contour.points[first_ctrl_point_index + 1]; - let ctrl = LineSegmentF32::new(*ctrl_position_0, *ctrl_position_1); + let ctrl = LineSegmentF::new(*ctrl_position_0, *ctrl_position_1); handle_cubic(self, Segment::cubic(&baseline, &ctrl)); } @@ -694,7 +694,7 @@ impl Contour { // Use this function to keep bounds up to date when mutating paths. See `Outline::transform()` // for an example of use. - pub(crate) fn update_bounds(&self, bounds: &mut Option) { + pub(crate) fn update_bounds(&self, bounds: &mut Option) { *bounds = Some(match *bounds { None => self.bounds, Some(bounds) => bounds.union_rect(self.bounds), @@ -800,21 +800,21 @@ impl<'a> Iterator for ContourIter<'a> { if self.index == contour.len() { let point1 = contour.position_of(0); self.index += 1; - return Some(Segment::line(&LineSegmentF32::new(point0, point1))); + return Some(Segment::line(&LineSegmentF::new(point0, point1))); } let point1_index = self.index; self.index += 1; let point1 = contour.position_of(point1_index); if contour.point_is_endpoint(point1_index) { - return Some(Segment::line(&LineSegmentF32::new(point0, point1))); + return Some(Segment::line(&LineSegmentF::new(point0, point1))); } let point2_index = self.index; let point2 = contour.position_of(point2_index); self.index += 1; if contour.point_is_endpoint(point2_index) { - return Some(Segment::quadratic(&LineSegmentF32::new(point0, point2), point1)); + return Some(Segment::quadratic(&LineSegmentF::new(point0, point2), point1)); } let point3_index = self.index; @@ -822,16 +822,16 @@ impl<'a> Iterator for ContourIter<'a> { self.index += 1; debug_assert!(contour.point_is_endpoint(point3_index)); return Some(Segment::cubic( - &LineSegmentF32::new(point0, point3), - &LineSegmentF32::new(point1, point2), + &LineSegmentF::new(point0, point3), + &LineSegmentF::new(point1, point2), )); } } #[inline] -pub(crate) fn union_rect(bounds: &mut RectF32, new_point: Point2DF32, first: bool) { +pub(crate) fn union_rect(bounds: &mut RectF, new_point: Point2DF, first: bool) { if first { - *bounds = RectF32::from_points(new_point, new_point); + *bounds = RectF::from_points(new_point, new_point); } else { *bounds = bounds.union_point(new_point) } diff --git a/geometry/src/segment.rs b/geometry/src/segment.rs index f201110c..4ef5620e 100644 --- a/geometry/src/segment.rs +++ b/geometry/src/segment.rs @@ -10,9 +10,9 @@ //! Line or curve segments, optimized with SIMD. -use crate::basic::line_segment::LineSegmentF32; -use crate::basic::point::Point2DF32; -use crate::basic::transform2d::Transform2DF32; +use crate::basic::line_segment::LineSegmentF; +use crate::basic::point::Point2DF; +use crate::basic::transform2d::Transform2DF; use crate::util::{self, EPSILON}; use pathfinder_simd::default::F32x4; use std::f32::consts::SQRT_2; @@ -21,8 +21,8 @@ const MAX_NEWTON_ITERATIONS: u32 = 32; #[derive(Clone, Copy, Debug, PartialEq)] pub struct Segment { - pub baseline: LineSegmentF32, - pub ctrl: LineSegmentF32, + pub baseline: LineSegmentF, + pub ctrl: LineSegmentF, pub kind: SegmentKind, pub flags: SegmentFlags, } @@ -31,35 +31,35 @@ impl Segment { #[inline] pub fn none() -> Segment { Segment { - baseline: LineSegmentF32::default(), - ctrl: LineSegmentF32::default(), + baseline: LineSegmentF::default(), + ctrl: LineSegmentF::default(), kind: SegmentKind::None, flags: SegmentFlags::empty(), } } #[inline] - pub fn line(line: &LineSegmentF32) -> Segment { + pub fn line(line: &LineSegmentF) -> Segment { Segment { baseline: *line, - ctrl: LineSegmentF32::default(), + ctrl: LineSegmentF::default(), kind: SegmentKind::Line, flags: SegmentFlags::empty(), } } #[inline] - pub fn quadratic(baseline: &LineSegmentF32, ctrl: Point2DF32) -> Segment { + pub fn quadratic(baseline: &LineSegmentF, ctrl: Point2DF) -> Segment { Segment { baseline: *baseline, - ctrl: LineSegmentF32::new(ctrl, Point2DF32::default()), + ctrl: LineSegmentF::new(ctrl, Point2DF::default()), kind: SegmentKind::Quadratic, flags: SegmentFlags::empty(), } } #[inline] - pub fn cubic(baseline: &LineSegmentF32, ctrl: &LineSegmentF32) -> Segment { + pub fn cubic(baseline: &LineSegmentF, ctrl: &LineSegmentF) -> Segment { Segment { baseline: *baseline, ctrl: *ctrl, @@ -85,17 +85,17 @@ impl Segment { // // https://pdfs.semanticscholar.org/1639/0db1a470bd13fe428e0896671a9a5745070a.pdf let term = F32x4::new(cos_sweep_angle, -cos_sweep_angle, 0.0, 0.0); - let p0 = Point2DF32((F32x4::splat(0.5) * (F32x4::splat(1.0) + term)).sqrt()); - let p3 = p0.scale_xy(Point2DF32::new(1.0, -1.0)); + let p0 = Point2DF((F32x4::splat(0.5) * (F32x4::splat(1.0) + term)).sqrt()); + let p3 = p0.scale_xy(Point2DF::new(1.0, -1.0)); let p1 = p0 - p3.yx().scale(K); let p2 = p3 + p0.yx().scale(K); - return Segment::cubic(&LineSegmentF32::new(p3, p0), &LineSegmentF32::new(p2, p1)); + return Segment::cubic(&LineSegmentF::new(p3, p0), &LineSegmentF::new(p2, p1)); const K: f32 = 4.0 / 3.0 * (SQRT_2 - 1.0); } #[inline] - pub fn as_line_segment(&self) -> LineSegmentF32 { + pub fn as_line_segment(&self) -> LineSegmentF { debug_assert!(self.is_line()); self.baseline } @@ -137,7 +137,7 @@ impl Segment { let mut new_segment = *self; let p1_2 = self.ctrl.from() + self.ctrl.from(); new_segment.ctrl = - LineSegmentF32::new(self.baseline.from() + p1_2, p1_2 + self.baseline.to()) + LineSegmentF::new(self.baseline.from() + p1_2, p1_2 + self.baseline.to()) .scale(1.0 / 3.0); new_segment.kind = SegmentKind::Cubic; new_segment @@ -196,7 +196,7 @@ impl Segment { } #[inline] - pub fn sample(self, t: f32) -> Point2DF32 { + pub fn sample(self, t: f32) -> Point2DF { // FIXME(pcwalton): Don't degree elevate! if self.is_line() { self.as_line_segment().sample(t) @@ -206,7 +206,7 @@ impl Segment { } #[inline] - pub fn transform(self, transform: &Transform2DF32) -> Segment { + pub fn transform(self, transform: &Transform2DF) -> Segment { Segment { baseline: transform.transform_line_segment(&self.baseline), ctrl: transform.transform_line_segment(&self.ctrl), @@ -253,16 +253,16 @@ impl<'s> CubicSegment<'s> { let (baseline0, ctrl0, baseline1, ctrl1); if t <= 0.0 { let from = &self.0.baseline.from(); - baseline0 = LineSegmentF32::new(*from, *from); - ctrl0 = LineSegmentF32::new(*from, *from); + baseline0 = LineSegmentF::new(*from, *from); + ctrl0 = LineSegmentF::new(*from, *from); baseline1 = self.0.baseline; ctrl1 = self.0.ctrl; } else if t >= 1.0 { let to = &self.0.baseline.to(); baseline0 = self.0.baseline; ctrl0 = self.0.ctrl; - baseline1 = LineSegmentF32::new(*to, *to); - ctrl1 = LineSegmentF32::new(*to, *to); + baseline1 = LineSegmentF::new(*to, *to); + ctrl1 = LineSegmentF::new(*to, *to); } else { let tttt = F32x4::splat(t); @@ -281,10 +281,10 @@ impl<'s> CubicSegment<'s> { // p0123 = lerp(p012, p123, t) let p0123 = p012p123 + tttt * (p123 - p012p123); - baseline0 = LineSegmentF32(p0p3.concat_xy_xy(p0123)); - ctrl0 = LineSegmentF32(p01p12.concat_xy_xy(p012p123)); - baseline1 = LineSegmentF32(p0123.concat_xy_zw(p0p3)); - ctrl1 = LineSegmentF32(p012p123.concat_zw_zw(p12p23)); + baseline0 = LineSegmentF(p0p3.concat_xy_xy(p0123)); + ctrl0 = LineSegmentF(p01p12.concat_xy_xy(p012p123)); + baseline1 = LineSegmentF(p0123.concat_xy_zw(p0p3)); + ctrl1 = LineSegmentF(p012p123.concat_zw_zw(p12p23)); } ( @@ -315,7 +315,7 @@ impl<'s> CubicSegment<'s> { // FIXME(pcwalton): Use Horner's method! #[inline] - pub fn sample(self, t: f32) -> Point2DF32 { + pub fn sample(self, t: f32) -> Point2DF { self.split(t).0.baseline.to() } diff --git a/geometry/src/stroke.rs b/geometry/src/stroke.rs index 5b905003..e910d04f 100644 --- a/geometry/src/stroke.rs +++ b/geometry/src/stroke.rs @@ -10,9 +10,9 @@ //! Utilities for converting path strokes to fills. -use crate::basic::line_segment::LineSegmentF32; -use crate::basic::point::Point2DF32; -use crate::basic::rect::RectF32; +use crate::basic::line_segment::LineSegmentF; +use crate::basic::point::Point2DF; +use crate::basic::rect::RectF; use crate::outline::{Contour, Outline}; use crate::segment::Segment; use std::f32; @@ -84,7 +84,7 @@ impl<'a> OutlineStrokeToFill<'a> { new_contours.iter().for_each(|contour| contour.update_bounds(&mut new_bounds)); self.output.contours = new_contours; - self.output.bounds = new_bounds.unwrap_or_else(|| RectF32::default()); + self.output.bounds = new_bounds.unwrap_or_else(|| RectF::default()); } #[inline] @@ -99,7 +99,7 @@ impl<'a> OutlineStrokeToFill<'a> { // Add join if necessary. if closed && stroker.output.needs_join(self.style.line_join) { let (p1, p0) = (stroker.output.position_of(1), stroker.output.position_of(0)); - let final_segment = LineSegmentF32::new(p1, p0); + let final_segment = LineSegmentF::new(p1, p0); let join_point = stroker.input.position_of(0); stroker.output.add_join(self.style.line_join, join_point, &final_segment); } @@ -123,7 +123,7 @@ impl<'a> OutlineStrokeToFill<'a> { let offset = gradient.scale(width * 0.5); let p2 = p1 + offset; - let p3 = p2 + gradient.yx().scale_xy(Point2DF32::new(-width, width)); + let p3 = p2 + gradient.yx().scale_xy(Point2DF::new(-width, width)); let p4 = p3 - offset; contour.push_endpoint(p2); @@ -131,8 +131,8 @@ impl<'a> OutlineStrokeToFill<'a> { contour.push_endpoint(p4); } LineCap::Round => { - let offset = gradient.yx().scale_xy(Point2DF32::new(-width, width)); - let chord = LineSegmentF32::new(p1, p1 + offset); + let offset = gradient.yx().scale_xy(Point2DF::new(-width, width)); + let chord = LineSegmentF::new(p1, p1 + offset); contour.push_arc_from_chord(p1 + offset.scale(0.5), chord); } } @@ -179,7 +179,7 @@ impl<'a> ContourStrokeToFill<'a> { trait Offset { fn offset(&self, distance: f32, join: LineJoin, contour: &mut Contour); - fn add_to_contour(&self, join: LineJoin, join_point: Point2DF32, contour: &mut Contour); + fn add_to_contour(&self, join: LineJoin, join_point: Point2DF, contour: &mut Contour); fn offset_once(&self, distance: f32) -> Self; fn error_is_within_tolerance(&self, other: &Segment, distance: f32) -> bool; } @@ -207,7 +207,7 @@ impl Offset for Segment { after.offset(distance, join, contour); } - fn add_to_contour(&self, join: LineJoin, join_point: Point2DF32, contour: &mut Contour) { + fn add_to_contour(&self, join: LineJoin, join_point: Point2DF, contour: &mut Contour) { // Add join if necessary. if contour.needs_join(join) { let p3 = self.baseline.from(); @@ -219,7 +219,7 @@ impl Offset for Segment { self.ctrl.from() }; - contour.add_join(join, join_point, &LineSegmentF32::new(p4, p3)); + contour.add_join(join, join_point, &LineSegmentF::new(p4, p3)); } // Push segment. @@ -232,51 +232,51 @@ impl Offset for Segment { } if self.is_quadratic() { - let mut segment_0 = LineSegmentF32::new(self.baseline.from(), self.ctrl.from()); - let mut segment_1 = LineSegmentF32::new(self.ctrl.from(), self.baseline.to()); + let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.from()); + let mut segment_1 = LineSegmentF::new(self.ctrl.from(), self.baseline.to()); segment_0 = segment_0.offset(distance); segment_1 = segment_1.offset(distance); let ctrl = match segment_0.intersection_t(&segment_1) { Some(t) => segment_0.sample(t), None => segment_0.to().lerp(segment_1.from(), 0.5), }; - let baseline = LineSegmentF32::new(segment_0.from(), segment_1.to()); + let baseline = LineSegmentF::new(segment_0.from(), segment_1.to()); return Segment::quadratic(&baseline, ctrl); } debug_assert!(self.is_cubic()); if self.baseline.from() == self.ctrl.from() { - let mut segment_0 = LineSegmentF32::new(self.baseline.from(), self.ctrl.to()); - let mut segment_1 = LineSegmentF32::new(self.ctrl.to(), self.baseline.to()); + let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.to()); + let mut segment_1 = LineSegmentF::new(self.ctrl.to(), self.baseline.to()); segment_0 = segment_0.offset(distance); segment_1 = segment_1.offset(distance); let ctrl = match segment_0.intersection_t(&segment_1) { Some(t) => segment_0.sample(t), None => segment_0.to().lerp(segment_1.from(), 0.5), }; - let baseline = LineSegmentF32::new(segment_0.from(), segment_1.to()); - let ctrl = LineSegmentF32::new(segment_0.from(), ctrl); + let baseline = LineSegmentF::new(segment_0.from(), segment_1.to()); + let ctrl = LineSegmentF::new(segment_0.from(), ctrl); return Segment::cubic(&baseline, &ctrl); } if self.ctrl.to() == self.baseline.to() { - let mut segment_0 = LineSegmentF32::new(self.baseline.from(), self.ctrl.from()); - let mut segment_1 = LineSegmentF32::new(self.ctrl.from(), self.baseline.to()); + let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.from()); + let mut segment_1 = LineSegmentF::new(self.ctrl.from(), self.baseline.to()); segment_0 = segment_0.offset(distance); segment_1 = segment_1.offset(distance); let ctrl = match segment_0.intersection_t(&segment_1) { Some(t) => segment_0.sample(t), None => segment_0.to().lerp(segment_1.from(), 0.5), }; - let baseline = LineSegmentF32::new(segment_0.from(), segment_1.to()); - let ctrl = LineSegmentF32::new(ctrl, segment_1.to()); + let baseline = LineSegmentF::new(segment_0.from(), segment_1.to()); + let ctrl = LineSegmentF::new(ctrl, segment_1.to()); return Segment::cubic(&baseline, &ctrl); } - let mut segment_0 = LineSegmentF32::new(self.baseline.from(), self.ctrl.from()); - let mut segment_1 = LineSegmentF32::new(self.ctrl.from(), self.ctrl.to()); - let mut segment_2 = LineSegmentF32::new(self.ctrl.to(), self.baseline.to()); + let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.from()); + let mut segment_1 = LineSegmentF::new(self.ctrl.from(), self.ctrl.to()); + let mut segment_2 = LineSegmentF::new(self.ctrl.to(), self.baseline.to()); segment_0 = segment_0.offset(distance); segment_1 = segment_1.offset(distance); segment_2 = segment_2.offset(distance); @@ -290,8 +290,8 @@ impl Offset for Segment { segment_1.to().lerp(segment_2.from(), 0.5), ), }; - let baseline = LineSegmentF32::new(segment_0.from(), segment_2.to()); - let ctrl = LineSegmentF32::new(ctrl_0, ctrl_1); + let baseline = LineSegmentF::new(segment_0.from(), segment_2.to()); + let ctrl = LineSegmentF::new(ctrl_0, ctrl_1); Segment::cubic(&baseline, &ctrl) } @@ -330,9 +330,9 @@ impl Contour { (join == LineJoin::Miter || join == LineJoin::Round) && self.len() >= 2 } - fn add_join(&mut self, join: LineJoin, join_point: Point2DF32, next_tangent: &LineSegmentF32) { + fn add_join(&mut self, join: LineJoin, join_point: Point2DF, next_tangent: &LineSegmentF) { let (p0, p1) = (self.position_of_last(2), self.position_of_last(1)); - let prev_tangent = LineSegmentF32::new(p0, p1); + let prev_tangent = LineSegmentF::new(p0, p1); match join { LineJoin::Bevel => {} @@ -342,7 +342,7 @@ impl Contour { } } LineJoin::Round => { - self.push_arc_from_chord(join_point, LineSegmentF32::new(prev_tangent.to(), + self.push_arc_from_chord(join_point, LineSegmentF::new(prev_tangent.to(), next_tangent.to())); } } diff --git a/geometry/src/unit_vector.rs b/geometry/src/unit_vector.rs index ac74d7a3..27fb9a9d 100644 --- a/geometry/src/unit_vector.rs +++ b/geometry/src/unit_vector.rs @@ -10,30 +10,30 @@ //! A utility module that allows unit vectors to be treated like angles. -use crate::basic::point::Point2DF32; +use crate::basic::point::Point2DF; use pathfinder_simd::default::F32x4; #[derive(Clone, Copy, Debug)] -pub struct UnitVector(pub Point2DF32); +pub struct UnitVector(pub Point2DF); impl UnitVector { #[inline] pub fn from_angle(theta: f32) -> UnitVector { - UnitVector(Point2DF32::new(theta.cos(), theta.sin())) + UnitVector(Point2DF::new(theta.cos(), theta.sin())) } /// Angle addition formula. #[inline] pub fn rotate_by(&self, other: UnitVector) -> UnitVector { let products = (self.0).0.xyyx() * (other.0).0.xyxy(); - UnitVector(Point2DF32::new(products[0] - products[1], products[2] + products[3])) + UnitVector(Point2DF::new(products[0] - products[1], products[2] + products[3])) } /// Angle subtraction formula. #[inline] pub fn rev_rotate_by(&self, other: UnitVector) -> UnitVector { let products = (self.0).0.xyyx() * (other.0).0.xyxy(); - UnitVector(Point2DF32::new(products[0] + products[1], products[2] - products[3])) + UnitVector(Point2DF::new(products[0] + products[1], products[2] - products[3])) } /// Half angle formula. @@ -41,6 +41,6 @@ impl UnitVector { pub fn halve_angle(&self) -> UnitVector { let x = self.0.x(); let term = F32x4::new(x, -x, 0.0, 0.0); - UnitVector(Point2DF32((F32x4::splat(0.5) * (F32x4::splat(1.0) + term)).sqrt())) + UnitVector(Point2DF((F32x4::splat(0.5) * (F32x4::splat(1.0) + term)).sqrt())) } } diff --git a/gl/src/lib.rs b/gl/src/lib.rs index 4fe6fd78..7ebc8c8a 100644 --- a/gl/src/lib.rs +++ b/gl/src/lib.rs @@ -14,8 +14,8 @@ extern crate log; use gl::types::{GLboolean, GLchar, GLenum, GLfloat, GLint, GLsizei, GLsizeiptr, GLuint, GLvoid}; -use pathfinder_geometry::basic::point::Point2DI32; -use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::rect::RectI; use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::{BlendState, BufferData, BufferTarget, BufferUploadMode, ClearParams}; use pathfinder_gpu::{DepthFunc, Device, Primitive, RenderState, ShaderKind, StencilFunc}; @@ -164,7 +164,7 @@ impl Device for GLDevice { type VertexArray = GLVertexArray; type VertexAttr = GLVertexAttr; - fn create_texture(&self, format: TextureFormat, size: Point2DI32) -> GLTexture { + fn create_texture(&self, format: TextureFormat, size: Point2DI) -> GLTexture { let (gl_internal_format, gl_format, gl_type); match format { TextureFormat::R8 => { @@ -203,7 +203,7 @@ impl Device for GLDevice { texture } - fn create_texture_from_data(&self, size: Point2DI32, data: &[u8]) -> GLTexture { + fn create_texture_from_data(&self, size: Point2DI, data: &[u8]) -> GLTexture { assert!(data.len() >= size.x() as usize * size.y() as usize); let mut texture = GLTexture { gl_texture: 0, size }; @@ -450,11 +450,11 @@ impl Device for GLDevice { } #[inline] - fn texture_size(&self, texture: &Self::Texture) -> Point2DI32 { + fn texture_size(&self, texture: &Self::Texture) -> Point2DI { texture.size } - fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI32, data: &[u8]) { + fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI, data: &[u8]) { assert!(data.len() >= size.x() as usize * size.y() as usize * 4); unsafe { self.bind_texture(texture, 0); @@ -472,7 +472,7 @@ impl Device for GLDevice { self.set_texture_parameters(texture); } - fn read_pixels_from_default_framebuffer(&self, size: Point2DI32) -> Vec { + fn read_pixels_from_default_framebuffer(&self, size: Point2DI) -> Vec { let mut pixels = vec![0; size.x() as usize * size.y() as usize * 4]; unsafe { gl::BindFramebuffer(gl::FRAMEBUFFER, self.default_framebuffer); ck(); @@ -622,7 +622,7 @@ impl Device for GLDevice { } #[inline] - fn bind_default_framebuffer(&self, viewport: RectI32) { + fn bind_default_framebuffer(&self, viewport: RectI) { unsafe { gl::BindFramebuffer(gl::FRAMEBUFFER, self.default_framebuffer); ck(); gl::Viewport(viewport.origin().x(), @@ -799,7 +799,7 @@ impl Drop for GLShader { pub struct GLTexture { gl_texture: GLuint, - pub size: Point2DI32, + pub size: Point2DI, } pub struct GLTimerQuery { diff --git a/gpu/src/lib.rs b/gpu/src/lib.rs index 21d475d5..dbdcd7d4 100644 --- a/gpu/src/lib.rs +++ b/gpu/src/lib.rs @@ -12,9 +12,9 @@ use crate::resources::ResourceLoader; use image::ImageFormat; -use pathfinder_geometry::basic::point::Point2DI32; -use pathfinder_geometry::basic::rect::RectI32; -use pathfinder_geometry::basic::transform3d::Transform3DF32; +use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::rect::RectI; +use pathfinder_geometry::basic::transform3d::Transform3DF; use pathfinder_geometry::color::ColorF; use pathfinder_simd::default::F32x4; use std::time::Duration; @@ -41,8 +41,8 @@ pub trait Device { type VertexArray; type VertexAttr; - fn create_texture(&self, format: TextureFormat, size: Point2DI32) -> Self::Texture; - fn create_texture_from_data(&self, size: Point2DI32, data: &[u8]) -> Self::Texture; + fn create_texture(&self, format: TextureFormat, size: Point2DI) -> Self::Texture; + fn create_texture_from_data(&self, size: Point2DI, data: &[u8]) -> Self::Texture; fn create_shader_from_source( &self, resources: &dyn ResourceLoader, @@ -74,9 +74,9 @@ pub trait Device { mode: BufferUploadMode, ); fn framebuffer_texture<'f>(&self, framebuffer: &'f Self::Framebuffer) -> &'f Self::Texture; - fn texture_size(&self, texture: &Self::Texture) -> Point2DI32; - fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI32, data: &[u8]); - fn read_pixels_from_default_framebuffer(&self, size: Point2DI32) -> Vec; + fn texture_size(&self, texture: &Self::Texture) -> Point2DI; + fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI, data: &[u8]); + fn read_pixels_from_default_framebuffer(&self, size: Point2DI) -> Vec; fn clear(&self, params: &ClearParams); fn draw_arrays(&self, primitive: Primitive, index_count: u32, render_state: &RenderState); fn draw_elements(&self, primitive: Primitive, index_count: u32, render_state: &RenderState); @@ -94,7 +94,7 @@ pub trait Device { // TODO(pcwalton): Go bindless... fn bind_vertex_array(&self, vertex_array: &Self::VertexArray); fn bind_buffer(&self, buffer: &Self::Buffer, target: BufferTarget); - fn bind_default_framebuffer(&self, viewport: RectI32); + fn bind_default_framebuffer(&self, viewport: RectI); fn bind_framebuffer(&self, framebuffer: &Self::Framebuffer); fn bind_texture(&self, texture: &Self::Texture, unit: u32); @@ -103,7 +103,7 @@ pub trait Device { let image = image::load_from_memory_with_format(&data, ImageFormat::PNG) .unwrap() .to_luma(); - let size = Point2DI32::new(image.width() as i32, image.height() as i32); + let size = Point2DI::new(image.width() as i32, image.height() as i32); self.create_texture_from_data(size, &image) } @@ -202,7 +202,7 @@ pub enum Primitive { #[derive(Clone, Copy, Default)] pub struct ClearParams { pub color: Option, - pub rect: Option, + pub rect: Option, pub depth: Option, pub stencil: Option, } @@ -297,7 +297,7 @@ impl Default for StencilFunc { impl UniformData { #[inline] - pub fn from_transform_3d(transform: &Transform3DF32) -> UniformData { + pub fn from_transform_3d(transform: &Transform3DF) -> UniformData { UniformData::Mat4([transform.c0, transform.c1, transform.c2, transform.c3]) } } diff --git a/renderer/src/builder.rs b/renderer/src/builder.rs index 15ac1dbe..c4353b3b 100644 --- a/renderer/src/builder.rs +++ b/renderer/src/builder.rs @@ -17,9 +17,9 @@ use crate::scene::Scene; use crate::tile_map::DenseTileMap; use crate::tiles::{self, TILE_HEIGHT, TILE_WIDTH, Tiler}; use crate::z_buffer::ZBuffer; -use pathfinder_geometry::basic::line_segment::{LineSegmentF32, LineSegmentU4, LineSegmentU8}; -use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; -use pathfinder_geometry::basic::rect::{RectF32, RectI32}; +use pathfinder_geometry::basic::line_segment::{LineSegmentF, LineSegmentU4, LineSegmentU8}; +use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::rect::{RectF, RectI}; use pathfinder_geometry::util; use pathfinder_simd::default::{F32x4, I32x4}; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -75,7 +75,7 @@ impl<'a> SceneBuilder<'a> { fn build_path( &self, path_index: usize, - view_box: RectF32, + view_box: RectF, built_options: &PreparedRenderOptions, scene: &Scene, ) -> Vec { @@ -141,7 +141,7 @@ pub struct TileStats { // Utilities for built objects impl BuiltObject { - pub(crate) fn new(bounds: RectF32) -> BuiltObject { + pub(crate) fn new(bounds: RectF) -> BuiltObject { let tile_rect = tiles::round_rect_out_to_tile_bounds(bounds); let tiles = DenseTileMap::new(tile_rect); BuiltObject { @@ -153,15 +153,15 @@ impl BuiltObject { } #[inline] - pub(crate) fn tile_rect(&self) -> RectI32 { + pub(crate) fn tile_rect(&self) -> RectI { self.tiles.rect } fn add_fill( &mut self, builder: &SceneBuilder, - segment: &LineSegmentF32, - tile_coords: Point2DI32, + segment: &LineSegmentF, + tile_coords: Point2DI, ) { debug!("add_fill({:?} ({:?}))", segment, tile_coords); @@ -214,7 +214,7 @@ impl BuiltObject { fn get_or_allocate_alpha_tile_index( &mut self, builder: &SceneBuilder, - tile_coords: Point2DI32, + tile_coords: Point2DI, ) -> u16 { let local_tile_index = self.tiles.coords_to_index_unchecked(tile_coords); let alpha_tile_index = self.tiles.data[local_tile_index].alpha_tile_index; @@ -235,16 +235,16 @@ impl BuiltObject { left: f32, right: f32, mut winding: i32, - tile_coords: Point2DI32, + tile_coords: Point2DI, ) { let tile_origin_y = (tile_coords.y() * TILE_HEIGHT as i32) as f32; - let left = Point2DF32::new(left, tile_origin_y); - let right = Point2DF32::new(right, tile_origin_y); + let left = Point2DF::new(left, tile_origin_y); + let right = Point2DF::new(right, tile_origin_y); let segment = if winding < 0 { - LineSegmentF32::new(left, right) + LineSegmentF::new(left, right) } else { - LineSegmentF32::new(right, left) + LineSegmentF::new(right, left) }; debug!( @@ -268,7 +268,7 @@ impl BuiltObject { pub(crate) fn generate_fill_primitives_for_line( &mut self, builder: &SceneBuilder, - mut segment: LineSegmentF32, + mut segment: LineSegmentF, tile_y: i32, ) { debug!( @@ -303,29 +303,29 @@ impl BuiltObject { ((i32::from(subsegment_tile_x) + 1) * TILE_HEIGHT as i32) as f32; if subsegment_tile_right < segment_right { let x = subsegment_tile_right; - let point = Point2DF32::new(x, segment.solve_y_for_x(x)); + let point = Point2DF::new(x, segment.solve_y_for_x(x)); if !winding { fill_to = point; - segment = LineSegmentF32::new(point, segment.to()); + segment = LineSegmentF::new(point, segment.to()); } else { fill_from = point; - segment = LineSegmentF32::new(segment.from(), point); + segment = LineSegmentF::new(segment.from(), point); } } - let fill_segment = LineSegmentF32::new(fill_from, fill_to); - let fill_tile_coords = Point2DI32::new(subsegment_tile_x, tile_y); + let fill_segment = LineSegmentF::new(fill_from, fill_to); + let fill_tile_coords = Point2DI::new(subsegment_tile_x, tile_y); self.add_fill(builder, &fill_segment, fill_tile_coords); } } #[inline] - pub(crate) fn tile_coords_to_local_index(&self, coords: Point2DI32) -> Option { + pub(crate) fn tile_coords_to_local_index(&self, coords: Point2DI) -> Option { self.tiles.coords_to_index(coords).map(|index| index as u32) } #[inline] - pub(crate) fn local_tile_index_to_coords(&self, tile_index: u32) -> Point2DI32 { + pub(crate) fn local_tile_index_to_coords(&self, tile_index: u32) -> Point2DI { self.tiles.index_to_coords(tile_index as usize) } } diff --git a/renderer/src/concurrent/scene_proxy.rs b/renderer/src/concurrent/scene_proxy.rs index cefb7dcc..09c0e38d 100644 --- a/renderer/src/concurrent/scene_proxy.rs +++ b/renderer/src/concurrent/scene_proxy.rs @@ -24,7 +24,7 @@ use crate::gpu::renderer::Renderer; use crate::gpu_data::RenderCommand; use crate::options::{RenderCommandListener, RenderOptions}; use crate::scene::Scene; -use pathfinder_geometry::basic::rect::RectF32; +use pathfinder_geometry::basic::rect::RectF; use pathfinder_gpu::Device; use std::sync::mpsc::{self, Receiver, Sender}; use std::thread; @@ -53,7 +53,7 @@ impl SceneProxy { } #[inline] - pub fn set_view_box(&self, new_view_box: RectF32) { + pub fn set_view_box(&self, new_view_box: RectF) { self.sender.send(MainToWorkerMsg::SetViewBox(new_view_box)).unwrap(); } @@ -117,7 +117,7 @@ fn scene_thread(mut scene: Scene, enum MainToWorkerMsg { ReplaceScene(Scene), - SetViewBox(RectF32), + SetViewBox(RectF), Build(RenderOptions, Box), GetSVG(Sender>), } diff --git a/renderer/src/gpu/debug.rs b/renderer/src/gpu/debug.rs index d23082b1..ca69b9ad 100644 --- a/renderer/src/gpu/debug.rs +++ b/renderer/src/gpu/debug.rs @@ -16,8 +16,8 @@ //! The debug font atlas was generated using: https://evanw.github.io/font-texture-generator/ use crate::gpu::renderer::{RenderStats, RenderTime}; -use pathfinder_geometry::basic::point::Point2DI32; -use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::rect::RectI; use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::Device; use pathfinder_ui::{FONT_ASCENT, LINE_HEIGHT, PADDING, UIPresenter, WINDOW_COLOR}; @@ -50,7 +50,7 @@ where pub fn new( device: &D, resources: &dyn ResourceLoader, - framebuffer_size: Point2DI32, + framebuffer_size: Point2DI, ) -> DebugUIPresenter { let ui_presenter = UIPresenter::new(device, resources, framebuffer_size); DebugUIPresenter { @@ -84,17 +84,17 @@ where fn draw_stats_window(&self, device: &D, mean_cpu_sample: &CPUSample) { let framebuffer_size = self.ui_presenter.framebuffer_size(); let bottom = framebuffer_size.y() - PADDING; - let window_rect = RectI32::new( - Point2DI32::new( + let window_rect = RectI::new( + Point2DI::new( framebuffer_size.x() - PADDING - STATS_WINDOW_WIDTH, bottom - PERFORMANCE_WINDOW_HEIGHT - PADDING - STATS_WINDOW_HEIGHT, ), - Point2DI32::new(STATS_WINDOW_WIDTH, STATS_WINDOW_HEIGHT), + Point2DI::new(STATS_WINDOW_WIDTH, STATS_WINDOW_HEIGHT), ); self.ui_presenter.draw_solid_rounded_rect(device, window_rect, WINDOW_COLOR); - let origin = window_rect.origin() + Point2DI32::new(PADDING, PADDING + FONT_ASCENT); + let origin = window_rect.origin() + Point2DI::new(PADDING, PADDING + FONT_ASCENT); self.ui_presenter.draw_text( device, &format!("Paths: {}", mean_cpu_sample.stats.path_count), @@ -104,19 +104,19 @@ where self.ui_presenter.draw_text( device, &format!("Solid Tiles: {}", mean_cpu_sample.stats.solid_tile_count), - origin + Point2DI32::new(0, LINE_HEIGHT * 1), + origin + Point2DI::new(0, LINE_HEIGHT * 1), false, ); self.ui_presenter.draw_text( device, &format!("Alpha Tiles: {}", mean_cpu_sample.stats.alpha_tile_count), - origin + Point2DI32::new(0, LINE_HEIGHT * 2), + origin + Point2DI::new(0, LINE_HEIGHT * 2), false, ); self.ui_presenter.draw_text( device, &format!("Fills: {}", mean_cpu_sample.stats.fill_count), - origin + Point2DI32::new(0, LINE_HEIGHT * 3), + origin + Point2DI::new(0, LINE_HEIGHT * 3), false, ); } @@ -124,17 +124,17 @@ where fn draw_performance_window(&self, device: &D, mean_cpu_sample: &CPUSample) { let framebuffer_size = self.ui_presenter.framebuffer_size(); let bottom = framebuffer_size.y() - PADDING; - let window_rect = RectI32::new( - Point2DI32::new( + let window_rect = RectI::new( + Point2DI::new( framebuffer_size.x() - PADDING - PERFORMANCE_WINDOW_WIDTH, bottom - PERFORMANCE_WINDOW_HEIGHT, ), - Point2DI32::new(PERFORMANCE_WINDOW_WIDTH, PERFORMANCE_WINDOW_HEIGHT), + Point2DI::new(PERFORMANCE_WINDOW_WIDTH, PERFORMANCE_WINDOW_HEIGHT), ); self.ui_presenter.draw_solid_rounded_rect(device, window_rect, WINDOW_COLOR); - let origin = window_rect.origin() + Point2DI32::new(PADDING, PADDING + FONT_ASCENT); + let origin = window_rect.origin() + Point2DI::new(PADDING, PADDING + FONT_ASCENT); self.ui_presenter.draw_text( device, &format!( @@ -152,7 +152,7 @@ where "Stage 0 GPU: {:.3} ms", duration_to_ms(mean_gpu_sample.time.stage_0) ), - origin + Point2DI32::new(0, LINE_HEIGHT * 1), + origin + Point2DI::new(0, LINE_HEIGHT * 1), false, ); self.ui_presenter.draw_text( @@ -161,7 +161,7 @@ where "Stage 1 GPU: {:.3} ms", duration_to_ms(mean_gpu_sample.time.stage_1) ), - origin + Point2DI32::new(0, LINE_HEIGHT * 2), + origin + Point2DI::new(0, LINE_HEIGHT * 2), false, ); @@ -171,7 +171,7 @@ where self.ui_presenter.draw_text( device, &format!("Wallclock: {:.3} ms", wallclock_time), - origin + Point2DI32::new(0, LINE_HEIGHT * 3), + origin + Point2DI::new(0, LINE_HEIGHT * 3), false, ); } diff --git a/renderer/src/gpu/renderer.rs b/renderer/src/gpu/renderer.rs index b5b03a61..9d6d2b0c 100644 --- a/renderer/src/gpu/renderer.rs +++ b/renderer/src/gpu/renderer.rs @@ -13,9 +13,9 @@ use crate::gpu_data::{AlphaTileBatchPrimitive, FillBatchPrimitive, PaintData}; use crate::gpu_data::{RenderCommand, SolidTileBatchPrimitive}; use crate::post::DefringingKernel; use crate::tiles::{TILE_HEIGHT, TILE_WIDTH}; -use pathfinder_geometry::basic::point::{Point2DI32, Point3DF32}; -use pathfinder_geometry::basic::rect::RectI32; -use pathfinder_geometry::basic::transform3d::Transform3DF32; +use pathfinder_geometry::basic::point::{Point2DI, Point3DF}; +use pathfinder_geometry::basic::rect::RectI; +use pathfinder_geometry::basic::transform3d::Transform3DF; use pathfinder_geometry::color::ColorF; use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::{BlendState, BufferData, BufferTarget, BufferUploadMode, ClearParams}; @@ -182,7 +182,7 @@ where ); let mask_framebuffer_size = - Point2DI32::new(MASK_FRAMEBUFFER_WIDTH, MASK_FRAMEBUFFER_HEIGHT); + Point2DI::new(MASK_FRAMEBUFFER_WIDTH, MASK_FRAMEBUFFER_HEIGHT); let mask_framebuffer_texture = device.create_texture(TextureFormat::R16F, mask_framebuffer_size); let mask_framebuffer = device.create_framebuffer(mask_framebuffer_texture); @@ -334,7 +334,7 @@ where } #[inline] - pub fn set_main_framebuffer_size(&mut self, new_framebuffer_size: Point2DI32) { + pub fn set_main_framebuffer_size(&mut self, new_framebuffer_size: Point2DI) { self.debug_ui_presenter.ui_presenter.set_framebuffer_size(new_framebuffer_size); } @@ -715,7 +715,7 @@ where } } - fn draw_stencil(&self, quad_positions: &[Point3DF32]) { + fn draw_stencil(&self, quad_positions: &[Point3DF]) { self.device.allocate_buffer( &self.stencil_vertex_array.vertex_buffer, BufferData::Memory(quad_positions), @@ -764,8 +764,8 @@ where pub fn reproject_texture( &self, texture: &D::Texture, - old_transform: &Transform3DF32, - new_transform: &Transform3DF32, + old_transform: &Transform3DF, + new_transform: &Transform3DF, ) { self.bind_draw_framebuffer(); @@ -869,28 +869,28 @@ where }) } - fn draw_viewport(&self) -> RectI32 { + fn draw_viewport(&self) -> RectI { let main_viewport = self.main_viewport(); match self.render_mode { RenderMode::Monochrome { defringing_kernel: Some(..), .. } => { - let scale = Point2DI32::new(3, 1); - RectI32::new(Point2DI32::default(), main_viewport.size().scale_xy(scale)) + let scale = Point2DI::new(3, 1); + RectI::new(Point2DI::default(), main_viewport.size().scale_xy(scale)) } _ => main_viewport, } } - fn main_viewport(&self) -> RectI32 { + fn main_viewport(&self) -> RectI { match self.dest_framebuffer { DestFramebuffer::Default { viewport, .. } => viewport, DestFramebuffer::Other(ref framebuffer) => { let size = self .device .texture_size(self.device.framebuffer_texture(framebuffer)); - RectI32::new(Point2DI32::default(), size) + RectI::new(Point2DI::default(), size) } } } @@ -1554,8 +1554,8 @@ where D: Device, { Default { - viewport: RectI32, - window_size: Point2DI32, + viewport: RectI, + window_size: Point2DI, }, Other(D::Framebuffer), } @@ -1565,12 +1565,12 @@ where D: Device, { #[inline] - pub fn full_window(window_size: Point2DI32) -> DestFramebuffer { - let viewport = RectI32::new(Point2DI32::default(), window_size); + pub fn full_window(window_size: Point2DI) -> DestFramebuffer { + let viewport = RectI::new(Point2DI::default(), window_size); DestFramebuffer::Default { viewport, window_size } } - fn window_size(&self, device: &D) -> Point2DI32 { + fn window_size(&self, device: &D) -> Point2DI { match *self { DestFramebuffer::Default { window_size, .. } => window_size, DestFramebuffer::Other(ref framebuffer) => { diff --git a/renderer/src/gpu_data.rs b/renderer/src/gpu_data.rs index 48520986..b7312b54 100644 --- a/renderer/src/gpu_data.rs +++ b/renderer/src/gpu_data.rs @@ -13,14 +13,14 @@ use crate::options::BoundingQuad; use crate::tile_map::DenseTileMap; use pathfinder_geometry::basic::line_segment::{LineSegmentU4, LineSegmentU8}; -use pathfinder_geometry::basic::point::Point2DI32; -use pathfinder_geometry::basic::rect::RectF32; +use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::rect::RectF; use std::fmt::{Debug, Formatter, Result as DebugResult}; use std::time::Duration; #[derive(Debug)] pub(crate) struct BuiltObject { - pub bounds: RectF32, + pub bounds: RectF, pub fills: Vec, pub alpha_tiles: Vec, pub tiles: DenseTileMap, @@ -38,7 +38,7 @@ pub enum RenderCommand { #[derive(Clone, Debug)] pub struct PaintData { - pub size: Point2DI32, + pub size: Point2DI, pub texels: Vec, } diff --git a/renderer/src/options.rs b/renderer/src/options.rs index 3ab28db6..b9e29028 100644 --- a/renderer/src/options.rs +++ b/renderer/src/options.rs @@ -11,9 +11,9 @@ //! Options that control how rendering is to be performed. use crate::gpu_data::RenderCommand; -use pathfinder_geometry::basic::point::{Point2DF32, Point3DF32}; -use pathfinder_geometry::basic::rect::RectF32; -use pathfinder_geometry::basic::transform2d::Transform2DF32; +use pathfinder_geometry::basic::point::{Point2DF, Point3DF}; +use pathfinder_geometry::basic::rect::RectF; +use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::basic::transform3d::Perspective; use pathfinder_geometry::clip::PolygonClipper3D; @@ -34,12 +34,12 @@ where #[derive(Clone, Default)] pub struct RenderOptions { pub transform: RenderTransform, - pub dilation: Point2DF32, + pub dilation: Point2DF, pub subpixel_aa_enabled: bool, } impl RenderOptions { - pub(crate) fn prepare(self, bounds: RectF32) -> PreparedRenderOptions { + pub(crate) fn prepare(self, bounds: RectF) -> PreparedRenderOptions { PreparedRenderOptions { transform: self.transform.prepare(bounds), dilation: self.dilation, @@ -50,19 +50,19 @@ impl RenderOptions { #[derive(Clone)] pub enum RenderTransform { - Transform2D(Transform2DF32), + Transform2D(Transform2DF), Perspective(Perspective), } impl Default for RenderTransform { #[inline] fn default() -> RenderTransform { - RenderTransform::Transform2D(Transform2DF32::default()) + RenderTransform::Transform2D(Transform2DF::default()) } } impl RenderTransform { - fn prepare(&self, bounds: RectF32) -> PreparedRenderTransform { + fn prepare(&self, bounds: RectF) -> PreparedRenderTransform { let perspective = match self { RenderTransform::Transform2D(ref transform) => { if transform.is_identity() { @@ -121,7 +121,7 @@ impl RenderTransform { pub(crate) struct PreparedRenderOptions { pub(crate) transform: PreparedRenderTransform, - pub(crate) dilation: Point2DF32, + pub(crate) dilation: Point2DF, pub(crate) subpixel_aa_enabled: bool, } @@ -130,20 +130,20 @@ impl PreparedRenderOptions { pub(crate) fn bounding_quad(&self) -> BoundingQuad { match self.transform { PreparedRenderTransform::Perspective { quad, .. } => quad, - _ => [Point3DF32::default(); 4], + _ => [Point3DF::default(); 4], } } } -pub(crate) type BoundingQuad = [Point3DF32; 4]; +pub(crate) type BoundingQuad = [Point3DF; 4]; pub(crate) enum PreparedRenderTransform { None, - Transform2D(Transform2DF32), + Transform2D(Transform2DF), Perspective { perspective: Perspective, - clip_polygon: Vec, - quad: [Point3DF32; 4], + clip_polygon: Vec, + quad: [Point3DF; 4], }, } diff --git a/renderer/src/paint.rs b/renderer/src/paint.rs index be48ce88..577661f9 100644 --- a/renderer/src/paint.rs +++ b/renderer/src/paint.rs @@ -10,7 +10,7 @@ use crate::gpu_data::PaintData; use crate::scene::Scene; -use pathfinder_geometry::basic::point::Point2DI32; +use pathfinder_geometry::basic::point::Point2DI; use pathfinder_geometry::color::ColorU; const PAINT_TEXTURE_WIDTH: i32 = 256; @@ -32,7 +32,7 @@ impl Paint { impl Scene { pub fn build_paint_data(&self) -> PaintData { - let size = Point2DI32::new(PAINT_TEXTURE_WIDTH, PAINT_TEXTURE_HEIGHT); + let size = Point2DI::new(PAINT_TEXTURE_WIDTH, PAINT_TEXTURE_HEIGHT); let mut texels = vec![0; size.x() as usize * size.y() as usize * 4]; for (paint_index, paint) in self.paints.iter().enumerate() { texels[paint_index * 4 + 0] = paint.color.r; @@ -44,8 +44,8 @@ impl Scene { } } -pub(crate) fn paint_id_to_tex_coords(paint_id: PaintId) -> Point2DI32 { - let tex_coords = Point2DI32::new(paint_id.0 as i32 % PAINT_TEXTURE_WIDTH, +pub(crate) fn paint_id_to_tex_coords(paint_id: PaintId) -> Point2DI { + let tex_coords = Point2DI::new(paint_id.0 as i32 % PAINT_TEXTURE_WIDTH, paint_id.0 as i32 / PAINT_TEXTURE_WIDTH); - tex_coords.scale(256) + Point2DI32::new(128, 128) + tex_coords.scale(256) + Point2DI::new(128, 128) } diff --git a/renderer/src/scene.rs b/renderer/src/scene.rs index 64479c34..478bee58 100644 --- a/renderer/src/scene.rs +++ b/renderer/src/scene.rs @@ -16,9 +16,9 @@ use crate::options::{PreparedRenderOptions, PreparedRenderTransform}; use crate::options::{RenderCommandListener, RenderOptions}; use crate::paint::{Paint, PaintId}; use hashbrown::HashMap; -use pathfinder_geometry::basic::point::Point2DF32; -use pathfinder_geometry::basic::rect::RectF32; -use pathfinder_geometry::basic::transform2d::Transform2DF32; +use pathfinder_geometry::basic::point::Point2DF; +use pathfinder_geometry::basic::rect::RectF; +use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::color::ColorU; use pathfinder_geometry::outline::Outline; use std::io::{self, Write}; @@ -28,8 +28,8 @@ pub struct Scene { pub(crate) paths: Vec, pub(crate) paints: Vec, paint_cache: HashMap, - bounds: RectF32, - view_box: RectF32, + bounds: RectF, + view_box: RectF, } impl Scene { @@ -39,8 +39,8 @@ impl Scene { paths: vec![], paints: vec![], paint_cache: HashMap::new(), - bounds: RectF32::default(), - view_box: RectF32::default(), + bounds: RectF::default(), + view_box: RectF::default(), } } @@ -67,22 +67,22 @@ impl Scene { } #[inline] - pub fn bounds(&self) -> RectF32 { + pub fn bounds(&self) -> RectF { self.bounds } #[inline] - pub fn set_bounds(&mut self, new_bounds: RectF32) { + pub fn set_bounds(&mut self, new_bounds: RectF) { self.bounds = new_bounds; } #[inline] - pub fn view_box(&self) -> RectF32 { + pub fn view_box(&self) -> RectF { self.view_box } #[inline] - pub fn set_view_box(&mut self, new_view_box: RectF32) { + pub fn set_view_box(&mut self, new_view_box: RectF) { self.view_box = new_view_box; } @@ -116,12 +116,12 @@ impl Scene { if options.transform.is_2d() || options.subpixel_aa_enabled { let mut transform = match options.transform { PreparedRenderTransform::Transform2D(transform) => transform, - PreparedRenderTransform::None => Transform2DF32::default(), + PreparedRenderTransform::None => Transform2DF::default(), PreparedRenderTransform::Perspective { .. } => unreachable!(), }; if options.subpixel_aa_enabled { transform = transform - .post_mul(&Transform2DF32::from_scale(Point2DF32::new(3.0, 1.0))) + .post_mul(&Transform2DF::from_scale(Point2DF::new(3.0, 1.0))) } outline.transform(&transform); } @@ -156,9 +156,9 @@ impl Scene { } #[inline] - pub(crate) fn effective_view_box(&self, render_options: &PreparedRenderOptions) -> RectF32 { + pub(crate) fn effective_view_box(&self, render_options: &PreparedRenderOptions) -> RectF { if render_options.subpixel_aa_enabled { - self.view_box.scale_xy(Point2DF32::new(3.0, 1.0)) + self.view_box.scale_xy(Point2DF::new(3.0, 1.0)) } else { self.view_box } diff --git a/renderer/src/tile_map.rs b/renderer/src/tile_map.rs index e83f7438..fa74fce2 100644 --- a/renderer/src/tile_map.rs +++ b/renderer/src/tile_map.rs @@ -8,18 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use pathfinder_geometry::basic::point::Point2DI32; -use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::rect::RectI; #[derive(Debug)] pub struct DenseTileMap { pub data: Vec, - pub rect: RectI32, + pub rect: RectI, } impl DenseTileMap { #[inline] - pub fn new(rect: RectI32) -> DenseTileMap + pub fn new(rect: RectI) -> DenseTileMap where T: Copy + Clone + Default, { @@ -31,7 +31,7 @@ impl DenseTileMap { } #[inline] - pub fn from_builder(build: F, rect: RectI32) -> DenseTileMap + pub fn from_builder(build: F, rect: RectI) -> DenseTileMap where F: FnMut(usize) -> T, { @@ -43,7 +43,7 @@ impl DenseTileMap { } #[inline] - pub fn coords_to_index(&self, coords: Point2DI32) -> Option { + pub fn coords_to_index(&self, coords: Point2DI) -> Option { // TODO(pcwalton): SIMD? if coords.x() < self.rect.min_x() || coords.x() >= self.rect.max_x() @@ -56,14 +56,14 @@ impl DenseTileMap { } #[inline] - pub fn coords_to_index_unchecked(&self, coords: Point2DI32) -> usize { + pub fn coords_to_index_unchecked(&self, coords: Point2DI) -> usize { (coords.y() - self.rect.min_y()) as usize * self.rect.size().x() as usize + (coords.x() - self.rect.min_x()) as usize } #[inline] - pub fn index_to_coords(&self, index: usize) -> Point2DI32 { + pub fn index_to_coords(&self, index: usize) -> Point2DI { let (width, index) = (self.rect.size().x(), index as i32); - self.rect.origin() + Point2DI32::new(index % width, index / width) + self.rect.origin() + Point2DI::new(index % width, index / width) } } diff --git a/renderer/src/tiles.rs b/renderer/src/tiles.rs index fb2c3eaf..e3c567a9 100644 --- a/renderer/src/tiles.rs +++ b/renderer/src/tiles.rs @@ -12,9 +12,9 @@ use crate::builder::SceneBuilder; use crate::gpu_data::{AlphaTileBatchPrimitive, BuiltObject, TileObjectPrimitive}; use crate::paint::{self, PaintId}; use crate::sorted_vector::SortedVector; -use pathfinder_geometry::basic::line_segment::LineSegmentF32; -use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; -use pathfinder_geometry::basic::rect::{RectF32, RectI32}; +use pathfinder_geometry::basic::line_segment::LineSegmentF; +use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::rect::{RectF, RectI}; use pathfinder_geometry::outline::{Contour, Outline, PointIndex}; use pathfinder_geometry::segment::Segment; use std::cmp::Ordering; @@ -44,7 +44,7 @@ impl<'a> Tiler<'a> { pub(crate) fn new( builder: &'a SceneBuilder<'a>, outline: &'a Outline, - view_box: RectF32, + view_box: RectF, object_index: u16, paint_id: PaintId, object_is_opaque: bool, @@ -52,7 +52,7 @@ impl<'a> Tiler<'a> { let bounds = outline .bounds() .intersection(view_box) - .unwrap_or(RectF32::default()); + .unwrap_or(RectF::default()); let built_object = BuiltObject::new(bounds); Tiler { @@ -194,7 +194,7 @@ impl<'a> Tiler<'a> { let current_x = (i32::from(current_tile_x) * TILE_WIDTH as i32) as f32 + current_subtile_x; let tile_right_x = ((i32::from(current_tile_x) + 1) * TILE_WIDTH as i32) as f32; - let current_tile_coords = Point2DI32::new(current_tile_x, tile_y); + let current_tile_coords = Point2DI::new(current_tile_x, tile_y); self.built_object.add_active_fill( self.builder, current_x, @@ -212,7 +212,7 @@ impl<'a> Tiler<'a> { "... emitting backdrop {} @ tile {}", current_winding, current_tile_x ); - let current_tile_coords = Point2DI32::new(current_tile_x, tile_y); + let current_tile_coords = Point2DI::new(current_tile_x, tile_y); if let Some(tile_index) = self .built_object .tile_coords_to_local_index(current_tile_coords) @@ -233,7 +233,7 @@ impl<'a> Tiler<'a> { if segment_subtile_x > current_subtile_x { let current_x = (i32::from(current_tile_x) * TILE_WIDTH as i32) as f32 + current_subtile_x; - let current_tile_coords = Point2DI32::new(current_tile_x, tile_y); + let current_tile_coords = Point2DI::new(current_tile_x, tile_y); self.built_object.add_active_fill( self.builder, current_x, @@ -354,8 +354,8 @@ impl<'a> Tiler<'a> { } } -pub fn round_rect_out_to_tile_bounds(rect: RectF32) -> RectI32 { - rect.scale_xy(Point2DF32::new( +pub fn round_rect_out_to_tile_bounds(rect: RectF) -> RectI { + rect.scale_xy(Point2DF::new( 1.0 / TILE_WIDTH as f32, 1.0 / TILE_HEIGHT as f32, )) @@ -403,7 +403,7 @@ impl PartialOrd for QueuedEndpoint { struct ActiveEdge { segment: Segment, // TODO(pcwalton): Shrink `crossing` down to just one f32? - crossing: Point2DF32, + crossing: Point2DF, } impl ActiveEdge { @@ -416,7 +416,7 @@ impl ActiveEdge { ActiveEdge::from_segment_and_crossing(segment, &crossing) } - fn from_segment_and_crossing(segment: &Segment, crossing: &Point2DF32) -> ActiveEdge { + fn from_segment_and_crossing(segment: &Segment, crossing: &Point2DF) -> ActiveEdge { ActiveEdge { segment: *segment, crossing: *crossing, @@ -451,7 +451,7 @@ impl ActiveEdge { // If necessary, draw initial line. if self.crossing.y() < segment.baseline.min_y() { let first_line_segment = - LineSegmentF32::new(self.crossing, segment.baseline.upper_point()).orient(winding); + LineSegmentF::new(self.crossing, segment.baseline.upper_point()).orient(winding); if self .process_line_segment(&first_line_segment, builder, built_object, tile_y) .is_some() @@ -504,11 +504,11 @@ impl ActiveEdge { fn process_line_segment( &mut self, - line_segment: &LineSegmentF32, + line_segment: &LineSegmentF, builder: &SceneBuilder, built_object: &mut BuiltObject, tile_y: i32, - ) -> Option { + ) -> Option { let tile_bottom = ((i32::from(tile_y) + 1) * TILE_HEIGHT as i32) as f32; debug!( "process_line_segment({:?}, tile_y={}) tile_bottom={}", @@ -535,11 +535,11 @@ impl PartialOrd for ActiveEdge { impl AlphaTileBatchPrimitive { #[inline] - fn new(tile_coords: Point2DI32, + fn new(tile_coords: Point2DI, backdrop: i8, object_index: u16, tile_index: u16, - origin_uv: Point2DI32) + origin_uv: Point2DI) -> AlphaTileBatchPrimitive { AlphaTileBatchPrimitive { tile_x_lo: (tile_coords.x() & 0xff) as u8, @@ -554,8 +554,8 @@ impl AlphaTileBatchPrimitive { } #[inline] - pub fn tile_coords(&self) -> Point2DI32 { - Point2DI32::new( + pub fn tile_coords(&self) -> Point2DI { + Point2DI::new( (self.tile_x_lo as i32) | (((self.tile_hi & 0xf) as i32) << 8), (self.tile_y_lo as i32) | (((self.tile_hi & 0xf0) as i32) << 4), ) diff --git a/renderer/src/z_buffer.rs b/renderer/src/z_buffer.rs index 36ffbb75..bd0c66bf 100644 --- a/renderer/src/z_buffer.rs +++ b/renderer/src/z_buffer.rs @@ -15,8 +15,8 @@ use crate::paint; use crate::scene::PathObject; use crate::tile_map::DenseTileMap; use crate::tiles; -use pathfinder_geometry::basic::point::Point2DI32; -use pathfinder_geometry::basic::rect::RectF32; +use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::rect::RectF; use std::ops::Range; use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering}; @@ -25,20 +25,20 @@ pub struct ZBuffer { } impl ZBuffer { - pub fn new(view_box: RectF32) -> ZBuffer { + pub fn new(view_box: RectF) -> ZBuffer { let tile_rect = tiles::round_rect_out_to_tile_bounds(view_box); ZBuffer { buffer: DenseTileMap::from_builder(|_| AtomicUsize::new(0), tile_rect), } } - pub fn test(&self, coords: Point2DI32, object_index: u32) -> bool { + pub fn test(&self, coords: Point2DI, object_index: u32) -> bool { let tile_index = self.buffer.coords_to_index_unchecked(coords); let existing_depth = self.buffer.data[tile_index as usize].load(AtomicOrdering::SeqCst); existing_depth < object_index as usize + 1 } - pub fn update(&self, coords: Point2DI32, object_index: u16) { + pub fn update(&self, coords: Point2DI, object_index: u16) { let tile_index = self.buffer.coords_to_index_unchecked(coords); let mut old_depth = self.buffer.data[tile_index].load(AtomicOrdering::SeqCst); let new_depth = (object_index + 1) as usize; @@ -83,7 +83,7 @@ impl ZBuffer { } impl SolidTileBatchPrimitive { - fn new(tile_coords: Point2DI32, object_index: u16, origin_uv: Point2DI32) + fn new(tile_coords: Point2DI, object_index: u16, origin_uv: Point2DI) -> SolidTileBatchPrimitive { SolidTileBatchPrimitive { tile_x: tile_coords.x() as i16, diff --git a/simd/src/x86/mod.rs b/simd/src/x86/mod.rs index af90be53..5452480b 100644 --- a/simd/src/x86/mod.rs +++ b/simd/src/x86/mod.rs @@ -163,7 +163,7 @@ impl F32x4 { unsafe { F32x4(x86_64::_mm_shuffle_ps(self.0, other.0, 0b0001_1011)) } } - // FIXME(pcwalton): Move to `Point3DF32`! + // FIXME(pcwalton): Move to `Point3DF`! #[inline] pub fn cross(&self, other: F32x4) -> F32x4 { self.yzxw() * other.zxyw() - self.zxyw() * other.yzxw() diff --git a/svg/src/lib.rs b/svg/src/lib.rs index c4d21c4d..750aa2ff 100644 --- a/svg/src/lib.rs +++ b/svg/src/lib.rs @@ -13,10 +13,10 @@ #[macro_use] extern crate bitflags; -use pathfinder_geometry::basic::line_segment::LineSegmentF32; -use pathfinder_geometry::basic::point::Point2DF32; -use pathfinder_geometry::basic::rect::RectF32; -use pathfinder_geometry::basic::transform2d::{Transform2DF32, Transform2DF32PathIter}; +use pathfinder_geometry::basic::line_segment::LineSegmentF; +use pathfinder_geometry::basic::point::Point2DF; +use pathfinder_geometry::basic::rect::RectF; +use pathfinder_geometry::basic::transform2d::{Transform2DF, Transform2DFPathIter}; use pathfinder_geometry::color::ColorU; use pathfinder_geometry::outline::Outline; use pathfinder_geometry::segment::{Segment, SegmentFlags}; @@ -61,7 +61,7 @@ bitflags! { impl BuiltSVG { // TODO(pcwalton): Allow a global transform to be set. pub fn from_tree(tree: Tree) -> BuiltSVG { - let global_transform = Transform2DF32::default(); + let global_transform = Transform2DF::default(); let mut built_svg = BuiltSVG { scene: Scene::new(), @@ -86,7 +86,7 @@ impl BuiltSVG { built_svg } - fn process_node(&mut self, node: &Node, transform: &Transform2DF32) { + fn process_node(&mut self, node: &Node, transform: &Transform2DF) { let node_transform = usvg_transform_to_transform_2d(&node.transform()); let transform = transform.pre_mul(&node_transform); @@ -122,7 +122,7 @@ impl BuiltSVG { )); let path = UsvgPathToSegments::new(path.segments.iter().cloned()); - let path = Transform2DF32PathIter::new(path, &transform); + let path = Transform2DFPathIter::new(path, &transform); let outline = Outline::from_segments(path); let name = format!("Fill({})", node.id()); @@ -265,15 +265,15 @@ impl PaintExt for Paint { } } -fn usvg_rect_to_euclid_rect(rect: &UsvgRect) -> RectF32 { - RectF32::new( - Point2DF32::new(rect.x as f32, rect.y as f32), - Point2DF32::new(rect.width as f32, rect.height as f32), +fn usvg_rect_to_euclid_rect(rect: &UsvgRect) -> RectF { + RectF::new( + Point2DF::new(rect.x as f32, rect.y as f32), + Point2DF::new(rect.width as f32, rect.height as f32), ) } -fn usvg_transform_to_transform_2d(transform: &UsvgTransform) -> Transform2DF32 { - Transform2DF32::row_major( +fn usvg_transform_to_transform_2d(transform: &UsvgTransform) -> Transform2DF { + Transform2DF::row_major( transform.a as f32, transform.b as f32, transform.c as f32, @@ -288,8 +288,8 @@ where I: Iterator, { iter: I, - first_subpath_point: Point2DF32, - last_subpath_point: Point2DF32, + first_subpath_point: Point2DF, + last_subpath_point: Point2DF, just_moved: bool, } @@ -300,8 +300,8 @@ where fn new(iter: I) -> UsvgPathToSegments { UsvgPathToSegments { iter, - first_subpath_point: Point2DF32::default(), - last_subpath_point: Point2DF32::default(), + first_subpath_point: Point2DF::default(), + last_subpath_point: Point2DF::default(), just_moved: false, } } @@ -316,15 +316,15 @@ where fn next(&mut self) -> Option { match self.iter.next()? { UsvgPathSegment::MoveTo { x, y } => { - let to = Point2DF32::new(x as f32, y as f32); + let to = Point2DF::new(x as f32, y as f32); self.first_subpath_point = to; self.last_subpath_point = to; self.just_moved = true; self.next() } UsvgPathSegment::LineTo { x, y } => { - let to = Point2DF32::new(x as f32, y as f32); - let mut segment = Segment::line(&LineSegmentF32::new(self.last_subpath_point, to)); + let to = Point2DF::new(x as f32, y as f32); + let mut segment = Segment::line(&LineSegmentF::new(self.last_subpath_point, to)); if self.just_moved { segment.flags.insert(SegmentFlags::FIRST_IN_SUBPATH); } @@ -340,12 +340,12 @@ where x, y, } => { - let ctrl0 = Point2DF32::new(x1 as f32, y1 as f32); - let ctrl1 = Point2DF32::new(x2 as f32, y2 as f32); - let to = Point2DF32::new(x as f32, y as f32); + let ctrl0 = Point2DF::new(x1 as f32, y1 as f32); + let ctrl1 = Point2DF::new(x2 as f32, y2 as f32); + let to = Point2DF::new(x as f32, y as f32); let mut segment = Segment::cubic( - &LineSegmentF32::new(self.last_subpath_point, to), - &LineSegmentF32::new(ctrl0, ctrl1), + &LineSegmentF::new(self.last_subpath_point, to), + &LineSegmentF::new(ctrl0, ctrl1), ); if self.just_moved { segment.flags.insert(SegmentFlags::FIRST_IN_SUBPATH); @@ -355,7 +355,7 @@ where Some(segment) } UsvgPathSegment::ClosePath => { - let mut segment = Segment::line(&LineSegmentF32::new( + let mut segment = Segment::line(&LineSegmentF::new( self.last_subpath_point, self.first_subpath_point, )); diff --git a/text/src/lib.rs b/text/src/lib.rs index 19c5701a..d859b944 100644 --- a/text/src/lib.rs +++ b/text/src/lib.rs @@ -13,8 +13,8 @@ use font_kit::error::GlyphLoadingError; use font_kit::hinting::HintingOptions; use font_kit::loader::Loader; use lyon_path::builder::{FlatPathBuilder, PathBuilder}; -use pathfinder_geometry::basic::point::Point2DF32; -use pathfinder_geometry::basic::transform2d::Transform2DF32; +use pathfinder_geometry::basic::point::Point2DF; +use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::outline::{Contour, Outline}; use pathfinder_geometry::stroke::{OutlineStrokeToFill, StrokeStyle}; use pathfinder_renderer::paint::PaintId; @@ -27,7 +27,7 @@ pub trait SceneExt { fn push_glyph(&mut self, font: &F, glyph_id: u32, - transform: &Transform2DF32, + transform: &Transform2DF, render_mode: TextRenderMode, hinting_options: HintingOptions, paint_id: PaintId) @@ -37,7 +37,7 @@ pub trait SceneExt { fn push_layout(&mut self, layout: &Layout, style: &TextStyle, - transform: &Transform2DF32, + transform: &Transform2DF, render_mode: TextRenderMode, hinting_options: HintingOptions, paint_id: PaintId) @@ -47,7 +47,7 @@ pub trait SceneExt { text: &str, style: &TextStyle, collection: &FontCollection, - transform: &Transform2DF32, + transform: &Transform2DF, render_mode: TextRenderMode, hinting_options: HintingOptions, paint_id: PaintId) @@ -59,7 +59,7 @@ impl SceneExt for Scene { fn push_glyph(&mut self, font: &F, glyph_id: u32, - transform: &Transform2DF32, + transform: &Transform2DF, render_mode: TextRenderMode, hinting_options: HintingOptions, paint_id: PaintId) @@ -82,19 +82,19 @@ impl SceneExt for Scene { fn push_layout(&mut self, layout: &Layout, style: &TextStyle, - transform: &Transform2DF32, + transform: &Transform2DF, render_mode: TextRenderMode, hinting_options: HintingOptions, paint_id: PaintId) -> Result<(), GlyphLoadingError> { for glyph in &layout.glyphs { - let offset = Point2DF32::new(glyph.offset.x, glyph.offset.y); + let offset = Point2DF::new(glyph.offset.x, glyph.offset.y); let font = &*glyph.font.font; // FIXME(pcwalton): Cache this! let scale = style.size / (font.metrics().units_per_em as f32); - let scale = Point2DF32::new(scale, -scale); + let scale = Point2DF::new(scale, -scale); let transform = - Transform2DF32::from_scale(scale).post_mul(transform).post_translate(offset); + Transform2DF::from_scale(scale).post_mul(transform).post_translate(offset); self.push_glyph(font, glyph.glyph_id, &transform, @@ -110,7 +110,7 @@ impl SceneExt for Scene { text: &str, style: &TextStyle, collection: &FontCollection, - transform: &Transform2DF32, + transform: &Transform2DF, render_mode: TextRenderMode, hinting_options: HintingOptions, paint_id: PaintId) @@ -129,11 +129,11 @@ pub enum TextRenderMode { struct OutlinePathBuilder { outline: Outline, current_contour: Contour, - transform: Transform2DF32, + transform: Transform2DF, } impl OutlinePathBuilder { - fn new(transform: &Transform2DF32) -> OutlinePathBuilder { + fn new(transform: &Transform2DF) -> OutlinePathBuilder { OutlinePathBuilder { outline: Outline::new(), current_contour: Contour::new(), @@ -147,8 +147,8 @@ impl OutlinePathBuilder { } } - fn convert_point(&self, point: Point2D) -> Point2DF32 { - self.transform.transform_point(Point2DF32::new(point.x, point.y)) + fn convert_point(&self, point: Point2D) -> Point2DF { + self.transform.transform_point(Point2DF::new(point.x, point.y)) } } diff --git a/ui/src/lib.rs b/ui/src/lib.rs index eaff03be..940af245 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -17,8 +17,8 @@ extern crate serde_derive; use hashbrown::HashMap; -use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; -use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::rect::RectI; use pathfinder_geometry::color::ColorU; use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::{BlendState, BufferData, BufferTarget, BufferUploadMode, Device, Primitive}; @@ -66,9 +66,9 @@ static OUTLINE_RECT_LINE_INDICES: [u32; 8] = [0, 1, 2, 3, 4, 5, 6, 7]; pub struct UIPresenter where D: Device { pub event_queue: UIEventQueue, - pub mouse_position: Point2DF32, + pub mouse_position: Point2DF, - framebuffer_size: Point2DI32, + framebuffer_size: Point2DI, texture_program: DebugTextureProgram, texture_vertex_array: DebugTextureVertexArray, @@ -82,7 +82,7 @@ pub struct UIPresenter where D: Device { } impl UIPresenter where D: Device { - pub fn new(device: &D, resources: &dyn ResourceLoader, framebuffer_size: Point2DI32) + pub fn new(device: &D, resources: &dyn ResourceLoader, framebuffer_size: Point2DI) -> UIPresenter { let texture_program = DebugTextureProgram::new(device, resources); let texture_vertex_array = DebugTextureVertexArray::new(device, &texture_program); @@ -98,7 +98,7 @@ impl UIPresenter where D: Device { UIPresenter { event_queue: UIEventQueue::new(), - mouse_position: Point2DF32::default(), + mouse_position: Point2DF::default(), framebuffer_size, @@ -114,24 +114,24 @@ impl UIPresenter where D: Device { } } - pub fn framebuffer_size(&self) -> Point2DI32 { + pub fn framebuffer_size(&self) -> Point2DI { self.framebuffer_size } - pub fn set_framebuffer_size(&mut self, window_size: Point2DI32) { + pub fn set_framebuffer_size(&mut self, window_size: Point2DI) { self.framebuffer_size = window_size; } - pub fn draw_solid_rect(&self, device: &D, rect: RectI32, color: ColorU) { + pub fn draw_solid_rect(&self, device: &D, rect: RectI, color: ColorU) { self.draw_rect(device, rect, color, true); } - pub fn draw_rect_outline(&self, device: &D, rect: RectI32, color: ColorU) { + pub fn draw_rect_outline(&self, device: &D, rect: RectI, color: ColorU) { self.draw_rect(device, rect, color, false); } - fn draw_rect(&self, device: &D, rect: RectI32, color: ColorU, filled: bool) { + fn draw_rect(&self, device: &D, rect: RectI, color: ColorU, filled: bool) { let vertex_data = [ DebugSolidVertex::new(rect.origin()), DebugSolidVertex::new(rect.upper_right()), @@ -183,7 +183,7 @@ impl UIPresenter where D: Device { }); } - pub fn draw_text(&self, device: &D, string: &str, origin: Point2DI32, invert: bool) { + pub fn draw_text(&self, device: &D, string: &str, origin: Point2DI, invert: bool) { let mut next = origin; let char_count = string.chars().count(); let mut vertex_data = Vec::with_capacity(char_count * 4); @@ -195,10 +195,10 @@ impl UIPresenter where D: Device { let info = &self.font.characters[&character]; let position_rect = - RectI32::new(Point2DI32::new(next.x() - info.origin_x, next.y() - info.origin_y), - Point2DI32::new(info.width as i32, info.height as i32)); - let tex_coord_rect = RectI32::new(Point2DI32::new(info.x, info.y), - Point2DI32::new(info.width, info.height)); + RectI::new(Point2DI::new(next.x() - info.origin_x, next.y() - info.origin_y), + Point2DI::new(info.width as i32, info.height as i32)); + let tex_coord_rect = RectI::new(Point2DI::new(info.x, info.y), + Point2DI::new(info.width, info.height)); let first_vertex_index = vertex_data.len(); vertex_data.extend_from_slice(&[ DebugTextureVertex::new(position_rect.origin(), tex_coord_rect.origin()), @@ -222,11 +222,11 @@ impl UIPresenter where D: Device { pub fn draw_texture(&self, device: &D, - origin: Point2DI32, + origin: Point2DI, texture: &D::Texture, color: ColorU) { - let position_rect = RectI32::new(origin, device.texture_size(&texture)); - let tex_coord_rect = RectI32::new(Point2DI32::default(), position_rect.size()); + let position_rect = RectI::new(origin, device.texture_size(&texture)); + let tex_coord_rect = RectI::new(Point2DI::default(), position_rect.size()); let vertex_data = [ DebugTextureVertex::new(position_rect.origin(), tex_coord_rect.origin()), DebugTextureVertex::new(position_rect.upper_right(), tex_coord_rect.upper_right()), @@ -255,16 +255,16 @@ impl UIPresenter where D: Device { SEGMENT_SIZE * segment_count as i32 + (segment_count - 1) as i32 } - pub fn draw_solid_rounded_rect(&self, device: &D, rect: RectI32, color: ColorU) { + pub fn draw_solid_rounded_rect(&self, device: &D, rect: RectI, color: ColorU) { let corner_texture = self.corner_texture(true); let corner_rects = CornerRects::new(device, rect, corner_texture); self.draw_rounded_rect_corners(device, color, corner_texture, &corner_rects); - let solid_rect_mid = RectI32::from_points(corner_rects.upper_left.upper_right(), + let solid_rect_mid = RectI::from_points(corner_rects.upper_left.upper_right(), corner_rects.lower_right.lower_left()); - let solid_rect_left = RectI32::from_points(corner_rects.upper_left.lower_left(), + let solid_rect_left = RectI::from_points(corner_rects.upper_left.lower_left(), corner_rects.lower_left.upper_right()); - let solid_rect_right = RectI32::from_points(corner_rects.upper_right.lower_left(), + let solid_rect_right = RectI::from_points(corner_rects.upper_right.lower_left(), corner_rects.lower_right.upper_right()); let vertex_data = vec![ DebugSolidVertex::new(solid_rect_mid.origin()), @@ -295,7 +295,7 @@ impl UIPresenter where D: Device { true); } - pub fn draw_rounded_rect_outline(&self, device: &D, rect: RectI32, color: ColorU) { + pub fn draw_rounded_rect_outline(&self, device: &D, rect: RectI, color: ColorU) { let corner_texture = self.corner_texture(false); let corner_rects = CornerRects::new(device, rect, corner_texture); self.draw_rounded_rect_corners(device, color, corner_texture, &corner_rects); @@ -316,7 +316,7 @@ impl UIPresenter where D: Device { } // TODO(pcwalton): `LineSegmentI32`. - fn draw_line(&self, device: &D, from: Point2DI32, to: Point2DI32, color: ColorU) { + fn draw_line(&self, device: &D, from: Point2DI, to: Point2DI, color: ColorU) { let vertex_data = vec![DebugSolidVertex::new(from), DebugSolidVertex::new(to)]; self.draw_solid_rects_with_vertex_data(device, &vertex_data, &[0, 1], color, false); @@ -328,7 +328,7 @@ impl UIPresenter where D: Device { texture: &D::Texture, corner_rects: &CornerRects) { let corner_size = device.texture_size(&texture); - let tex_coord_rect = RectI32::new(Point2DI32::default(), corner_size); + let tex_coord_rect = RectI::new(Point2DI::default(), corner_size); let vertex_data = vec![ DebugTextureVertex::new( @@ -412,12 +412,12 @@ impl UIPresenter where D: Device { }); } - pub fn draw_button(&mut self, device: &D, origin: Point2DI32, texture: &D::Texture) -> bool { - let button_rect = RectI32::new(origin, Point2DI32::new(BUTTON_WIDTH, BUTTON_HEIGHT)); + pub fn draw_button(&mut self, device: &D, origin: Point2DI, texture: &D::Texture) -> bool { + let button_rect = RectI::new(origin, Point2DI::new(BUTTON_WIDTH, BUTTON_HEIGHT)); self.draw_solid_rounded_rect(device, button_rect, WINDOW_COLOR); self.draw_rounded_rect_outline(device, button_rect, OUTLINE_COLOR); self.draw_texture(device, - origin + Point2DI32::new(PADDING, PADDING), + origin + Point2DI::new(PADDING, PADDING), texture, BUTTON_ICON_COLOR); self.event_queue.handle_mouse_down_in_rect(button_rect).is_some() @@ -425,7 +425,7 @@ impl UIPresenter where D: Device { pub fn draw_text_switch(&mut self, device: &D, - mut origin: Point2DI32, + mut origin: Point2DI, segment_labels: &[&str], mut value: u8) -> u8 { @@ -436,15 +436,15 @@ impl UIPresenter where D: Device { value = new_value; } - origin = origin + Point2DI32::new(0, BUTTON_TEXT_OFFSET); + origin = origin + Point2DI::new(0, BUTTON_TEXT_OFFSET); for (segment_index, segment_label) in segment_labels.iter().enumerate() { let label_width = self.measure_text(segment_label); let offset = SEGMENT_SIZE / 2 - label_width / 2; self.draw_text(device, segment_label, - origin + Point2DI32::new(offset, 0), + origin + Point2DI::new(offset, 0), segment_index as u8 == value); - origin += Point2DI32::new(SEGMENT_SIZE + 1, 0); + origin += Point2DI::new(SEGMENT_SIZE + 1, 0); } value @@ -452,7 +452,7 @@ impl UIPresenter where D: Device { pub fn draw_image_segmented_control(&mut self, device: &D, - mut origin: Point2DI32, + mut origin: Point2DI, segment_textures: &[&D::Texture], mut value: Option) -> Option { @@ -469,7 +469,7 @@ impl UIPresenter where D: Device { for (segment_index, segment_texture) in segment_textures.iter().enumerate() { let texture_width = device.texture_size(segment_texture).x(); - let offset = Point2DI32::new(SEGMENT_SIZE / 2 - texture_width / 2, PADDING); + let offset = Point2DI::new(SEGMENT_SIZE / 2 - texture_width / 2, PADDING); let color = if Some(segment_index as u8) == value { WINDOW_COLOR } else { @@ -477,7 +477,7 @@ impl UIPresenter where D: Device { }; self.draw_texture(device, origin + offset, segment_texture, color); - origin += Point2DI32::new(SEGMENT_SIZE + 1, 0); + origin += Point2DI::new(SEGMENT_SIZE + 1, 0); } clicked_segment @@ -485,12 +485,12 @@ impl UIPresenter where D: Device { fn draw_segmented_control(&mut self, device: &D, - origin: Point2DI32, + origin: Point2DI, mut value: Option, segment_count: u8) -> Option { let widget_width = self.measure_segmented_control(segment_count); - let widget_rect = RectI32::new(origin, Point2DI32::new(widget_width, BUTTON_HEIGHT)); + let widget_rect = RectI::new(origin, Point2DI::new(widget_width, BUTTON_HEIGHT)); let mut clicked_segment = None; if let Some(position) = self.event_queue.handle_mouse_down_in_rect(widget_rect) { @@ -505,15 +505,15 @@ impl UIPresenter where D: Device { self.draw_rounded_rect_outline(device, widget_rect, OUTLINE_COLOR); if let Some(value) = value { - let highlight_size = Point2DI32::new(SEGMENT_SIZE, BUTTON_HEIGHT); + let highlight_size = Point2DI::new(SEGMENT_SIZE, BUTTON_HEIGHT); let x_offset = value as i32 * SEGMENT_SIZE + (value as i32 - 1); self.draw_solid_rounded_rect(device, - RectI32::new(origin + Point2DI32::new(x_offset, 0), + RectI::new(origin + Point2DI::new(x_offset, 0), highlight_size), TEXT_COLOR); } - let mut segment_origin = origin + Point2DI32::new(SEGMENT_SIZE + 1, 0); + let mut segment_origin = origin + Point2DI::new(SEGMENT_SIZE + 1, 0); for next_segment_index in 1..segment_count { let prev_segment_index = next_segment_index - 1; match value { @@ -521,29 +521,29 @@ impl UIPresenter where D: Device { _ => { self.draw_line(device, segment_origin, - segment_origin + Point2DI32::new(0, BUTTON_HEIGHT), + segment_origin + Point2DI::new(0, BUTTON_HEIGHT), TEXT_COLOR); } } - segment_origin = segment_origin + Point2DI32::new(SEGMENT_SIZE + 1, 0); + segment_origin = segment_origin + Point2DI::new(SEGMENT_SIZE + 1, 0); } clicked_segment } - pub fn draw_tooltip(&self, device: &D, string: &str, rect: RectI32) { + pub fn draw_tooltip(&self, device: &D, string: &str, rect: RectI) { if !rect.to_f32().contains_point(self.mouse_position) { return; } let text_size = self.measure_text(string); - let window_size = Point2DI32::new(text_size + PADDING * 2, TOOLTIP_HEIGHT); - let origin = rect.origin() - Point2DI32::new(0, window_size.y() + PADDING); + let window_size = Point2DI::new(text_size + PADDING * 2, TOOLTIP_HEIGHT); + let origin = rect.origin() - Point2DI::new(0, window_size.y() + PADDING); - self.draw_solid_rounded_rect(device, RectI32::new(origin, window_size), WINDOW_COLOR); + self.draw_solid_rounded_rect(device, RectI::new(origin, window_size), WINDOW_COLOR); self.draw_text(device, string, - origin + Point2DI32::new(PADDING, PADDING + FONT_ASCENT), + origin + Point2DI::new(PADDING, PADDING + FONT_ASCENT), false); } } @@ -668,7 +668,7 @@ struct DebugTextureVertex { } impl DebugTextureVertex { - fn new(position: Point2DI32, tex_coord: Point2DI32) -> DebugTextureVertex { + fn new(position: Point2DI, tex_coord: Point2DI) -> DebugTextureVertex { DebugTextureVertex { position_x: position.x() as i16, position_y: position.y() as i16, @@ -687,26 +687,26 @@ struct DebugSolidVertex { } impl DebugSolidVertex { - fn new(position: Point2DI32) -> DebugSolidVertex { + fn new(position: Point2DI) -> DebugSolidVertex { DebugSolidVertex { position_x: position.x() as i16, position_y: position.y() as i16 } } } struct CornerRects { - upper_left: RectI32, - upper_right: RectI32, - lower_left: RectI32, - lower_right: RectI32, + upper_left: RectI, + upper_right: RectI, + lower_left: RectI, + lower_right: RectI, } impl CornerRects { - fn new(device: &D, rect: RectI32, texture: &D::Texture) -> CornerRects where D: Device { + fn new(device: &D, rect: RectI, texture: &D::Texture) -> CornerRects where D: Device { let size = device.texture_size(texture); CornerRects { - upper_left: RectI32::new(rect.origin(), size), - upper_right: RectI32::new(rect.upper_right() - Point2DI32::new(size.x(), 0), size), - lower_left: RectI32::new(rect.lower_left() - Point2DI32::new(0, size.y()), size), - lower_right: RectI32::new(rect.lower_right() - size, size), + upper_left: RectI::new(rect.origin(), size), + upper_right: RectI::new(rect.upper_right() - Point2DI::new(size.x(), 0), size), + lower_left: RectI::new(rect.lower_left() - Point2DI::new(0, size.y()), size), + lower_right: RectI::new(rect.lower_right() - size, size), } } } @@ -739,7 +739,7 @@ impl UIEventQueue { mem::replace(&mut self.events, vec![]) } - pub fn handle_mouse_down_in_rect(&mut self, rect: RectI32) -> Option { + pub fn handle_mouse_down_in_rect(&mut self, rect: RectI) -> Option { let (mut remaining_events, mut result) = (vec![], None); for event in self.events.drain(..) { match event { @@ -753,7 +753,7 @@ impl UIEventQueue { result } - pub fn handle_mouse_down_or_dragged_in_rect(&mut self, rect: RectI32) -> Option { + pub fn handle_mouse_down_or_dragged_in_rect(&mut self, rect: RectI) -> Option { let (mut remaining_events, mut result) = (vec![], None); for event in self.events.drain(..) { match event { @@ -771,8 +771,8 @@ impl UIEventQueue { #[derive(Clone, Copy)] pub struct MousePosition { - pub absolute: Point2DI32, - pub relative: Point2DI32, + pub absolute: Point2DI, + pub relative: Point2DI, } #[derive(Deserialize)]