From a1b0df0a425572c650c0f3ca5ffdc13ded2398a7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 3 Jun 2019 12:39:29 -0700 Subject: [PATCH] Rename `Point2DF` to `Vector2F`, `Point3DF` to `Vector4F`, and `LineSegmentF` to `LineSegment2F`. Straw poll on Twitter suggested that these names were preferred. --- c/include/pathfinder/pathfinder.h | 28 +-- c/src/lib.rs | 44 ++-- canvas/src/lib.rs | 38 ++-- demo/android/rust/src/lib.rs | 18 +- demo/common/src/camera.rs | 20 +- demo/common/src/lib.rs | 26 +-- demo/common/src/ui.rs | 76 +++---- demo/common/src/window.rs | 14 +- demo/native/src/main.rs | 12 +- examples/c_canvas_minimal/c_canvas_minimal.c | 10 +- examples/canvas_minimal/src/main.rs | 14 +- examples/canvas_moire/src/main.rs | 20 +- examples/canvas_text/src/main.rs | 8 +- geometry/src/basic/line_segment.rs | 80 ++++---- geometry/src/basic/mod.rs | 2 +- geometry/src/basic/rect.rs | 62 +++--- geometry/src/basic/transform2d.rs | 46 ++--- geometry/src/basic/transform3d.rs | 24 +-- geometry/src/basic/{point.rs => vector.rs} | 200 +++++++++---------- geometry/src/clip.rs | 38 ++-- geometry/src/dilation.rs | 12 +- geometry/src/outline.rs | 70 +++---- geometry/src/segment.rs | 56 +++--- geometry/src/stroke.rs | 62 +++--- geometry/src/unit_vector.rs | 12 +- gl/src/lib.rs | 14 +- gpu/src/lib.rs | 14 +- renderer/src/builder.rs | 36 ++-- renderer/src/gpu/debug.rs | 28 +-- renderer/src/gpu/renderer.rs | 22 +- renderer/src/gpu_data.rs | 4 +- renderer/src/options.rs | 14 +- renderer/src/paint.rs | 10 +- renderer/src/scene.rs | 6 +- renderer/src/tile_map.rs | 10 +- renderer/src/tiles.rs | 30 +-- renderer/src/z_buffer.rs | 8 +- simd/src/x86/mod.rs | 2 +- svg/src/lib.rs | 34 ++-- text/src/lib.rs | 10 +- ui/src/lib.rs | 88 ++++---- 41 files changed, 661 insertions(+), 661 deletions(-) rename geometry/src/basic/{point.rs => vector.rs} (52%) diff --git a/c/include/pathfinder/pathfinder.h b/c/include/pathfinder/pathfinder.h index b047b87a..d82ec435 100644 --- a/c/include/pathfinder/pathfinder.h +++ b/c/include/pathfinder/pathfinder.h @@ -55,20 +55,20 @@ struct PFColorF { float r, g, b, a; }; typedef struct PFColorF PFColorF; -struct PFPoint2DF { +struct PFVector2F { float x, y; }; -typedef struct PFPoint2DF PFPoint2DF; -struct PFPoint2DI { +typedef struct PFVector2F PFVector2F; +struct PFVector2I { int32_t x, y; }; -typedef struct PFPoint2DI PFPoint2DI; +typedef struct PFVector2I PFVector2I; struct PFRectF { - PFPoint2DF origin, lower_right; + PFVector2F origin, lower_right; }; typedef struct PFRectF PFRectF; struct PFRectI { - PFPoint2DI origin, lower_right; + PFVector2I origin, lower_right; }; typedef struct PFRectI PFRectI; @@ -112,7 +112,7 @@ typedef struct PFSceneProxy *PFSceneProxyRef; // `canvas` -PFCanvasRef PFCanvasCreate(PFCanvasFontContextRef font_context, const PFPoint2DF *size); +PFCanvasRef PFCanvasCreate(PFCanvasFontContextRef font_context, const PFVector2F *size); void PFCanvasDestroy(PFCanvasRef canvas); PFCanvasFontContextRef PFCanvasFontContextCreate(); void PFCanvasFontContextDestroy(PFCanvasFontContextRef font_context); @@ -126,18 +126,18 @@ void PFCanvasStrokePath(PFCanvasRef canvas, PFPathRef path); PFPathRef PFPathCreate(); void PFPathDestroy(PFPathRef path); PFPathRef PFPathClone(PFPathRef path); -void PFPathMoveTo(PFPathRef path, const PFPoint2DF *to); -void PFPathLineTo(PFPathRef path, const PFPoint2DF *to); -void PFPathQuadraticCurveTo(PFPathRef path, const PFPoint2DF *ctrl, const PFPoint2DF *to); +void PFPathMoveTo(PFPathRef path, const PFVector2F *to); +void PFPathLineTo(PFPathRef path, const PFVector2F *to); +void PFPathQuadraticCurveTo(PFPathRef path, const PFVector2F *ctrl, const PFVector2F *to); void PFPathBezierCurveTo(PFPathRef path, - const PFPoint2DF *ctrl0, - const PFPoint2DF *ctrl1, - const PFPoint2DF *to); + const PFVector2F *ctrl0, + const PFVector2F *ctrl1, + const PFVector2F *to); void PFPathClosePath(PFPathRef path); // `gl` -PFGLDestFramebufferRef PFGLDestFramebufferCreateFullWindow(const PFPoint2DI *window_size); +PFGLDestFramebufferRef PFGLDestFramebufferCreateFullWindow(const PFVector2I *window_size); void PFGLDestFramebufferDestroy(PFGLDestFramebufferRef dest_framebuffer); PFGLDeviceRef PFGLDeviceCreate(PFGLVersion version, uint32_t default_framebuffer); void PFGLDeviceDestroy(PFGLDeviceRef device); diff --git a/c/src/lib.rs b/c/src/lib.rs index 4cd7ff68..a27dbd20 100644 --- a/c/src/lib.rs +++ b/c/src/lib.rs @@ -12,7 +12,7 @@ use gl; use pathfinder_canvas::{CanvasFontContext, CanvasRenderingContext2D, Path2D}; -use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; use pathfinder_geometry::basic::rect::{RectF, RectI}; use pathfinder_geometry::color::ColorF; use pathfinder_geometry::stroke::LineCap; @@ -49,24 +49,24 @@ pub type PFLineCap = u8; // `geometry` #[repr(C)] -pub struct PFPoint2DF { +pub struct PFVector2F { pub x: f32, pub y: f32, } #[repr(C)] -pub struct PFPoint2DI { +pub struct PFVector2I { pub x: i32, pub y: i32, } #[repr(C)] pub struct PFRectF { - pub origin: PFPoint2DF, - pub lower_right: PFPoint2DF, + pub origin: PFVector2F, + pub lower_right: PFVector2F, } #[repr(C)] pub struct PFRectI { - pub origin: PFPoint2DI, - pub lower_right: PFPoint2DI, + pub origin: PFVector2I, + pub lower_right: PFVector2I, } #[repr(C)] pub struct PFColorF { @@ -110,7 +110,7 @@ pub struct PFRenderOptions { #[no_mangle] pub unsafe extern "C" fn PFCanvasCreate(font_context: PFCanvasFontContextRef, - size: *const PFPoint2DF) + size: *const PFVector2F) -> PFCanvasRef { Box::into_raw(Box::new(CanvasRenderingContext2D::new(*Box::from_raw(font_context), (*size).to_rust()))) @@ -189,27 +189,27 @@ pub unsafe extern "C" fn PFPathClone(path: PFPathRef) -> PFPathRef { } #[no_mangle] -pub unsafe extern "C" fn PFPathMoveTo(path: PFPathRef, to: *const PFPoint2DF) { +pub unsafe extern "C" fn PFPathMoveTo(path: PFPathRef, to: *const PFVector2F) { (*path).move_to((*to).to_rust()) } #[no_mangle] -pub unsafe extern "C" fn PFPathLineTo(path: PFPathRef, to: *const PFPoint2DF) { +pub unsafe extern "C" fn PFPathLineTo(path: PFPathRef, to: *const PFVector2F) { (*path).line_to((*to).to_rust()) } #[no_mangle] pub unsafe extern "C" fn PFPathQuadraticCurveTo(path: PFPathRef, - ctrl: *const PFPoint2DF, - to: *const PFPoint2DF) { + ctrl: *const PFVector2F, + to: *const PFVector2F) { (*path).quadratic_curve_to((*ctrl).to_rust(), (*to).to_rust()) } #[no_mangle] pub unsafe extern "C" fn PFPathBezierCurveTo(path: PFPathRef, - ctrl0: *const PFPoint2DF, - ctrl1: *const PFPoint2DF, - to: *const PFPoint2DF) { + ctrl0: *const PFVector2F, + ctrl1: *const PFVector2F, + to: *const PFVector2F) { (*path).bezier_curve_to((*ctrl0).to_rust(), (*ctrl1).to_rust(), (*to).to_rust()) } @@ -258,7 +258,7 @@ pub unsafe extern "C" fn PFResourceLoaderDestroy(loader: PFResourceLoaderRef) { // `gpu` #[no_mangle] -pub unsafe extern "C" fn PFGLDestFramebufferCreateFullWindow(window_size: *const PFPoint2DI) +pub unsafe extern "C" fn PFGLDestFramebufferCreateFullWindow(window_size: *const PFVector2I) -> PFGLDestFramebufferRef { Box::into_raw(Box::new(DestFramebuffer::full_window((*window_size).to_rust()))) } @@ -337,17 +337,17 @@ impl PFRectI { } } -impl PFPoint2DF { +impl PFVector2F { #[inline] - pub fn to_rust(&self) -> Point2DF { - Point2DF::new(self.x, self.y) + pub fn to_rust(&self) -> Vector2F { + Vector2F::new(self.x, self.y) } } -impl PFPoint2DI { +impl PFVector2I { #[inline] - pub fn to_rust(&self) -> Point2DI { - Point2DI::new(self.x, self.y) + pub fn to_rust(&self) -> Vector2I { + Vector2I::new(self.x, self.y) } } diff --git a/canvas/src/lib.rs b/canvas/src/lib.rs index 2b50c296..c3a0f033 100644 --- a/canvas/src/lib.rs +++ b/canvas/src/lib.rs @@ -14,8 +14,8 @@ 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::line_segment::LineSegmentF; -use pathfinder_geometry::basic::point::Point2DF; +use pathfinder_geometry::basic::line_segment::LineSegment2F; +use pathfinder_geometry::basic::vector::Vector2F; use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::color::ColorU; @@ -44,9 +44,9 @@ pub struct CanvasRenderingContext2D { impl CanvasRenderingContext2D { #[inline] - pub fn new(font_context: CanvasFontContext, size: Point2DF) -> CanvasRenderingContext2D { + pub fn new(font_context: CanvasFontContext, size: Vector2F) -> CanvasRenderingContext2D { let mut scene = Scene::new(); - scene.set_view_box(RectF::new(Point2DF::default(), size)); + scene.set_view_box(RectF::new(Vector2F::default(), size)); CanvasRenderingContext2D::from_scene(font_context, scene) } @@ -82,12 +82,12 @@ impl CanvasRenderingContext2D { // Drawing text - pub fn fill_text(&mut self, string: &str, position: Point2DF) { + pub fn fill_text(&mut self, string: &str, position: Vector2F) { let paint_id = self.scene.push_paint(&self.current_state.fill_paint); self.fill_or_stroke_text(string, position, paint_id, TextRenderMode::Fill); } - pub fn stroke_text(&mut self, string: &str, position: Point2DF) { + pub fn stroke_text(&mut self, string: &str, position: Vector2F) { let paint_id = self.scene.push_paint(&self.current_state.stroke_paint); let render_mode = TextRenderMode::Stroke(self.current_state.resolve_stroke_style()); self.fill_or_stroke_text(string, position, paint_id, render_mode); @@ -99,7 +99,7 @@ impl CanvasRenderingContext2D { fn fill_or_stroke_text(&mut self, string: &str, - mut position: Point2DF, + mut position: Vector2F, paint_id: PaintId, render_mode: TextRenderMode) { let layout = self.layout_text(string); @@ -314,41 +314,41 @@ impl Path2D { } #[inline] - pub fn move_to(&mut self, to: Point2DF) { + pub fn move_to(&mut self, to: Vector2F) { // TODO(pcwalton): Cull degenerate contours. self.flush_current_contour(); self.current_contour.push_endpoint(to); } #[inline] - pub fn line_to(&mut self, to: Point2DF) { + pub fn line_to(&mut self, to: Vector2F) { self.current_contour.push_endpoint(to); } #[inline] - pub fn quadratic_curve_to(&mut self, ctrl: Point2DF, to: Point2DF) { + pub fn quadratic_curve_to(&mut self, ctrl: Vector2F, to: Vector2F) { self.current_contour.push_quadratic(ctrl, to); } #[inline] - pub fn bezier_curve_to(&mut self, ctrl0: Point2DF, ctrl1: Point2DF, to: Point2DF) { + pub fn bezier_curve_to(&mut self, ctrl0: Vector2F, ctrl1: Vector2F, to: Vector2F) { self.current_contour.push_cubic(ctrl0, ctrl1, to); } #[inline] pub fn arc(&mut self, - center: Point2DF, + center: Vector2F, radius: f32, start_angle: f32, end_angle: f32, direction: ArcDirection) { - let mut transform = Transform2DF::from_scale(Point2DF::splat(radius)); + let mut transform = Transform2DF::from_scale(Vector2F::splat(radius)); transform = transform.post_mul(&Transform2DF::from_translation(center)); self.current_contour.push_arc(&transform, start_angle, end_angle, direction); } #[inline] - pub fn arc_to(&mut self, ctrl: Point2DF, to: Point2DF, radius: f32) { + pub fn arc_to(&mut self, ctrl: Vector2F, to: Vector2F, radius: f32) { // FIXME(pcwalton): What should we do if there's no initial point? let from = self.current_contour.last_position().unwrap_or_default(); let (v0, v1) = (from - ctrl, to - ctrl); @@ -357,11 +357,11 @@ impl Path2D { let bisector = vu0 + vu1; let center = ctrl + bisector.scale(hypot / bisector.length()); - let mut transform = Transform2DF::from_scale(Point2DF::splat(radius)); + let mut transform = Transform2DF::from_scale(Vector2F::splat(radius)); transform = transform.post_mul(&Transform2DF::from_translation(center)); - let chord = LineSegmentF::new(vu0.yx().scale_xy(Point2DF::new(-1.0, 1.0)), - vu1.yx().scale_xy(Point2DF::new(1.0, -1.0))); + let chord = LineSegment2F::new(vu0.yx().scale_xy(Vector2F::new(-1.0, 1.0)), + vu1.yx().scale_xy(Vector2F::new(1.0, -1.0))); // FIXME(pcwalton): Is clockwise direction correct? self.current_contour.push_arc_from_unit_chord(&transform, chord, ArcDirection::CW); @@ -377,8 +377,8 @@ impl Path2D { } pub fn ellipse(&mut self, - center: Point2DF, - axes: Point2DF, + center: Vector2F, + axes: Vector2F, rotation: f32, start_angle: f32, end_angle: f32) { diff --git a/demo/android/rust/src/lib.rs b/demo/android/rust/src/lib.rs index 7dadd259..6e322418 100644 --- a/demo/android/rust/src/lib.rs +++ b/demo/android/rust/src/lib.rs @@ -16,7 +16,7 @@ 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::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; use pathfinder_geometry::basic::rect::RectI; use pathfinder_gl::GLVersion; use pathfinder_gpu::resources::ResourceLoader; @@ -48,7 +48,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder width: i32, height: i32, ) { - let logical_size = Point2DI::new(width, height); + let logical_size = Vector2I::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: Point2DI::new(width, height), + logical_size: Vector2I::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(Point2DI::new(x, y))) + .push(Event::MouseDown(Vector2I::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(Point2DI::new(x, y))) + .push(Event::MouseDragged(Vector2I::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, Point2DI::new(center_x, center_y))) + .push(Event::Zoom(factor, Vector2I::new(center_x, center_y))) } #[no_mangle] @@ -188,7 +188,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder } struct WindowImpl { - size: Point2DI, + size: Vector2I, } impl Window for WindowImpl { @@ -204,8 +204,8 @@ impl Window for WindowImpl { width = width / 2; offset_x = (index as i32) * width; } - let size = Point2DI::new(width, height); - let offset = Point2DI::new(offset_x, 0); + let size = Vector2I::new(width, height); + let offset = Vector2I::new(offset_x, 0); RectI::new(offset, size) } diff --git a/demo/common/src/camera.rs b/demo/common/src/camera.rs index 7f80a334..f8dc6445 100644 --- a/demo/common/src/camera.rs +++ b/demo/common/src/camera.rs @@ -14,7 +14,7 @@ // proper. use crate::window::{OcularTransform, View}; -use pathfinder_geometry::basic::point::{Point2DF, Point2DI, Point3DF}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I, Vector4F}; use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF}; @@ -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: Point3DF, + velocity: Vector4F, }, } impl Camera { - pub fn new(mode: Mode, view_box: RectF, viewport_size: Point2DI) -> Camera { + pub fn new(mode: Mode, view_box: RectF, viewport_size: Vector2I) -> Camera { if mode == Mode::TwoD { Camera::new_2d(view_box, viewport_size) } else { @@ -52,14 +52,14 @@ impl Camera { } } - fn new_2d(view_box: RectF, viewport_size: Point2DI) -> Camera { + fn new_2d(view_box: RectF, viewport_size: Vector2I) -> 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(Transform2DF::from_scale(Point2DF::splat(scale)).post_translate(origin)) + Camera::TwoD(Transform2DF::from_scale(Vector2F::splat(scale)).post_translate(origin)) } - fn new_3d(mode: Mode, view_box: RectF, viewport_size: Point2DI) -> Camera { + fn new_3d(mode: Mode, view_box: RectF, viewport_size: Vector2I) -> Camera { let viewport_count = mode.viewport_count(); let fov_y = FRAC_PI_4; @@ -96,7 +96,7 @@ impl Camera { scene_transform, eye_transforms, modelview_transform: CameraTransform3D::new(view_box), - velocity: Point3DF::default(), + velocity: Vector4F::default(), } } @@ -120,7 +120,7 @@ impl Camera { #[derive(Clone, Copy, Debug)] pub struct CameraTransform3D { - position: Point3DF, + position: Vector4F, pub yaw: f32, pub pitch: f32, scale: f32, @@ -130,7 +130,7 @@ impl CameraTransform3D { fn new(view_box: RectF) -> CameraTransform3D { let scale = scale_factor_for_view_box(view_box); CameraTransform3D { - position: Point3DF::new( + position: Vector4F::new( 0.5 * view_box.max_x(), -0.5 * view_box.max_y(), 1.5 / scale, @@ -142,7 +142,7 @@ impl CameraTransform3D { } } - pub fn offset(&mut self, vector: Point3DF) -> bool { + pub fn offset(&mut self, vector: Vector4F) -> bool { let update = !vector.is_zero(); if update { let rotation = Transform3DF::from_rotation(-self.yaw, -self.pitch, 0.0); diff --git a/demo/common/src/lib.rs b/demo/common/src/lib.rs index 0a3c0eba..f41bfe22 100644 --- a/demo/common/src/lib.rs +++ b/demo/common/src/lib.rs @@ -19,7 +19,7 @@ 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::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::color::ColorU; @@ -99,7 +99,7 @@ pub struct DemoApp where W: Window { pub dirty: bool, expire_message_event_id: u32, message_epoch: u32, - last_mouse_position: Point2DI, + last_mouse_position: Vector2I, 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: Point2DI::default(), + last_mouse_position: Vector2I::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]); - Point2DF::new(x, y).scale(font_size) + Vector2F::new(x, y).scale(font_size) } else { - Point2DF::default() + Vector2F::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(RectF::new(Point2DF::default(), + self.scene_proxy.set_view_box(RectF::new(Vector2F::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(Point2DF::splat(scale_delta)); + *transform = transform.post_scale(Vector2F::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: Point2DI) -> MousePosition { + fn process_mouse_position(&mut self, new_position: Vector2I) -> 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 = Point2DF::splat(1.0 + CAMERA_ZOOM_AMOUNT_2D); + let scale = Vector2F::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 = Point2DF::splat(1.0 - CAMERA_ZOOM_AMOUNT_2D); + let scale = Vector2F::splat(1.0 - CAMERA_ZOOM_AMOUNT_2D); let center = center_of_window(&self.window_size); *transform = transform .post_translate(-center) @@ -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) -> Point2DF { +fn center_of_window(window_size: &WindowSize) -> Vector2F { window_size.device_size().to_f32().scale(0.5) } @@ -807,10 +807,10 @@ struct SceneMetadata { 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: Point2DI) -> SceneMetadata { + fn new_clipping_view_box(scene: &mut Scene, viewport_size: Vector2I) -> SceneMetadata { let view_box = scene.view_box(); let monochrome_color = scene.monochrome_color(); - scene.set_view_box(RectF::new(Point2DF::default(), viewport_size.to_f32())); + scene.set_view_box(RectF::new(Vector2F::default(), viewport_size.to_f32())); SceneMetadata { view_box, monochrome_color } } } diff --git a/demo/common/src/ui.rs b/demo/common/src/ui.rs index a857abc6..0a13c3bc 100644 --- a/demo/common/src/ui.rs +++ b/demo/common/src/ui.rs @@ -11,7 +11,7 @@ use crate::camera::Mode; use crate::window::Window; use crate::{BackgroundColor, Options}; -use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; use pathfinder_geometry::basic::rect::RectI; use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::Device; @@ -152,9 +152,9 @@ where // Draw button strip. let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING; - let mut position = Point2DI::new(PADDING, bottom - BUTTON_HEIGHT); + let mut position = Vector2I::new(PADDING, bottom - BUTTON_HEIGHT); - let button_size = Point2DI::new(BUTTON_WIDTH, BUTTON_HEIGHT); + let button_size = Vector2I::new(BUTTON_WIDTH, BUTTON_HEIGHT); // Draw text effects button. if self.show_text_effects { @@ -170,7 +170,7 @@ where RectI::new(position, button_size), ); } - position += Point2DI::new(button_size.x() + PADDING, 0); + position += Vector2I::new(button_size.x() + PADDING, 0); } // Draw open button. @@ -182,7 +182,7 @@ where debug_ui_presenter.ui_presenter.draw_tooltip(device, "Open SVG", RectI::new(position, button_size)); - position += Point2DI::new(BUTTON_WIDTH + PADDING, 0); + position += Vector2I::new(BUTTON_WIDTH + PADDING, 0); // Draw screenshot button. if debug_ui_presenter.ui_presenter.draw_button(device, @@ -200,7 +200,7 @@ where // Draw screenshot panel, if necessary. self.draw_screenshot_panel(device, window, debug_ui_presenter, position.x(), action); - position += Point2DI::new(button_size.x() + PADDING, 0); + position += Vector2I::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 = Point2DI::new(mode_switch_width, BUTTON_HEIGHT); + let mode_switch_size = Vector2I::new(mode_switch_width, BUTTON_HEIGHT); debug_ui_presenter.ui_presenter.draw_tooltip( device, "2D/3D/VR Mode", RectI::new(position, mode_switch_size), ); - position += Point2DI::new(mode_switch_width + PADDING, 0); + position += Vector2I::new(mode_switch_width + PADDING, 0); // Draw background switch. if debug_ui_presenter.ui_presenter.draw_button(device, @@ -242,7 +242,7 @@ where // Draw background panel, if necessary. self.draw_background_panel(device, debug_ui_presenter, position.x(), action, model); - position += Point2DI::new(button_size.x() + PADDING, 0); + position += Vector2I::new(button_size.x() + PADDING, 0); // Draw effects panel, if necessary. self.draw_effects_panel(device, debug_ui_presenter, model); @@ -261,7 +261,7 @@ where RectI::new(position, button_size)); } self.draw_rotate_panel(device, debug_ui_presenter, position.x(), action, model); - position += Point2DI::new(BUTTON_WIDTH + PADDING, 0); + position += Vector2I::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: Point2DI, + position: Vector2I, action: &mut UIAction, ) { let zoom_segmented_control_width = debug_ui_presenter.ui_presenter.measure_segmented_control(3); let zoom_segmented_control_rect = - RectI::new(position, Point2DI::new(zoom_segmented_control_width, BUTTON_HEIGHT)); + RectI::new(position, Vector2I::new(zoom_segmented_control_width, BUTTON_HEIGHT)); debug_ui_presenter.ui_presenter.draw_tooltip(device, "Zoom", zoom_segmented_control_rect); let zoom_textures = &[ @@ -306,8 +306,8 @@ where } let message_size = debug_ui_presenter.ui_presenter.measure_text(&model.message); - let window_origin = Point2DI::new(PADDING, PADDING); - let window_size = Point2DI::new(PADDING * 2 + message_size, TOOLTIP_HEIGHT); + let window_origin = Vector2I::new(PADDING, PADDING); + let window_size = Vector2I::new(PADDING * 2 + message_size, TOOLTIP_HEIGHT); debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( device, RectI::new(window_origin, window_size), @@ -316,7 +316,7 @@ where debug_ui_presenter.ui_presenter.draw_text( device, &model.message, - window_origin + Point2DI::new(PADDING, PADDING + FONT_ASCENT), + window_origin + Vector2I::new(PADDING, PADDING + FONT_ASCENT), false, ); } @@ -334,8 +334,8 @@ where debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( device, RectI::new( - Point2DI::new(PADDING, effects_panel_y), - Point2DI::new(EFFECTS_PANEL_WIDTH, EFFECTS_PANEL_HEIGHT), + Vector2I::new(PADDING, effects_panel_y), + Vector2I::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 = Point2DI::new(panel_x, panel_y); + let panel_position = Vector2I::new(panel_x, panel_y); debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( device, RectI::new( panel_position, - Point2DI::new(SCREENSHOT_PANEL_WIDTH, SCREENSHOT_PANEL_HEIGHT), + Vector2I::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 = Point2DI::new(panel_x, panel_y); + let panel_position = Vector2I::new(panel_x, panel_y); debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( device, RectI::new( panel_position, - Point2DI::new(BACKGROUND_PANEL_WIDTH, BACKGROUND_PANEL_HEIGHT), + Vector2I::new(BACKGROUND_PANEL_WIDTH, BACKGROUND_PANEL_HEIGHT), ), WINDOW_COLOR, ); @@ -472,8 +472,8 @@ 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 = Point2DI::new(rotate_panel_x, rotate_panel_y); - let rotate_panel_size = Point2DI::new(ROTATE_PANEL_WIDTH, ROTATE_PANEL_HEIGHT); + let rotate_panel_origin = Vector2I::new(rotate_panel_x, rotate_panel_y); + let rotate_panel_size = Vector2I::new(ROTATE_PANEL_WIDTH, ROTATE_PANEL_HEIGHT); debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( device, RectI::new(rotate_panel_origin, rotate_panel_size), @@ -482,8 +482,8 @@ where let (widget_x, widget_y) = (rotate_panel_x + PADDING, rotate_panel_y + PADDING); let widget_rect = RectI::new( - Point2DI::new(widget_x, widget_y), - Point2DI::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT), + Vector2I::new(widget_x, widget_y), + Vector2I::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT), ); if let Some(position) = debug_ui_presenter .ui_presenter @@ -497,8 +497,8 @@ where let slider_track_y = rotate_panel_y + PADDING + SLIDER_KNOB_HEIGHT / 2 - SLIDER_TRACK_HEIGHT / 2; let slider_track_rect = RectI::new( - Point2DI::new(widget_x, slider_track_y), - Point2DI::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT), + Vector2I::new(widget_x, slider_track_y), + Vector2I::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT), ); debug_ui_presenter .ui_presenter @@ -506,8 +506,8 @@ where let slider_knob_x = widget_x + model.rotation - SLIDER_KNOB_WIDTH / 2; let slider_knob_rect = RectI::new( - Point2DI::new(slider_knob_x, widget_y), - Point2DI::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT), + Vector2I::new(slider_knob_x, widget_y), + Vector2I::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT), ); debug_ui_presenter.ui_presenter.draw_solid_rect(device, slider_knob_rect, TEXT_COLOR); } @@ -518,14 +518,14 @@ where window: &mut W, debug_ui_presenter: &mut DebugUIPresenter, screenshot_type: ScreenshotType, - panel_position: Point2DI, + panel_position: Vector2I, action: &mut UIAction, ) where W: Window { let index = screenshot_type as i32; let text = format!("Save as {}...", screenshot_type.as_str()); - let widget_size = Point2DI::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); - let widget_origin = panel_position + Point2DI::new(0, widget_size.y() * index); + let widget_size = Vector2I::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); + let widget_origin = panel_position + Vector2I::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) { @@ -543,14 +543,14 @@ where device: &D, debug_ui_presenter: &mut DebugUIPresenter, color: BackgroundColor, - panel_position: Point2DI, + panel_position: Vector2I, action: &mut UIAction, model: &mut DemoUIModel, ) { let (text, index) = (color.as_str(), color as i32); - let widget_size = Point2DI::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); - let widget_origin = panel_position + Point2DI::new(0, widget_size.y() * index); + let widget_size = Vector2I::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); + let widget_origin = panel_position + Vector2I::new(0, widget_size.y() * index); let widget_rect = RectI::new(widget_origin, widget_size); let selected = color == model.background_color; @@ -574,7 +574,7 @@ where } let (text_x, text_y) = (PADDING * 2, BUTTON_TEXT_OFFSET); - let text_position = widget_rect.origin() + Point2DI::new(text_x, text_y); + let text_position = widget_rect.origin() + Vector2I::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, Point2DI::new(text_x, text_y), false); + .draw_text(device, text, Vector2I::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 = Point2DI::new(switch_x, switch_y); + let switch_position = Vector2I::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 b38f4fcf..5d2fe0ec 100644 --- a/demo/common/src/window.rs +++ b/demo/common/src/window.rs @@ -11,7 +11,7 @@ //! A minimal cross-platform windowing layer. use gl::types::GLuint; -use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; use pathfinder_geometry::basic::rect::RectI; use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF}; use pathfinder_gl::GLVersion; @@ -42,10 +42,10 @@ pub enum Event { WindowResized(WindowSize), KeyDown(Keycode), KeyUp(Keycode), - MouseDown(Point2DI), - MouseMoved(Point2DI), - MouseDragged(Point2DI), - Zoom(f32, Point2DI), + MouseDown(Vector2I), + MouseMoved(Vector2I), + MouseDragged(Vector2I), + Zoom(f32, Vector2I), Look { pitch: f32, yaw: f32, @@ -67,13 +67,13 @@ pub enum Keycode { #[derive(Clone, Copy, Debug)] pub struct WindowSize { - pub logical_size: Point2DI, + pub logical_size: Vector2I, pub backing_scale_factor: f32, } impl WindowSize { #[inline] - pub fn device_size(&self) -> Point2DI { + pub fn device_size(&self) -> Vector2I { self.logical_size .to_f32() .scale(self.backing_scale_factor) diff --git a/demo/native/src/main.rs b/demo/native/src/main.rs index d8981cc3..ad166dae 100644 --- a/demo/native/src/main.rs +++ b/demo/native/src/main.rs @@ -13,7 +13,7 @@ use nfd::Response; use pathfinder_demo::window::{Event, Keycode, SVGPath, View, Window, WindowSize}; use pathfinder_demo::{DemoApp, Options}; -use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; use pathfinder_geometry::basic::rect::RectI; use pathfinder_gl::GLVersion; use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader}; @@ -92,7 +92,7 @@ impl Window for WindowImpl { width = width / 2; x_offset = width * (index as i32); } - RectI::new(Point2DI::new(x_offset, 0), Point2DI::new(width, height)) + RectI::new(Vector2I::new(x_offset, 0), Vector2I::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: Point2DI::new(logical_width as i32, logical_height as i32), + logical_size: Vector2I::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(Point2DI::new(x, y))), + SDLEvent::MouseButtonDown { x, y, .. } => Some(Event::MouseDown(Vector2I::new(x, y))), SDLEvent::MouseMotion { x, y, mousestate, .. } => { - let position = Point2DI::new(x, y); + let position = Vector2I::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 = Point2DI::new(mouse_state.x(), mouse_state.y()); + let center = Vector2I::new(mouse_state.x(), mouse_state.y()); Some(Event::Zoom(d_dist, center)) } _ => None, diff --git a/examples/c_canvas_minimal/c_canvas_minimal.c b/examples/c_canvas_minimal/c_canvas_minimal.c index 9cdbe0a4..9e773b02 100644 --- a/examples/c_canvas_minimal/c_canvas_minimal.c +++ b/examples/c_canvas_minimal/c_canvas_minimal.c @@ -55,7 +55,7 @@ int main(int argc, const char **argv) { // Create a Pathfinder renderer. PFGLLoadWith(LoadGLFunction, NULL); PFGLDestFramebufferRef dest_framebuffer = - PFGLDestFramebufferCreateFullWindow(&(PFPoint2DI){640, 480}); + PFGLDestFramebufferCreateFullWindow(&(PFVector2I){640, 480}); PFGLRendererRef renderer = PFGLRendererCreate(PFGLDeviceCreate(PF_GL_VERSION_GL3, 0), PFFilesystemResourceLoaderLocate(), dest_framebuffer); @@ -67,7 +67,7 @@ int main(int argc, const char **argv) { // Make a canvas. We're going to draw a house. PFCanvasRef canvas = PFCanvasCreate(PFCanvasFontContextCreate(), - &(PFPoint2DF){640.0f, 480.0f}); + &(PFVector2F){640.0f, 480.0f}); // Set line width. PFCanvasSetLineWidth(canvas, 10.0f); @@ -80,9 +80,9 @@ int main(int argc, const char **argv) { // Draw roof. PFPathRef path = PFPathCreate(); - PFPathMoveTo(path, &(PFPoint2DF){50.0, 140.0}); - PFPathLineTo(path, &(PFPoint2DF){150.0, 60.0}); - PFPathLineTo(path, &(PFPoint2DF){250.0, 140.0}); + PFPathMoveTo(path, &(PFVector2F){50.0, 140.0}); + PFPathLineTo(path, &(PFVector2F){150.0, 60.0}); + PFPathLineTo(path, &(PFVector2F){250.0, 140.0}); PFPathClosePath(path); PFCanvasStrokePath(canvas, path); diff --git a/examples/canvas_minimal/src/main.rs b/examples/canvas_minimal/src/main.rs index bf340d46..07588dcc 100644 --- a/examples/canvas_minimal/src/main.rs +++ b/examples/canvas_minimal/src/main.rs @@ -9,7 +9,7 @@ // except according to those terms. use pathfinder_canvas::{CanvasFontContext, CanvasRenderingContext2D, Path2D}; -use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::color::ColorF; use pathfinder_gl::{GLDevice, GLVersion}; @@ -34,7 +34,7 @@ fn main() { gl_attributes.set_context_version(3, 3); // Open a window. - let window_size = Point2DI::new(640, 480); + let window_size = Vector2I::new(640, 480); let window = video.window("Minimal example", window_size.x() as u32, window_size.y() as u32) .opengl() .build() @@ -60,16 +60,16 @@ fn main() { canvas.set_line_width(10.0); // Draw walls. - canvas.stroke_rect(RectF::new(Point2DF::new(75.0, 140.0), Point2DF::new(150.0, 110.0))); + canvas.stroke_rect(RectF::new(Vector2F::new(75.0, 140.0), Vector2F::new(150.0, 110.0))); // Draw door. - canvas.fill_rect(RectF::new(Point2DF::new(130.0, 190.0), Point2DF::new(40.0, 60.0))); + canvas.fill_rect(RectF::new(Vector2F::new(130.0, 190.0), Vector2F::new(40.0, 60.0))); // Draw roof. let mut path = Path2D::new(); - 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.move_to(Vector2F::new(50.0, 140.0)); + path.line_to(Vector2F::new(150.0, 60.0)); + path.line_to(Vector2F::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 a8618098..7a55404e 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::{CanvasFontContext, CanvasRenderingContext2D, FillStyle, Path2D}; -use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; 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 = Point2DI::new(1067, 800); + let window_size = Vector2I::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 = Point2DI::new(drawable_width as i32, drawable_height as i32); + let drawable_size = Vector2I::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(); @@ -88,14 +88,14 @@ struct MoireRenderer { font_context: CanvasFontContext, scene: SceneProxy, frame: i32, - window_size: Point2DI, - drawable_size: Point2DI, + window_size: Vector2I, + drawable_size: Vector2I, device_pixel_ratio: f32, colors: ColorGradient, } impl MoireRenderer { - fn new(renderer: Renderer, window_size: Point2DI, drawable_size: Point2DI) + fn new(renderer: Renderer, window_size: Vector2I, drawable_size: Vector2I) -> MoireRenderer { MoireRenderer { renderer, @@ -119,9 +119,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 + Point2DF::new(sin_time, cos_time).scale(OUTER_RADIUS); + let outer_center = window_center + Vector2F::new(sin_time, cos_time).scale(OUTER_RADIUS); let inner_center = window_center + - Point2DF::new(1.0, sin_time).scale(cos_time * INNER_RADIUS); + Vector2F::new(1.0, sin_time).scale(cos_time * INNER_RADIUS); // Clear to background color. self.renderer.device.clear(&ClearParams { @@ -147,12 +147,12 @@ impl MoireRenderer { self.frame += 1; } - fn draw_circles(&self, canvas: &mut CanvasRenderingContext2D, center: Point2DF) { + fn draw_circles(&self, canvas: &mut CanvasRenderingContext2D, center: Vector2F) { 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; let mut path = Path2D::new(); - path.ellipse(center, Point2DF::splat(radius), 0.0, 0.0, PI * 2.0); + path.ellipse(center, Vector2F::splat(radius), 0.0, 0.0, PI * 2.0); canvas.stroke_path(path); } } diff --git a/examples/canvas_text/src/main.rs b/examples/canvas_text/src/main.rs index 986a3456..0829723e 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::{CanvasFontContext, CanvasRenderingContext2D, TextAlign}; -use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; 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 = Point2DI::new(640, 480); + let window_size = Vector2I::new(640, 480); let window = video.window("Text example", window_size.x() as u32, window_size.y() as u32) .opengl() .build() @@ -57,9 +57,9 @@ fn main() { // Draw the text. canvas.set_font_size(32.0); - canvas.fill_text("Hello Pathfinder!", Point2DF::new(32.0, 48.0)); + canvas.fill_text("Hello Pathfinder!", Vector2F::new(32.0, 48.0)); canvas.set_text_align(TextAlign::Right); - canvas.stroke_text("Goodbye Pathfinder!", Point2DF::new(608.0, 464.0)); + canvas.stroke_text("Goodbye Pathfinder!", Vector2F::new(608.0, 464.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 f22928aa..33ba7f04 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::Point2DF; +use crate::basic::vector::Vector2F; 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 LineSegmentF(pub F32x4); +pub struct LineSegment2F(pub F32x4); -impl LineSegmentF { +impl LineSegment2F { #[inline] - pub fn new(from: Point2DF, to: Point2DF) -> LineSegmentF { - LineSegmentF(from.0.concat_xy_xy(to.0)) + pub fn new(from: Vector2F, to: Vector2F) -> LineSegment2F { + LineSegment2F(from.0.concat_xy_xy(to.0)) } #[inline] - pub fn from(&self) -> Point2DF { - Point2DF(self.0) + pub fn from(&self) -> Vector2F { + Vector2F(self.0) } #[inline] - pub fn to(&self) -> Point2DF { - Point2DF(self.0.zwxy()) + pub fn to(&self) -> Vector2F { + Vector2F(self.0.zwxy()) } #[inline] - pub fn set_from(&mut self, point: &Point2DF) { + pub fn set_from(&mut self, point: &Vector2F) { self.0 = point.0.concat_xy_zw(self.0) } #[inline] - pub fn set_to(&mut self, point: &Point2DF) { + pub fn set_to(&mut self, point: &Vector2F) { self.0 = self.0.concat_xy_xy(point.0) } @@ -88,35 +88,35 @@ impl LineSegmentF { } #[inline] - pub fn translate(&self, offset: Point2DF) -> LineSegmentF { - LineSegmentF(self.0 + offset.0.xyxy()) + pub fn translate(&self, offset: Vector2F) -> LineSegment2F { + LineSegment2F(self.0 + offset.0.xyxy()) } #[inline] - pub fn scale(&self, factor: f32) -> LineSegmentF { - LineSegmentF(self.0 * F32x4::splat(factor)) + pub fn scale(&self, factor: f32) -> LineSegment2F { + LineSegment2F(self.0 * F32x4::splat(factor)) } #[inline] - pub fn scale_xy(&self, factors: Point2DF) -> LineSegmentF { - LineSegmentF(self.0 * factors.0.xyxy()) + pub fn scale_xy(&self, factors: Vector2F) -> LineSegment2F { + LineSegment2F(self.0 * factors.0.xyxy()) } #[inline] - pub fn split(&self, t: f32) -> (LineSegmentF, LineSegmentF) { + pub fn split(&self, t: f32) -> (LineSegment2F, LineSegment2F) { 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); ( - LineSegmentF(from_from.concat_xy_xy(mid_mid)), - LineSegmentF(mid_mid.concat_xy_xy(to_to)), + LineSegment2F(from_from.concat_xy_xy(mid_mid)), + LineSegment2F(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) -> (LineSegmentF, LineSegmentF) { + pub fn split_at_x(&self, x: f32) -> (LineSegment2F, LineSegment2F) { 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) @@ -127,7 +127,7 @@ impl LineSegmentF { // Returns the upper segment first, followed by the lower segment. #[inline] - pub fn split_at_y(&self, y: f32) -> (LineSegmentF, LineSegmentF) { + pub fn split_at_y(&self, y: f32) -> (LineSegment2F, LineSegment2F) { 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 @@ -160,12 +160,12 @@ impl LineSegmentF { } #[inline] - pub fn reversed(&self) -> LineSegmentF { - LineSegmentF(self.0.zwxy()) + pub fn reversed(&self) -> LineSegment2F { + LineSegment2F(self.0.zwxy()) } #[inline] - pub fn upper_point(&self) -> Point2DF { + pub fn upper_point(&self) -> Vector2F { if self.from_y() < self.to_y() { self.from() } else { @@ -205,7 +205,7 @@ impl LineSegmentF { // 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) -> LineSegmentF { + pub fn orient(&self, y_winding: i32) -> LineSegment2F { if y_winding >= 0 { *self } else { @@ -232,12 +232,12 @@ impl LineSegmentF { } #[inline] - pub fn vector(&self) -> Point2DF { + pub fn vector(&self) -> Vector2F { self.to() - self.from() } // http://www.cs.swan.ac.uk/~cssimon/line_intersection.html - pub fn intersection_t(&self, other: &LineSegmentF) -> Option { + pub fn intersection_t(&self, other: &LineSegment2F) -> Option { let p0p1 = self.vector(); let matrix = Matrix2x2F(other.vector().0.concat_xy_xy((-p0p1).0)); if f32::abs(matrix.det()) < EPSILON { @@ -249,18 +249,18 @@ impl LineSegmentF { } #[inline] - pub fn sample(&self, t: f32) -> Point2DF { + pub fn sample(&self, t: f32) -> Vector2F { self.from() + self.vector().scale(t) } #[inline] - pub fn midpoint(&self) -> Point2DF { + pub fn midpoint(&self) -> Vector2F { self.sample(0.5) } #[inline] - pub fn offset(&self, distance: f32) -> LineSegmentF { + pub fn offset(&self, distance: f32) -> LineSegment2F { if self.is_zero_length() { *self } else { @@ -269,7 +269,7 @@ impl LineSegmentF { .vector() .yx() .normalize() - .scale_xy(Point2DF::new(-distance, distance)) + .scale_xy(Vector2F::new(-distance, distance)) } } @@ -279,19 +279,19 @@ impl LineSegmentF { } } -impl Add for LineSegmentF { - type Output = LineSegmentF; +impl Add for LineSegment2F { + type Output = LineSegment2F; #[inline] - fn add(self, point: Point2DF) -> LineSegmentF { - LineSegmentF(self.0 + point.0.xyxy()) + fn add(self, point: Vector2F) -> LineSegment2F { + LineSegment2F(self.0 + point.0.xyxy()) } } -impl Sub for LineSegmentF { - type Output = LineSegmentF; +impl Sub for LineSegment2F { + type Output = LineSegment2F; #[inline] - fn sub(self, point: Point2DF) -> LineSegmentF { - LineSegmentF(self.0 - point.0.xyxy()) + fn sub(self, point: Vector2F) -> LineSegment2F { + LineSegment2F(self.0 - point.0.xyxy()) } } diff --git a/geometry/src/basic/mod.rs b/geometry/src/basic/mod.rs index 7dc82675..d77c1fc0 100644 --- a/geometry/src/basic/mod.rs +++ b/geometry/src/basic/mod.rs @@ -11,7 +11,7 @@ //! Basic geometry and linear algebra primitives, optimized with SIMD. pub mod line_segment; -pub mod point; pub mod rect; pub mod transform2d; pub mod transform3d; +pub mod vector; diff --git a/geometry/src/basic/rect.rs b/geometry/src/basic/rect.rs index 95b9f752..95e60ee3 100644 --- a/geometry/src/basic/rect.rs +++ b/geometry/src/basic/rect.rs @@ -10,7 +10,7 @@ //! 2D axis-aligned rectangles, optimized with SIMD. -use crate::basic::point::{Point2DF, Point2DI}; +use crate::basic::vector::{Vector2F, Vector2I}; use pathfinder_simd::default::{F32x4, I32x4}; #[derive(Clone, Copy, Debug, PartialEq, Default)] @@ -18,42 +18,42 @@ pub struct RectF(pub F32x4); impl RectF { #[inline] - pub fn new(origin: Point2DF, size: Point2DF) -> RectF { + pub fn new(origin: Vector2F, size: Vector2F) -> RectF { RectF(origin.0.concat_xy_xy(origin.0 + size.0)) } #[inline] - pub fn from_points(origin: Point2DF, lower_right: Point2DF) -> RectF { + pub fn from_points(origin: Vector2F, lower_right: Vector2F) -> RectF { RectF(origin.0.concat_xy_xy(lower_right.0)) } #[inline] - pub fn origin(&self) -> Point2DF { - Point2DF(self.0) + pub fn origin(&self) -> Vector2F { + Vector2F(self.0) } #[inline] - pub fn size(&self) -> Point2DF { - Point2DF(self.0.zwxy() - self.0.xyxy()) + pub fn size(&self) -> Vector2F { + Vector2F(self.0.zwxy() - self.0.xyxy()) } #[inline] - pub fn upper_right(&self) -> Point2DF { - Point2DF(self.0.zyxw()) + pub fn upper_right(&self) -> Vector2F { + Vector2F(self.0.zyxw()) } #[inline] - pub fn lower_left(&self) -> Point2DF { - Point2DF(self.0.xwzy()) + pub fn lower_left(&self) -> Vector2F { + Vector2F(self.0.xwzy()) } #[inline] - pub fn lower_right(&self) -> Point2DF { - Point2DF(self.0.zwxy()) + pub fn lower_right(&self) -> Vector2F { + Vector2F(self.0.zwxy()) } #[inline] - pub fn contains_point(&self, point: Point2DF) -> bool { + pub fn contains_point(&self, point: Vector2F) -> bool { // self.origin <= point && point <= self.lower_right self.0 .concat_xy_xy(point.0) @@ -76,7 +76,7 @@ impl RectF { } #[inline] - pub fn union_point(&self, point: Point2DF) -> RectF { + pub fn union_point(&self, point: Vector2F) -> RectF { RectF::from_points(self.origin().min(point), self.lower_right().max(point)) } @@ -130,7 +130,7 @@ impl RectF { } #[inline] - pub fn scale_xy(self, factors: Point2DF) -> RectF { + pub fn scale_xy(self, factors: Vector2F) -> RectF { RectF(self.0 * factors.0.concat_xy_xy(factors.0)) } @@ -140,7 +140,7 @@ impl RectF { } #[inline] - pub fn dilate(self, amount: Point2DF) -> RectF { + pub fn dilate(self, amount: Vector2F) -> RectF { RectF::from_points(self.origin() - amount, self.lower_right() + amount) } @@ -155,38 +155,38 @@ pub struct RectI(pub I32x4); impl RectI { #[inline] - pub fn new(origin: Point2DI, size: Point2DI) -> RectI { + pub fn new(origin: Vector2I, size: Vector2I) -> RectI { RectI(origin.0.concat_xy_xy(origin.0 + size.0)) } #[inline] - pub fn from_points(origin: Point2DI, lower_right: Point2DI) -> RectI { + pub fn from_points(origin: Vector2I, lower_right: Vector2I) -> RectI { RectI(origin.0.concat_xy_xy(lower_right.0)) } #[inline] - pub fn origin(&self) -> Point2DI { - Point2DI(self.0) + pub fn origin(&self) -> Vector2I { + Vector2I(self.0) } #[inline] - pub fn size(&self) -> Point2DI { - Point2DI(self.0.zwxy() - self.0.xyxy()) + pub fn size(&self) -> Vector2I { + Vector2I(self.0.zwxy() - self.0.xyxy()) } #[inline] - pub fn upper_right(&self) -> Point2DI { - Point2DI(self.0.zyxw()) + pub fn upper_right(&self) -> Vector2I { + Vector2I(self.0.zyxw()) } #[inline] - pub fn lower_left(&self) -> Point2DI { - Point2DI(self.0.xwzy()) + pub fn lower_left(&self) -> Vector2I { + Vector2I(self.0.xwzy()) } #[inline] - pub fn lower_right(&self) -> Point2DI { - Point2DI(self.0.zwxy()) + pub fn lower_right(&self) -> Vector2I { + Vector2I(self.0.zwxy()) } #[inline] @@ -210,9 +210,9 @@ impl RectI { } #[inline] - pub fn contains_point(&self, point: Point2DI) -> bool { + pub fn contains_point(&self, point: Vector2I) -> bool { // self.origin <= point && point <= self.lower_right - 1 - let lower_right = self.lower_right() - Point2DI::splat(1); + let lower_right = self.lower_right() - Vector2I::splat(1); self.0 .concat_xy_xy(point.0) .packed_le(point.0.concat_xy_xy(lower_right.0)) diff --git a/geometry/src/basic/transform2d.rs b/geometry/src/basic/transform2d.rs index ab428e07..db0df148 100644 --- a/geometry/src/basic/transform2d.rs +++ b/geometry/src/basic/transform2d.rs @@ -10,8 +10,8 @@ //! 2D affine transforms. -use crate::basic::line_segment::LineSegmentF; -use crate::basic::point::Point2DF; +use crate::basic::line_segment::LineSegment2F; +use crate::basic::vector::Vector2F; use crate::basic::rect::RectF; use crate::basic::transform3d::Transform3DF; use crate::segment::Segment; @@ -26,13 +26,13 @@ pub struct Matrix2x2F(pub F32x4); impl Default for Matrix2x2F { #[inline] fn default() -> Matrix2x2F { - Self::from_scale(Point2DF::splat(1.0)) + Self::from_scale(Vector2F::splat(1.0)) } } impl Matrix2x2F { #[inline] - pub fn from_scale(scale: Point2DF) -> Matrix2x2F { + pub fn from_scale(scale: Vector2F) -> Matrix2x2F { Matrix2x2F(F32x4::new(scale.x(), 0.0, 0.0, scale.y())) } @@ -72,9 +72,9 @@ impl Matrix2x2F { } #[inline] - pub fn transform_point(&self, point: Point2DF) -> Point2DF { + pub fn transform_point(&self, point: Vector2F) -> Vector2F { let halves = self.0 * point.0.xxyy(); - Point2DF(halves + halves.zwzw()) + Vector2F(halves + halves.zwzw()) } #[inline] @@ -118,22 +118,22 @@ impl Sub for Matrix2x2F { pub struct Transform2DF { // Row-major order. matrix: Matrix2x2F, - vector: Point2DF, + vector: Vector2F, } impl Default for Transform2DF { #[inline] fn default() -> Transform2DF { - Self::from_scale(Point2DF::splat(1.0)) + Self::from_scale(Vector2F::splat(1.0)) } } impl Transform2DF { #[inline] - pub fn from_scale(scale: Point2DF) -> Transform2DF { + pub fn from_scale(scale: Vector2F) -> Transform2DF { Transform2DF { matrix: Matrix2x2F::from_scale(scale), - vector: Point2DF::default(), + vector: Vector2F::default(), } } @@ -141,7 +141,7 @@ impl Transform2DF { pub fn from_rotation(theta: f32) -> Transform2DF { Transform2DF { matrix: Matrix2x2F::from_rotation(theta), - vector: Point2DF::default(), + vector: Vector2F::default(), } } @@ -149,20 +149,20 @@ impl Transform2DF { pub fn from_rotation_vector(vector: UnitVector) -> Transform2DF { Transform2DF { matrix: Matrix2x2F::from_rotation_vector(vector), - vector: Point2DF::default(), + vector: Vector2F::default(), } } #[inline] - pub fn from_translation(vector: Point2DF) -> Transform2DF { + pub fn from_translation(vector: Vector2F) -> Transform2DF { Transform2DF { matrix: Matrix2x2F::default(), vector } } #[inline] pub fn from_scale_rotation_translation( - scale: Point2DF, + scale: Vector2F, theta: f32, - translation: Point2DF, + translation: Vector2F, ) -> Transform2DF { let rotation = Transform2DF::from_rotation(theta); let translation = Transform2DF::from_translation(translation); @@ -173,18 +173,18 @@ impl Transform2DF { 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), + vector: Vector2F::new(m31, m32), } } #[inline] - pub fn transform_point(&self, point: Point2DF) -> Point2DF { + pub fn transform_point(&self, point: Vector2F) -> Vector2F { self.matrix.transform_point(point) + self.vector } #[inline] - pub fn transform_line_segment(&self, line_segment: &LineSegmentF) -> LineSegmentF { - LineSegmentF::new(self.transform_point(line_segment.from()), + pub fn transform_line_segment(&self, line_segment: &LineSegment2F) -> LineSegment2F { + LineSegment2F::new(self.transform_point(line_segment.from()), self.transform_point(line_segment.to())) } @@ -257,7 +257,7 @@ impl Transform2DF { } #[inline] - pub fn post_translate(&self, vector: Point2DF) -> Transform2DF { + pub fn post_translate(&self, vector: Vector2F) -> Transform2DF { self.post_mul(&Transform2DF::from_translation(vector)) } @@ -267,7 +267,7 @@ impl Transform2DF { } #[inline] - pub fn post_scale(&self, scale: Point2DF) -> Transform2DF { + pub fn post_scale(&self, scale: Vector2F) -> Transform2DF { self.post_mul(&Transform2DF::from_scale(scale)) } @@ -275,7 +275,7 @@ impl Transform2DF { /// /// This decomposition assumes that scale, rotation, and translation are applied in that order. #[inline] - pub fn translation(&self) -> Point2DF { + pub fn translation(&self) -> Vector2F { self.vector } @@ -292,7 +292,7 @@ impl Transform2DF { /// This decomposition assumes that scale, rotation, and translation are applied in that order. #[inline] pub fn scale_factor(&self) -> f32 { - Point2DF(self.matrix.0.zwxy()).length() + Vector2F(self.matrix.0.zwxy()).length() } } diff --git a/geometry/src/basic/transform3d.rs b/geometry/src/basic/transform3d.rs index 191e159c..9b7aa4bd 100644 --- a/geometry/src/basic/transform3d.rs +++ b/geometry/src/basic/transform3d.rs @@ -10,7 +10,7 @@ //! 3D transforms that can be applied to paths. -use crate::basic::point::{Point2DF, Point2DI, Point3DF}; +use crate::basic::vector::{Vector2F, Vector2I, Vector4F}; use crate::basic::rect::RectF; use crate::basic::transform2d::Matrix2x2F; use crate::segment::Segment; @@ -236,12 +236,12 @@ impl Transform3DF { } #[inline] - pub fn transform_point(&self, point: Point3DF) -> Point3DF { + pub fn transform_point(&self, point: Vector4F) -> Vector4F { 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()); - Point3DF(term0 + term1 + term2 + term3) + Vector4F(term0 + term1 + term2 + term3) } #[inline] @@ -319,12 +319,12 @@ impl Neg for Matrix2x2F { #[derive(Clone, Copy, Debug)] pub struct Perspective { pub transform: Transform3DF, - pub window_size: Point2DI, + pub window_size: Vector2I, } impl Perspective { #[inline] - pub fn new(transform: &Transform3DF, window_size: Point2DI) -> Perspective { + pub fn new(transform: &Transform3DF, window_size: Vector2I) -> Perspective { Perspective { transform: *transform, window_size, @@ -332,14 +332,14 @@ impl Perspective { } #[inline] - pub fn transform_point_2d(&self, point: &Point2DF) -> Point2DF { + pub fn transform_point_2d(&self, point: &Vector2F) -> Vector2F { let point = self .transform .transform_point(point.to_3d()) .perspective_divide() .to_2d() - * Point2DF::new(1.0, -1.0); - (point + Point2DF::splat(1.0)) * self.window_size.to_f32().scale(0.5) + * Vector2F::new(1.0, -1.0); + (point + Vector2F::splat(1.0)) * self.window_size.to_f32().scale(0.5) } // TODO(pcwalton): SIMD? @@ -420,7 +420,7 @@ where #[cfg(test)] mod test { - use crate::basic::point::Point3DF; + use crate::basic::vector::Vector4F; use crate::basic::transform3d::Transform3DF; #[test] @@ -458,8 +458,8 @@ mod test { 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 = Point3DF::new(3.0, 8.0, 4.0, 6.0); - let q = Point3DF::new(63.0, 97.0, 135.0, 117.0); + let p = Vector4F::new(3.0, 8.0, 4.0, 6.0); + let q = Vector4F::new(63.0, 97.0, 135.0, 117.0); assert_eq!(a.transform_point(p), q); } @@ -471,7 +471,7 @@ mod test { 0.12969608, 0.0946466, 0.43248631, 0.63480505, 0.08154603, 0.50305436, 0.48359687, 0.51057162, 0.24812012, ); - let p0 = Point3DF::new(0.95536648, 0.80633691, 0.16357357, 0.5477598); + let p0 = Vector4F::new(0.95536648, 0.80633691, 0.16357357, 0.5477598); let p1 = m.transform_point(p0); let m_inv = m.inverse(); let m_inv_exp = Transform3DF::row_major( diff --git a/geometry/src/basic/point.rs b/geometry/src/basic/vector.rs similarity index 52% rename from geometry/src/basic/point.rs rename to geometry/src/basic/vector.rs index e098e44e..0d6e4941 100644 --- a/geometry/src/basic/point.rs +++ b/geometry/src/basic/vector.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 Point2DF(pub F32x4); +pub struct Vector2F(pub F32x4); -impl Point2DF { +impl Vector2F { #[inline] - pub fn new(x: f32, y: f32) -> Point2DF { - Point2DF(F32x4::new(x, y, 0.0, 0.0)) + pub fn new(x: f32, y: f32) -> Vector2F { + Vector2F(F32x4::new(x, y, 0.0, 0.0)) } #[inline] - pub fn splat(value: f32) -> Point2DF { - Point2DF(F32x4::splat(value)) + pub fn splat(value: f32) -> Vector2F { + Vector2F(F32x4::splat(value)) } #[inline] - pub fn to_3d(self) -> Point3DF { - Point3DF(self.0.concat_xy_xy(F32x4::new(0.0, 1.0, 0.0, 0.0))) + pub fn to_3d(self) -> Vector4F { + Vector4F(self.0.concat_xy_xy(F32x4::new(0.0, 1.0, 0.0, 0.0))) } #[inline] @@ -54,49 +54,49 @@ impl Point2DF { } #[inline] - pub fn min(&self, other: Point2DF) -> Point2DF { - Point2DF(self.0.min(other.0)) + pub fn min(&self, other: Vector2F) -> Vector2F { + Vector2F(self.0.min(other.0)) } #[inline] - pub fn max(&self, other: Point2DF) -> Point2DF { - Point2DF(self.0.max(other.0)) + pub fn max(&self, other: Vector2F) -> Vector2F { + Vector2F(self.0.max(other.0)) } #[inline] - pub fn clamp(&self, min_val: Point2DF, max_val: Point2DF) -> Point2DF { + pub fn clamp(&self, min_val: Vector2F, max_val: Vector2F) -> Vector2F { self.max(min_val).min(max_val) } #[inline] - pub fn det(&self, other: Point2DF) -> f32 { + pub fn det(&self, other: Vector2F) -> f32 { self.x() * other.y() - self.y() * other.x() } #[inline] - pub fn dot(&self, other: Point2DF) -> f32 { + pub fn dot(&self, other: Vector2F) -> f32 { let xy = self.0 * other.0; xy.x() + xy.y() } #[inline] - pub fn scale(&self, x: f32) -> Point2DF { - Point2DF(self.0 * F32x4::splat(x)) + pub fn scale(&self, x: f32) -> Vector2F { + Vector2F(self.0 * F32x4::splat(x)) } #[inline] - pub fn scale_xy(&self, factors: Point2DF) -> Point2DF { - Point2DF(self.0 * factors.0) + pub fn scale_xy(&self, factors: Vector2F) -> Vector2F { + Vector2F(self.0 * factors.0) } #[inline] - pub fn floor(&self) -> Point2DF { - Point2DF(self.0.floor()) + pub fn floor(&self) -> Vector2F { + Vector2F(self.0.floor()) } #[inline] - pub fn ceil(&self) -> Point2DF { - Point2DF(self.0.ceil()) + pub fn ceil(&self) -> Vector2F { + Vector2F(self.0.ceil()) } /// Treats this point as a vector and calculates its squared length. @@ -114,85 +114,85 @@ impl Point2DF { /// Treats this point as a vector and normalizes it. #[inline] - pub fn normalize(&self) -> Point2DF { + pub fn normalize(&self) -> Vector2F { self.scale(1.0 / self.length()) } /// Swaps y and x. #[inline] - pub fn yx(&self) -> Point2DF { - Point2DF(self.0.yxwz()) + pub fn yx(&self) -> Vector2F { + Vector2F(self.0.yxwz()) } #[inline] pub fn is_zero(&self) -> bool { - *self == Point2DF::default() + *self == Vector2F::default() } #[inline] - pub fn lerp(&self, other: Point2DF, t: f32) -> Point2DF { + pub fn lerp(&self, other: Vector2F, t: f32) -> Vector2F { *self + (other - *self).scale(t) } #[inline] - pub fn to_i32(&self) -> Point2DI { - Point2DI(self.0.to_i32x4()) + pub fn to_i32(&self) -> Vector2I { + Vector2I(self.0.to_i32x4()) } } -impl PartialEq for Point2DF { +impl PartialEq for Vector2F { #[inline] - fn eq(&self, other: &Point2DF) -> bool { + fn eq(&self, other: &Vector2F) -> bool { let results = self.0.packed_eq(other.0); results[0] != 0 && results[1] != 0 } } -impl Add for Point2DF { - type Output = Point2DF; +impl Add for Vector2F { + type Output = Vector2F; #[inline] - fn add(self, other: Point2DF) -> Point2DF { - Point2DF(self.0 + other.0) + fn add(self, other: Vector2F) -> Vector2F { + Vector2F(self.0 + other.0) } } -impl Sub for Point2DF { - type Output = Point2DF; +impl Sub for Vector2F { + type Output = Vector2F; #[inline] - fn sub(self, other: Point2DF) -> Point2DF { - Point2DF(self.0 - other.0) + fn sub(self, other: Vector2F) -> Vector2F { + Vector2F(self.0 - other.0) } } -impl Mul for Point2DF { - type Output = Point2DF; +impl Mul for Vector2F { + type Output = Vector2F; #[inline] - fn mul(self, other: Point2DF) -> Point2DF { - Point2DF(self.0 * other.0) + fn mul(self, other: Vector2F) -> Vector2F { + Vector2F(self.0 * other.0) } } -impl Neg for Point2DF { - type Output = Point2DF; +impl Neg for Vector2F { + type Output = Vector2F; #[inline] - fn neg(self) -> Point2DF { - Point2DF(-self.0) + fn neg(self) -> Vector2F { + Vector2F(-self.0) } } /// 2D points with 32-bit signed integer coordinates. #[derive(Clone, Copy, Debug, Default)] -pub struct Point2DI(pub I32x4); +pub struct Vector2I(pub I32x4); -impl Point2DI { +impl Vector2I { #[inline] - pub fn new(x: i32, y: i32) -> Point2DI { - Point2DI(I32x4::new(x, y, 0, 0)) + pub fn new(x: i32, y: i32) -> Vector2I { + Vector2I(I32x4::new(x, y, 0, 0)) } #[inline] - pub fn splat(value: i32) -> Point2DI { - Point2DI(I32x4::splat(value)) + pub fn splat(value: i32) -> Vector2I { + Vector2I(I32x4::splat(value)) } #[inline] @@ -216,47 +216,47 @@ impl Point2DI { } #[inline] - pub fn scale(&self, factor: i32) -> Point2DI { - Point2DI(self.0 * I32x4::splat(factor)) + pub fn scale(&self, factor: i32) -> Vector2I { + Vector2I(self.0 * I32x4::splat(factor)) } #[inline] - pub fn scale_xy(&self, factors: Point2DI) -> Point2DI { - Point2DI(self.0 * factors.0) + pub fn scale_xy(&self, factors: Vector2I) -> Vector2I { + Vector2I(self.0 * factors.0) } #[inline] - pub fn to_f32(&self) -> Point2DF { - Point2DF(self.0.to_f32x4()) + pub fn to_f32(&self) -> Vector2F { + Vector2F(self.0.to_f32x4()) } } -impl Add for Point2DI { - type Output = Point2DI; +impl Add for Vector2I { + type Output = Vector2I; #[inline] - fn add(self, other: Point2DI) -> Point2DI { - Point2DI(self.0 + other.0) + fn add(self, other: Vector2I) -> Vector2I { + Vector2I(self.0 + other.0) } } -impl AddAssign for Point2DI { +impl AddAssign for Vector2I { #[inline] - fn add_assign(&mut self, other: Point2DI) { + fn add_assign(&mut self, other: Vector2I) { self.0 += other.0 } } -impl Sub for Point2DI { - type Output = Point2DI; +impl Sub for Vector2I { + type Output = Vector2I; #[inline] - fn sub(self, other: Point2DI) -> Point2DI { - Point2DI(self.0 - other.0) + fn sub(self, other: Vector2I) -> Vector2I { + Vector2I(self.0 - other.0) } } -impl PartialEq for Point2DI { +impl PartialEq for Vector2I { #[inline] - fn eq(&self, other: &Point2DI) -> bool { + fn eq(&self, other: &Vector2I) -> bool { let results = self.0.packed_eq(other.0); results[0] != 0 && results[1] != 0 } @@ -264,22 +264,22 @@ impl PartialEq for Point2DI { /// 3D homogeneous points. #[derive(Clone, Copy, Debug, PartialEq)] -pub struct Point3DF(pub F32x4); +pub struct Vector4F(pub F32x4); -impl Point3DF { +impl Vector4F { #[inline] - pub fn new(x: f32, y: f32, z: f32, w: f32) -> Point3DF { - Point3DF(F32x4::new(x, y, z, w)) + pub fn new(x: f32, y: f32, z: f32, w: f32) -> Vector4F { + Vector4F(F32x4::new(x, y, z, w)) } #[inline] - pub fn splat(value: f32) -> Point3DF { - Point3DF(F32x4::splat(value)) + pub fn splat(value: f32) -> Vector4F { + Vector4F(F32x4::splat(value)) } #[inline] - pub fn to_2d(self) -> Point2DF { - Point2DF(self.0) + pub fn to_2d(self) -> Vector2F { + Vector2F(self.0) } #[inline] @@ -303,10 +303,10 @@ impl Point3DF { } #[inline] - pub fn scale(&self, x: f32) -> Point3DF { + pub fn scale(&self, x: f32) -> Vector4F { let mut factors = F32x4::splat(x); factors[3] = 1.0; - Point3DF(self.0 * factors) + Vector4F(self.0 * factors) } #[inline] @@ -330,12 +330,12 @@ impl Point3DF { } #[inline] - pub fn perspective_divide(self) -> Point3DF { - Point3DF(self.0 * F32x4::splat(1.0 / self.w())) + pub fn perspective_divide(self) -> Vector4F { + Vector4F(self.0 * F32x4::splat(1.0 / self.w())) } #[inline] - pub fn approx_eq(&self, other: &Point3DF, epsilon: f32) -> bool { + pub fn approx_eq(&self, other: &Vector4F, epsilon: f32) -> bool { self.0.approx_eq(other.0, epsilon) } @@ -349,39 +349,39 @@ impl Point3DF { } #[inline] - pub fn lerp(self, other: Point3DF, t: f32) -> Point3DF { - Point3DF(self.0 + (other.0 - self.0) * F32x4::splat(t)) + pub fn lerp(self, other: Vector4F, t: f32) -> Vector4F { + Vector4F(self.0 + (other.0 - self.0) * F32x4::splat(t)) } } -impl Add for Point3DF { - type Output = Point3DF; +impl Add for Vector4F { + type Output = Vector4F; #[inline] - fn add(self, other: Point3DF) -> Point3DF { - Point3DF(self.0 + other.0) + fn add(self, other: Vector4F) -> Vector4F { + Vector4F(self.0 + other.0) } } -impl AddAssign for Point3DF { +impl AddAssign for Vector4F { #[inline] - fn add_assign(&mut self, other: Point3DF) { + fn add_assign(&mut self, other: Vector4F) { self.0 += other.0 } } -impl Mul for Point3DF { - type Output = Point3DF; +impl Mul for Vector4F { + type Output = Vector4F; #[inline] - fn mul(self, other: Point3DF) -> Point3DF { - Point3DF(self.0 * other.0) + fn mul(self, other: Vector4F) -> Vector4F { + Vector4F(self.0 * other.0) } } -impl Default for Point3DF { +impl Default for Vector4F { #[inline] - fn default() -> Point3DF { + fn default() -> Vector4F { let mut point = F32x4::default(); point.set_w(1.0); - Point3DF(point) + Vector4F(point) } } diff --git a/geometry/src/clip.rs b/geometry/src/clip.rs index 938c1913..4569a68d 100644 --- a/geometry/src/clip.rs +++ b/geometry/src/clip.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use crate::basic::line_segment::LineSegmentF; -use crate::basic::point::{Point2DF, Point3DF}; +use crate::basic::line_segment::LineSegment2F; +use crate::basic::vector::{Vector2F, Vector4F}; use crate::basic::rect::RectF; use crate::outline::{Contour, PointFlags, PushSegmentFlags}; use crate::segment::{CubicSegment, Segment}; @@ -20,17 +20,17 @@ use std::fmt::Debug; use std::mem; #[derive(Clone, Copy, Debug)] -struct Edge(LineSegmentF); +struct Edge(LineSegment2F); impl TEdge for Edge { #[inline] - fn point_is_inside(&self, point: &Point2DF) -> bool { + fn point_is_inside(&self, point: &Vector2F) -> 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: &LineSegmentF) -> ArrayVec<[f32; 3]> { + fn intersect_line_segment(&self, segment: &LineSegment2F) -> 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: &Point2DF) -> bool { + fn point_is_inside(&self, point: &Vector2F) -> 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: &LineSegmentF) -> ArrayVec<[f32; 3]> { + fn intersect_line_segment(&self, segment: &LineSegment2F) -> 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: &Point2DF) -> bool; - fn intersect_line_segment(&self, segment: &LineSegmentF) -> ArrayVec<[f32; 3]>; + fn point_is_inside(&self, point: &Vector2F) -> bool; + fn intersect_line_segment(&self, segment: &LineSegment2F) -> 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<[Point2DF; 4]>, + clip_polygon: SmallVec<[Vector2F; 4]>, contour: Contour, } @@ -309,7 +309,7 @@ impl ContourClipper for ContourPolygonClipper { impl ContourPolygonClipper { #[inline] - pub(crate) fn new(clip_polygon: &[Point2DF], contour: Contour) -> ContourPolygonClipper { + pub(crate) fn new(clip_polygon: &[Vector2F], 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(LineSegmentF::new(prev, next))); + self.clip_against(Edge(LineSegment2F::new(prev, next))); prev = next; } @@ -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: Point3DF) -> bool { + fn point_is_inside(self, point: Vector4F) -> 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: Point3DF, next: Point3DF) -> Point3DF { + fn line_intersection(self, prev: Vector4F, next: Vector4F) -> Vector4F { 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: RectF, polygon_points: &[Point2DF]) -> bool { +pub(crate) fn rect_is_outside_polygon(rect: RectF, polygon_points: &[Vector2F]) -> 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: RectF, polygon_points: &[Point2DF]) } // Edge equation method. Requires that the polygon be convex. -pub(crate) fn rect_is_inside_polygon(rect: RectF, polygon_points: &[Point2DF]) -> bool { +pub(crate) fn rect_is_inside_polygon(rect: RectF, polygon_points: &[Vector2F]) -> bool { // FIXME(pcwalton): Check winding! let rect_points = [ rect.origin(), diff --git a/geometry/src/dilation.rs b/geometry/src/dilation.rs index 961f687f..4441c90b 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::Point2DF; +use crate::basic::vector::Vector2F; use crate::orientation::Orientation; use crate::outline::Contour; pub struct ContourDilator<'a> { contour: &'a mut Contour, - amount: Point2DF, + amount: Vector2F, orientation: Orientation, } impl<'a> ContourDilator<'a> { pub fn new( contour: &'a mut Contour, - amount: Point2DF, + amount: Vector2F, 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 => Point2DF::new(1.0, -1.0), - Orientation::Cw => Point2DF::new(-1.0, 1.0), + Orientation::Ccw => Vector2F::new(1.0, -1.0), + Orientation::Cw => Vector2F::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 { - Point2DF::default() + Vector2F::default() } else { bisector.scale_xy(scale).scale(1.0 / bisector_length) }; diff --git a/geometry/src/outline.rs b/geometry/src/outline.rs index c66d0868..5858941c 100644 --- a/geometry/src/outline.rs +++ b/geometry/src/outline.rs @@ -10,8 +10,8 @@ //! A compressed in-memory representation of paths. -use crate::basic::line_segment::LineSegmentF; -use crate::basic::point::Point2DF; +use crate::basic::line_segment::LineSegment2F; +use crate::basic::vector::Vector2F; use crate::basic::rect::RectF; use crate::basic::transform2d::Transform2DF; use crate::basic::transform3d::Perspective; @@ -32,7 +32,7 @@ pub struct Outline { #[derive(Clone)] pub struct Contour { - pub(crate) points: Vec, + pub(crate) points: Vec, pub(crate) flags: Vec, pub(crate) bounds: RectF, pub(crate) closed: bool, @@ -156,7 +156,7 @@ impl Outline { self.bounds = new_bounds.unwrap_or_else(|| RectF::default()); } - pub fn dilate(&mut self, amount: Point2DF) { + pub fn dilate(&mut self, amount: Vector2F) { let orientation = Orientation::from_outline(self); self.contours .iter_mut() @@ -174,15 +174,15 @@ impl Outline { .unwrap_or_else(|| RectF::default()); } - pub fn is_outside_polygon(&self, clip_polygon: &[Point2DF]) -> bool { + pub fn is_outside_polygon(&self, clip_polygon: &[Vector2F]) -> bool { clip::rect_is_outside_polygon(self.bounds, clip_polygon) } - fn is_inside_polygon(&self, clip_polygon: &[Point2DF]) -> bool { + fn is_inside_polygon(&self, clip_polygon: &[Vector2F]) -> bool { clip::rect_is_inside_polygon(self.bounds, clip_polygon) } - pub fn clip_against_polygon(&mut self, clip_polygon: &[Point2DF]) { + pub fn clip_against_polygon(&mut self, clip_polygon: &[Vector2F]) { // Quick check. if self.is_inside_polygon(clip_polygon) { return; @@ -271,33 +271,33 @@ impl Contour { } #[inline] - pub fn position_of(&self, index: u32) -> Point2DF { + pub fn position_of(&self, index: u32) -> Vector2F { self.points[index as usize] } #[inline] - pub fn last_position(&self) -> Option { + pub fn last_position(&self) -> Option { self.points.last().cloned() } #[inline] - pub(crate) fn position_of_last(&self, index: u32) -> Point2DF { + pub(crate) fn position_of_last(&self, index: u32) -> Vector2F { self.points[self.points.len() - index as usize] } #[inline] - pub fn push_endpoint(&mut self, point: Point2DF) { + pub fn push_endpoint(&mut self, point: Vector2F) { self.push_point(point, PointFlags::empty(), true); } #[inline] - pub fn push_quadratic(&mut self, ctrl: Point2DF, point: Point2DF) { + pub fn push_quadratic(&mut self, ctrl: Vector2F, point: Vector2F) { self.push_point(ctrl, PointFlags::CONTROL_POINT_0, true); self.push_point(point, PointFlags::empty(), true); } #[inline] - pub fn push_cubic(&mut self, ctrl0: Point2DF, ctrl1: Point2DF, point: Point2DF) { + pub fn push_cubic(&mut self, ctrl0: Vector2F, ctrl1: Vector2F, point: Vector2F) { 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); @@ -311,7 +311,7 @@ impl Contour { // TODO(pcwalton): SIMD. #[inline] pub(crate) fn push_point(&mut self, - point: Point2DF, + point: Vector2F, flags: PointFlags, update_bounds: bool) { debug_assert!(!point.x().is_nan() && !point.y().is_nan()); @@ -360,20 +360,20 @@ impl Contour { if end_angle - start_angle >= PI * 2.0 { self.push_ellipse(transform); } else { - let start = Point2DF::new(f32::cos(start_angle), f32::sin(start_angle)); - let end = Point2DF::new(f32::cos(end_angle), f32::sin(end_angle)); - self.push_arc_from_unit_chord(transform, LineSegmentF::new(start, end), direction); + let start = Vector2F::new(f32::cos(start_angle), f32::sin(start_angle)); + let end = Vector2F::new(f32::cos(end_angle), f32::sin(end_angle)); + self.push_arc_from_unit_chord(transform, LineSegment2F::new(start, end), direction); } } pub fn push_arc_from_unit_chord(&mut self, transform: &Transform2DF, - mut chord: LineSegmentF, + mut chord: LineSegment2F, direction: ArcDirection) { let mut direction_transform = Transform2DF::default(); if direction == ArcDirection::CCW { - chord = chord.scale_xy(Point2DF::new(-1.0, 1.0)); - direction_transform = Transform2DF::from_scale(Point2DF::new(-1.0, 1.0)); + chord = chord.scale_xy(Vector2F::new(-1.0, 1.0)); + direction_transform = Transform2DF::from_scale(Vector2F::new(-1.0, 1.0)); } let (mut vector, end_vector) = (UnitVector(chord.from()), UnitVector(chord.to())); @@ -385,7 +385,7 @@ impl Contour { let mut segment; if !last { - sweep_vector = UnitVector(Point2DF::new(0.0, 1.0)); + sweep_vector = UnitVector(Vector2F::new(0.0, 1.0)); segment = Segment::quarter_circle_arc(); } else { segment = Segment::arc_from_cos(sweep_vector.0.x()); @@ -418,13 +418,13 @@ impl Contour { let mut rotation; self.push_segment(&segment.transform(transform), PushSegmentFlags::UPDATE_BOUNDS | PushSegmentFlags::INCLUDE_FROM_POINT); - rotation = Transform2DF::from_rotation_vector(UnitVector(Point2DF::new( 0.0, 1.0))); + rotation = Transform2DF::from_rotation_vector(UnitVector(Vector2F::new( 0.0, 1.0))); self.push_segment(&segment.transform(&rotation.post_mul(&transform)), PushSegmentFlags::UPDATE_BOUNDS); - rotation = Transform2DF::from_rotation_vector(UnitVector(Point2DF::new(-1.0, 0.0))); + rotation = Transform2DF::from_rotation_vector(UnitVector(Vector2F::new(-1.0, 0.0))); self.push_segment(&segment.transform(&rotation.post_mul(&transform)), PushSegmentFlags::UPDATE_BOUNDS); - rotation = Transform2DF::from_rotation_vector(UnitVector(Point2DF::new( 0.0, -1.0))); + rotation = Transform2DF::from_rotation_vector(UnitVector(Vector2F::new( 0.0, -1.0))); self.push_segment(&segment.transform(&rotation.post_mul(&transform)), PushSegmentFlags::UPDATE_BOUNDS); } @@ -460,9 +460,9 @@ impl Contour { } #[inline] - pub fn hull_segment_after(&self, prev_point_index: u32) -> LineSegmentF { + pub fn hull_segment_after(&self, prev_point_index: u32) -> LineSegment2F { let next_point_index = self.next_point_index_of(prev_point_index); - LineSegmentF::new( + LineSegment2F::new( self.points[prev_point_index as usize], self.points[next_point_index as usize], ) @@ -546,7 +546,7 @@ impl Contour { } } - pub fn dilate(&mut self, amount: Point2DF, orientation: Orientation) { + pub fn dilate(&mut self, amount: Vector2F, orientation: Orientation) { ContourDilator::new(self, amount, orientation).dilate(); self.bounds = self.bounds.dilate(amount); } @@ -600,7 +600,7 @@ impl Contour { } else { point_index }; - let baseline = LineSegmentF::new( + let baseline = LineSegment2F::new( contour.points[last_endpoint_index as usize], contour.points[position_index as usize], ); @@ -616,7 +616,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 = LineSegmentF::new(*ctrl_position_0, *ctrl_position_1); + let ctrl = LineSegment2F::new(*ctrl_position_0, *ctrl_position_1); handle_cubic(self, &Segment::cubic(&baseline, &ctrl)); } @@ -802,21 +802,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(&LineSegmentF::new(point0, point1))); + return Some(Segment::line(&LineSegment2F::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(&LineSegmentF::new(point0, point1))); + return Some(Segment::line(&LineSegment2F::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(&LineSegmentF::new(point0, point2), point1)); + return Some(Segment::quadratic(&LineSegment2F::new(point0, point2), point1)); } let point3_index = self.index; @@ -824,8 +824,8 @@ impl<'a> Iterator for ContourIter<'a> { self.index += 1; debug_assert!(contour.point_is_endpoint(point3_index)); return Some(Segment::cubic( - &LineSegmentF::new(point0, point3), - &LineSegmentF::new(point1, point2), + &LineSegment2F::new(point0, point3), + &LineSegment2F::new(point1, point2), )); } } @@ -837,7 +837,7 @@ pub enum ArcDirection { } #[inline] -pub(crate) fn union_rect(bounds: &mut RectF, new_point: Point2DF, first: bool) { +pub(crate) fn union_rect(bounds: &mut RectF, new_point: Vector2F, first: bool) { if first { *bounds = RectF::from_points(new_point, new_point); } else { diff --git a/geometry/src/segment.rs b/geometry/src/segment.rs index 8182754a..c1e8559d 100644 --- a/geometry/src/segment.rs +++ b/geometry/src/segment.rs @@ -10,8 +10,8 @@ //! Line or curve segments, optimized with SIMD. -use crate::basic::line_segment::LineSegmentF; -use crate::basic::point::Point2DF; +use crate::basic::line_segment::LineSegment2F; +use crate::basic::vector::Vector2F; use crate::basic::transform2d::Transform2DF; use crate::util::{self, EPSILON}; use pathfinder_simd::default::F32x4; @@ -21,8 +21,8 @@ const MAX_NEWTON_ITERATIONS: u32 = 32; #[derive(Clone, Copy, Debug, PartialEq)] pub struct Segment { - pub baseline: LineSegmentF, - pub ctrl: LineSegmentF, + pub baseline: LineSegment2F, + pub ctrl: LineSegment2F, pub kind: SegmentKind, pub flags: SegmentFlags, } @@ -31,35 +31,35 @@ impl Segment { #[inline] pub fn none() -> Segment { Segment { - baseline: LineSegmentF::default(), - ctrl: LineSegmentF::default(), + baseline: LineSegment2F::default(), + ctrl: LineSegment2F::default(), kind: SegmentKind::None, flags: SegmentFlags::empty(), } } #[inline] - pub fn line(line: &LineSegmentF) -> Segment { + pub fn line(line: &LineSegment2F) -> Segment { Segment { baseline: *line, - ctrl: LineSegmentF::default(), + ctrl: LineSegment2F::default(), kind: SegmentKind::Line, flags: SegmentFlags::empty(), } } #[inline] - pub fn quadratic(baseline: &LineSegmentF, ctrl: Point2DF) -> Segment { + pub fn quadratic(baseline: &LineSegment2F, ctrl: Vector2F) -> Segment { Segment { baseline: *baseline, - ctrl: LineSegmentF::new(ctrl, Point2DF::default()), + ctrl: LineSegment2F::new(ctrl, Vector2F::default()), kind: SegmentKind::Quadratic, flags: SegmentFlags::empty(), } } #[inline] - pub fn cubic(baseline: &LineSegmentF, ctrl: &LineSegmentF) -> Segment { + pub fn cubic(baseline: &LineSegment2F, ctrl: &LineSegment2F) -> Segment { Segment { baseline: *baseline, ctrl: *ctrl, @@ -91,20 +91,20 @@ impl Segment { let (p0x, p0y) = (p3p0.z(), p3p0.w()); let (p1x, p1y) = (4.0 - p0x, (1.0 - p0x) * (3.0 - p0x) / p0y); let p2p1 = F32x4::new(p1x, -p1y, p1x, p1y) * F32x4::splat(1.0 / 3.0); - return Segment::cubic(&LineSegmentF(p3p0), &LineSegmentF(p2p1)); + return Segment::cubic(&LineSegment2F(p3p0), &LineSegment2F(p2p1)); } #[inline] pub fn quarter_circle_arc() -> Segment { - let p0 = Point2DF::splat(SQRT_2 * 0.5); - let p1 = Point2DF::new(-SQRT_2 / 6.0 + 4.0 / 3.0, 7.0 * SQRT_2 / 6.0 - 4.0 / 3.0); - let flip = Point2DF::new(1.0, -1.0); + let p0 = Vector2F::splat(SQRT_2 * 0.5); + let p1 = Vector2F::new(-SQRT_2 / 6.0 + 4.0 / 3.0, 7.0 * SQRT_2 / 6.0 - 4.0 / 3.0); + let flip = Vector2F::new(1.0, -1.0); let (p2, p3) = (p1.scale_xy(flip), p0.scale_xy(flip)); - Segment::cubic(&LineSegmentF::new(p3, p0), &LineSegmentF::new(p2, p1)) + Segment::cubic(&LineSegment2F::new(p3, p0), &LineSegment2F::new(p2, p1)) } #[inline] - pub fn as_line_segment(&self) -> LineSegmentF { + pub fn as_line_segment(&self) -> LineSegment2F { debug_assert!(self.is_line()); self.baseline } @@ -146,7 +146,7 @@ impl Segment { let mut new_segment = *self; let p1_2 = self.ctrl.from() + self.ctrl.from(); new_segment.ctrl = - LineSegmentF::new(self.baseline.from() + p1_2, p1_2 + self.baseline.to()) + LineSegment2F::new(self.baseline.from() + p1_2, p1_2 + self.baseline.to()) .scale(1.0 / 3.0); new_segment.kind = SegmentKind::Cubic; new_segment @@ -205,7 +205,7 @@ impl Segment { } #[inline] - pub fn sample(self, t: f32) -> Point2DF { + pub fn sample(self, t: f32) -> Vector2F { // FIXME(pcwalton): Don't degree elevate! if self.is_line() { self.as_line_segment().sample(t) @@ -262,16 +262,16 @@ impl<'s> CubicSegment<'s> { let (baseline0, ctrl0, baseline1, ctrl1); if t <= 0.0 { let from = &self.0.baseline.from(); - baseline0 = LineSegmentF::new(*from, *from); - ctrl0 = LineSegmentF::new(*from, *from); + baseline0 = LineSegment2F::new(*from, *from); + ctrl0 = LineSegment2F::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 = LineSegmentF::new(*to, *to); - ctrl1 = LineSegmentF::new(*to, *to); + baseline1 = LineSegment2F::new(*to, *to); + ctrl1 = LineSegment2F::new(*to, *to); } else { let tttt = F32x4::splat(t); @@ -290,10 +290,10 @@ impl<'s> CubicSegment<'s> { // p0123 = lerp(p012, p123, t) let p0123 = p012p123 + tttt * (p123 - p012p123); - 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)); + baseline0 = LineSegment2F(p0p3.concat_xy_xy(p0123)); + ctrl0 = LineSegment2F(p01p12.concat_xy_xy(p012p123)); + baseline1 = LineSegment2F(p0123.concat_xy_zw(p0p3)); + ctrl1 = LineSegment2F(p012p123.concat_zw_zw(p12p23)); } ( @@ -324,7 +324,7 @@ impl<'s> CubicSegment<'s> { // FIXME(pcwalton): Use Horner's method! #[inline] - pub fn sample(self, t: f32) -> Point2DF { + pub fn sample(self, t: f32) -> Vector2F { self.split(t).0.baseline.to() } diff --git a/geometry/src/stroke.rs b/geometry/src/stroke.rs index fe80cef0..4e9a195a 100644 --- a/geometry/src/stroke.rs +++ b/geometry/src/stroke.rs @@ -10,8 +10,8 @@ //! Utilities for converting path strokes to fills. -use crate::basic::line_segment::LineSegmentF; -use crate::basic::point::Point2DF; +use crate::basic::line_segment::LineSegment2F; +use crate::basic::vector::Vector2F; use crate::basic::rect::RectF; use crate::basic::transform2d::Transform2DF; use crate::outline::{ArcDirection, Contour, Outline, PushSegmentFlags}; @@ -100,7 +100,7 @@ impl<'a> OutlineStrokeToFill<'a> { // Add join if necessary. if closed && stroker.output.might_need_join(self.style.line_join) { let (p1, p0) = (stroker.output.position_of(1), stroker.output.position_of(0)); - let final_segment = LineSegmentF::new(p1, p0); + let final_segment = LineSegment2F::new(p1, p0); stroker.output.add_join(self.style.line_width * 0.5, self.style.line_join, stroker.input.position_of(0), @@ -127,7 +127,7 @@ impl<'a> OutlineStrokeToFill<'a> { let offset = gradient.scale(width * 0.5); let p2 = p1 + offset; - let p3 = p2 + gradient.yx().scale_xy(Point2DF::new(-width, width)); + let p3 = p2 + gradient.yx().scale_xy(Vector2F::new(-width, width)); let p4 = p3 - offset; contour.push_endpoint(p2); @@ -136,12 +136,12 @@ impl<'a> OutlineStrokeToFill<'a> { } LineCap::Round => { - let scale = Point2DF::splat(width * 0.5); - let offset = gradient.yx().scale_xy(Point2DF::new(-1.0, 1.0)); + let scale = Vector2F::splat(width * 0.5); + let offset = gradient.yx().scale_xy(Vector2F::new(-1.0, 1.0)); let mut transform = Transform2DF::from_scale(scale); let translation = p1 + offset.scale(width * 0.5); transform = transform.post_mul(&Transform2DF::from_translation(translation)); - let chord = LineSegmentF::new(-offset, offset); + let chord = LineSegment2F::new(-offset, offset); contour.push_arc_from_unit_chord(&transform, chord, ArcDirection::CW); } } @@ -191,7 +191,7 @@ trait Offset { fn add_to_contour(&self, distance: f32, join: LineJoin, - join_point: Point2DF, + join_point: Vector2F, contour: &mut Contour); fn offset_once(&self, distance: f32) -> Self; fn error_is_within_tolerance(&self, other: &Segment, distance: f32) -> bool; @@ -222,7 +222,7 @@ impl Offset for Segment { fn add_to_contour(&self, distance: f32, join: LineJoin, - join_point: Point2DF, + join_point: Vector2F, contour: &mut Contour) { // Add join if necessary. if contour.might_need_join(join) { @@ -235,7 +235,7 @@ impl Offset for Segment { self.ctrl.from() }; - contour.add_join(distance, join, join_point, &LineSegmentF::new(p4, p3)); + contour.add_join(distance, join, join_point, &LineSegment2F::new(p4, p3)); } // Push segment. @@ -249,51 +249,51 @@ impl Offset for Segment { } if self.is_quadratic() { - let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.from()); - let mut segment_1 = LineSegmentF::new(self.ctrl.from(), self.baseline.to()); + let mut segment_0 = LineSegment2F::new(self.baseline.from(), self.ctrl.from()); + let mut segment_1 = LineSegment2F::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 = LineSegmentF::new(segment_0.from(), segment_1.to()); + let baseline = LineSegment2F::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 = LineSegmentF::new(self.baseline.from(), self.ctrl.to()); - let mut segment_1 = LineSegmentF::new(self.ctrl.to(), self.baseline.to()); + let mut segment_0 = LineSegment2F::new(self.baseline.from(), self.ctrl.to()); + let mut segment_1 = LineSegment2F::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 = LineSegmentF::new(segment_0.from(), segment_1.to()); - let ctrl = LineSegmentF::new(segment_0.from(), ctrl); + let baseline = LineSegment2F::new(segment_0.from(), segment_1.to()); + let ctrl = LineSegment2F::new(segment_0.from(), ctrl); return Segment::cubic(&baseline, &ctrl); } if 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.baseline.to()); + let mut segment_0 = LineSegment2F::new(self.baseline.from(), self.ctrl.from()); + let mut segment_1 = LineSegment2F::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 = LineSegmentF::new(segment_0.from(), segment_1.to()); - let ctrl = LineSegmentF::new(ctrl, segment_1.to()); + let baseline = LineSegment2F::new(segment_0.from(), segment_1.to()); + let ctrl = LineSegment2F::new(ctrl, segment_1.to()); return Segment::cubic(&baseline, &ctrl); } - 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()); + let mut segment_0 = LineSegment2F::new(self.baseline.from(), self.ctrl.from()); + let mut segment_1 = LineSegment2F::new(self.ctrl.from(), self.ctrl.to()); + let mut segment_2 = LineSegment2F::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); @@ -307,8 +307,8 @@ impl Offset for Segment { segment_1.to().lerp(segment_2.from(), 0.5), ), }; - let baseline = LineSegmentF::new(segment_0.from(), segment_2.to()); - let ctrl = LineSegmentF::new(ctrl_0, ctrl_1); + let baseline = LineSegment2F::new(segment_0.from(), segment_2.to()); + let ctrl = LineSegment2F::new(ctrl_0, ctrl_1); Segment::cubic(&baseline, &ctrl) } @@ -356,10 +356,10 @@ impl Contour { fn add_join(&mut self, distance: f32, join: LineJoin, - join_point: Point2DF, - next_tangent: &LineSegmentF) { + join_point: Vector2F, + next_tangent: &LineSegment2F) { let (p0, p1) = (self.position_of_last(2), self.position_of_last(1)); - let prev_tangent = LineSegmentF::new(p0, p1); + let prev_tangent = LineSegment2F::new(p0, p1); match join { LineJoin::Bevel => {} @@ -373,12 +373,12 @@ impl Contour { } } LineJoin::Round => { - let scale = Point2DF::splat(distance.abs()); + let scale = Vector2F::splat(distance.abs()); let mut transform = Transform2DF::from_scale(scale); transform = transform.post_mul(&Transform2DF::from_translation(join_point)); let chord_from = (prev_tangent.to() - join_point).normalize(); let chord_to = (next_tangent.to() - join_point).normalize(); - let chord = LineSegmentF::new(chord_from, chord_to); + let chord = LineSegment2F::new(chord_from, chord_to); self.push_arc_from_unit_chord(&transform, chord, ArcDirection::CW); } } diff --git a/geometry/src/unit_vector.rs b/geometry/src/unit_vector.rs index 27fb9a9d..35533e7a 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::Point2DF; +use crate::basic::vector::Vector2F; use pathfinder_simd::default::F32x4; #[derive(Clone, Copy, Debug)] -pub struct UnitVector(pub Point2DF); +pub struct UnitVector(pub Vector2F); impl UnitVector { #[inline] pub fn from_angle(theta: f32) -> UnitVector { - UnitVector(Point2DF::new(theta.cos(), theta.sin())) + UnitVector(Vector2F::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(Point2DF::new(products[0] - products[1], products[2] + products[3])) + UnitVector(Vector2F::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(Point2DF::new(products[0] + products[1], products[2] - products[3])) + UnitVector(Vector2F::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(Point2DF((F32x4::splat(0.5) * (F32x4::splat(1.0) + term)).sqrt())) + UnitVector(Vector2F((F32x4::splat(0.5) * (F32x4::splat(1.0) + term)).sqrt())) } } diff --git a/gl/src/lib.rs b/gl/src/lib.rs index 7ebc8c8a..baec4e26 100644 --- a/gl/src/lib.rs +++ b/gl/src/lib.rs @@ -14,7 +14,7 @@ extern crate log; use gl::types::{GLboolean, GLchar, GLenum, GLfloat, GLint, GLsizei, GLsizeiptr, GLuint, GLvoid}; -use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; use pathfinder_geometry::basic::rect::RectI; use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::{BlendState, BufferData, BufferTarget, BufferUploadMode, ClearParams}; @@ -164,7 +164,7 @@ impl Device for GLDevice { type VertexArray = GLVertexArray; type VertexAttr = GLVertexAttr; - fn create_texture(&self, format: TextureFormat, size: Point2DI) -> GLTexture { + fn create_texture(&self, format: TextureFormat, size: Vector2I) -> 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: Point2DI, data: &[u8]) -> GLTexture { + fn create_texture_from_data(&self, size: Vector2I, 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) -> Point2DI { + fn texture_size(&self, texture: &Self::Texture) -> Vector2I { texture.size } - fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI, data: &[u8]) { + fn upload_to_texture(&self, texture: &Self::Texture, size: Vector2I, 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: Point2DI) -> Vec { + fn read_pixels_from_default_framebuffer(&self, size: Vector2I) -> Vec { let mut pixels = vec![0; size.x() as usize * size.y() as usize * 4]; unsafe { gl::BindFramebuffer(gl::FRAMEBUFFER, self.default_framebuffer); ck(); @@ -799,7 +799,7 @@ impl Drop for GLShader { pub struct GLTexture { gl_texture: GLuint, - pub size: Point2DI, + pub size: Vector2I, } pub struct GLTimerQuery { diff --git a/gpu/src/lib.rs b/gpu/src/lib.rs index dbdcd7d4..fdbab686 100644 --- a/gpu/src/lib.rs +++ b/gpu/src/lib.rs @@ -12,7 +12,7 @@ use crate::resources::ResourceLoader; use image::ImageFormat; -use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; use pathfinder_geometry::basic::rect::RectI; use pathfinder_geometry::basic::transform3d::Transform3DF; use pathfinder_geometry::color::ColorF; @@ -41,8 +41,8 @@ pub trait Device { type VertexArray; type VertexAttr; - fn create_texture(&self, format: TextureFormat, size: Point2DI) -> Self::Texture; - fn create_texture_from_data(&self, size: Point2DI, data: &[u8]) -> Self::Texture; + fn create_texture(&self, format: TextureFormat, size: Vector2I) -> Self::Texture; + fn create_texture_from_data(&self, size: Vector2I, 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) -> Point2DI; - fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI, data: &[u8]); - fn read_pixels_from_default_framebuffer(&self, size: Point2DI) -> Vec; + fn texture_size(&self, texture: &Self::Texture) -> Vector2I; + fn upload_to_texture(&self, texture: &Self::Texture, size: Vector2I, data: &[u8]); + fn read_pixels_from_default_framebuffer(&self, size: Vector2I) -> 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); @@ -103,7 +103,7 @@ pub trait Device { let image = image::load_from_memory_with_format(&data, ImageFormat::PNG) .unwrap() .to_luma(); - let size = Point2DI::new(image.width() as i32, image.height() as i32); + let size = Vector2I::new(image.width() as i32, image.height() as i32); self.create_texture_from_data(size, &image) } diff --git a/renderer/src/builder.rs b/renderer/src/builder.rs index c4353b3b..73562f8d 100644 --- a/renderer/src/builder.rs +++ b/renderer/src/builder.rs @@ -17,8 +17,8 @@ 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::{LineSegmentF, LineSegmentU4, LineSegmentU8}; -use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::line_segment::{LineSegment2F, LineSegmentU4, LineSegmentU8}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; use pathfinder_geometry::basic::rect::{RectF, RectI}; use pathfinder_geometry::util; use pathfinder_simd::default::{F32x4, I32x4}; @@ -160,8 +160,8 @@ impl BuiltObject { fn add_fill( &mut self, builder: &SceneBuilder, - segment: &LineSegmentF, - tile_coords: Point2DI, + segment: &LineSegment2F, + tile_coords: Vector2I, ) { 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: Point2DI, + tile_coords: Vector2I, ) -> 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: Point2DI, + tile_coords: Vector2I, ) { let tile_origin_y = (tile_coords.y() * TILE_HEIGHT as i32) as f32; - let left = Point2DF::new(left, tile_origin_y); - let right = Point2DF::new(right, tile_origin_y); + let left = Vector2F::new(left, tile_origin_y); + let right = Vector2F::new(right, tile_origin_y); let segment = if winding < 0 { - LineSegmentF::new(left, right) + LineSegment2F::new(left, right) } else { - LineSegmentF::new(right, left) + LineSegment2F::new(right, left) }; debug!( @@ -268,7 +268,7 @@ impl BuiltObject { pub(crate) fn generate_fill_primitives_for_line( &mut self, builder: &SceneBuilder, - mut segment: LineSegmentF, + mut segment: LineSegment2F, 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 = Point2DF::new(x, segment.solve_y_for_x(x)); + let point = Vector2F::new(x, segment.solve_y_for_x(x)); if !winding { fill_to = point; - segment = LineSegmentF::new(point, segment.to()); + segment = LineSegment2F::new(point, segment.to()); } else { fill_from = point; - segment = LineSegmentF::new(segment.from(), point); + segment = LineSegment2F::new(segment.from(), point); } } - let fill_segment = LineSegmentF::new(fill_from, fill_to); - let fill_tile_coords = Point2DI::new(subsegment_tile_x, tile_y); + let fill_segment = LineSegment2F::new(fill_from, fill_to); + let fill_tile_coords = Vector2I::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: Point2DI) -> Option { + pub(crate) fn tile_coords_to_local_index(&self, coords: Vector2I) -> 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) -> Point2DI { + pub(crate) fn local_tile_index_to_coords(&self, tile_index: u32) -> Vector2I { self.tiles.index_to_coords(tile_index as usize) } } diff --git a/renderer/src/gpu/debug.rs b/renderer/src/gpu/debug.rs index ca69b9ad..5e982d79 100644 --- a/renderer/src/gpu/debug.rs +++ b/renderer/src/gpu/debug.rs @@ -16,7 +16,7 @@ //! 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::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; use pathfinder_geometry::basic::rect::RectI; use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::Device; @@ -50,7 +50,7 @@ where pub fn new( device: &D, resources: &dyn ResourceLoader, - framebuffer_size: Point2DI, + framebuffer_size: Vector2I, ) -> DebugUIPresenter { let ui_presenter = UIPresenter::new(device, resources, framebuffer_size); DebugUIPresenter { @@ -85,16 +85,16 @@ where let framebuffer_size = self.ui_presenter.framebuffer_size(); let bottom = framebuffer_size.y() - PADDING; let window_rect = RectI::new( - Point2DI::new( + Vector2I::new( framebuffer_size.x() - PADDING - STATS_WINDOW_WIDTH, bottom - PERFORMANCE_WINDOW_HEIGHT - PADDING - STATS_WINDOW_HEIGHT, ), - Point2DI::new(STATS_WINDOW_WIDTH, STATS_WINDOW_HEIGHT), + Vector2I::new(STATS_WINDOW_WIDTH, STATS_WINDOW_HEIGHT), ); self.ui_presenter.draw_solid_rounded_rect(device, window_rect, WINDOW_COLOR); - let origin = window_rect.origin() + Point2DI::new(PADDING, PADDING + FONT_ASCENT); + let origin = window_rect.origin() + Vector2I::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 + Point2DI::new(0, LINE_HEIGHT * 1), + origin + Vector2I::new(0, LINE_HEIGHT * 1), false, ); self.ui_presenter.draw_text( device, &format!("Alpha Tiles: {}", mean_cpu_sample.stats.alpha_tile_count), - origin + Point2DI::new(0, LINE_HEIGHT * 2), + origin + Vector2I::new(0, LINE_HEIGHT * 2), false, ); self.ui_presenter.draw_text( device, &format!("Fills: {}", mean_cpu_sample.stats.fill_count), - origin + Point2DI::new(0, LINE_HEIGHT * 3), + origin + Vector2I::new(0, LINE_HEIGHT * 3), false, ); } @@ -125,16 +125,16 @@ where let framebuffer_size = self.ui_presenter.framebuffer_size(); let bottom = framebuffer_size.y() - PADDING; let window_rect = RectI::new( - Point2DI::new( + Vector2I::new( framebuffer_size.x() - PADDING - PERFORMANCE_WINDOW_WIDTH, bottom - PERFORMANCE_WINDOW_HEIGHT, ), - Point2DI::new(PERFORMANCE_WINDOW_WIDTH, PERFORMANCE_WINDOW_HEIGHT), + Vector2I::new(PERFORMANCE_WINDOW_WIDTH, PERFORMANCE_WINDOW_HEIGHT), ); self.ui_presenter.draw_solid_rounded_rect(device, window_rect, WINDOW_COLOR); - let origin = window_rect.origin() + Point2DI::new(PADDING, PADDING + FONT_ASCENT); + let origin = window_rect.origin() + Vector2I::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 + Point2DI::new(0, LINE_HEIGHT * 1), + origin + Vector2I::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 + Point2DI::new(0, LINE_HEIGHT * 2), + origin + Vector2I::new(0, LINE_HEIGHT * 2), false, ); @@ -171,7 +171,7 @@ where self.ui_presenter.draw_text( device, &format!("Wallclock: {:.3} ms", wallclock_time), - origin + Point2DI::new(0, LINE_HEIGHT * 3), + origin + Vector2I::new(0, LINE_HEIGHT * 3), false, ); } diff --git a/renderer/src/gpu/renderer.rs b/renderer/src/gpu/renderer.rs index 9d6d2b0c..0579d0f2 100644 --- a/renderer/src/gpu/renderer.rs +++ b/renderer/src/gpu/renderer.rs @@ -13,7 +13,7 @@ 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::{Point2DI, Point3DF}; +use pathfinder_geometry::basic::vector::{Vector2I, Vector4F}; use pathfinder_geometry::basic::rect::RectI; use pathfinder_geometry::basic::transform3d::Transform3DF; use pathfinder_geometry::color::ColorF; @@ -182,7 +182,7 @@ where ); let mask_framebuffer_size = - Point2DI::new(MASK_FRAMEBUFFER_WIDTH, MASK_FRAMEBUFFER_HEIGHT); + Vector2I::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: Point2DI) { + pub fn set_main_framebuffer_size(&mut self, new_framebuffer_size: Vector2I) { self.debug_ui_presenter.ui_presenter.set_framebuffer_size(new_framebuffer_size); } @@ -715,7 +715,7 @@ where } } - fn draw_stencil(&self, quad_positions: &[Point3DF]) { + fn draw_stencil(&self, quad_positions: &[Vector4F]) { self.device.allocate_buffer( &self.stencil_vertex_array.vertex_buffer, BufferData::Memory(quad_positions), @@ -876,8 +876,8 @@ where defringing_kernel: Some(..), .. } => { - let scale = Point2DI::new(3, 1); - RectI::new(Point2DI::default(), main_viewport.size().scale_xy(scale)) + let scale = Vector2I::new(3, 1); + RectI::new(Vector2I::default(), main_viewport.size().scale_xy(scale)) } _ => main_viewport, } @@ -890,7 +890,7 @@ where let size = self .device .texture_size(self.device.framebuffer_texture(framebuffer)); - RectI::new(Point2DI::default(), size) + RectI::new(Vector2I::default(), size) } } } @@ -1555,7 +1555,7 @@ where { Default { viewport: RectI, - window_size: Point2DI, + window_size: Vector2I, }, Other(D::Framebuffer), } @@ -1565,12 +1565,12 @@ where D: Device, { #[inline] - pub fn full_window(window_size: Point2DI) -> DestFramebuffer { - let viewport = RectI::new(Point2DI::default(), window_size); + pub fn full_window(window_size: Vector2I) -> DestFramebuffer { + let viewport = RectI::new(Vector2I::default(), window_size); DestFramebuffer::Default { viewport, window_size } } - fn window_size(&self, device: &D) -> Point2DI { + fn window_size(&self, device: &D) -> Vector2I { 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 b7312b54..76734d59 100644 --- a/renderer/src/gpu_data.rs +++ b/renderer/src/gpu_data.rs @@ -13,7 +13,7 @@ use crate::options::BoundingQuad; use crate::tile_map::DenseTileMap; use pathfinder_geometry::basic::line_segment::{LineSegmentU4, LineSegmentU8}; -use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; use pathfinder_geometry::basic::rect::RectF; use std::fmt::{Debug, Formatter, Result as DebugResult}; use std::time::Duration; @@ -38,7 +38,7 @@ pub enum RenderCommand { #[derive(Clone, Debug)] pub struct PaintData { - pub size: Point2DI, + pub size: Vector2I, pub texels: Vec, } diff --git a/renderer/src/options.rs b/renderer/src/options.rs index b9e29028..2cb34fe6 100644 --- a/renderer/src/options.rs +++ b/renderer/src/options.rs @@ -11,7 +11,7 @@ //! Options that control how rendering is to be performed. use crate::gpu_data::RenderCommand; -use pathfinder_geometry::basic::point::{Point2DF, Point3DF}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector4F}; use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::basic::transform3d::Perspective; @@ -34,7 +34,7 @@ where #[derive(Clone, Default)] pub struct RenderOptions { pub transform: RenderTransform, - pub dilation: Point2DF, + pub dilation: Vector2F, pub subpixel_aa_enabled: bool, } @@ -121,7 +121,7 @@ impl RenderTransform { pub(crate) struct PreparedRenderOptions { pub(crate) transform: PreparedRenderTransform, - pub(crate) dilation: Point2DF, + pub(crate) dilation: Vector2F, 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, - _ => [Point3DF::default(); 4], + _ => [Vector4F::default(); 4], } } } -pub(crate) type BoundingQuad = [Point3DF; 4]; +pub(crate) type BoundingQuad = [Vector4F; 4]; pub(crate) enum PreparedRenderTransform { None, Transform2D(Transform2DF), Perspective { perspective: Perspective, - clip_polygon: Vec, - quad: [Point3DF; 4], + clip_polygon: Vec, + quad: [Vector4F; 4], }, } diff --git a/renderer/src/paint.rs b/renderer/src/paint.rs index 577661f9..134ca8a4 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::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; 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 = Point2DI::new(PAINT_TEXTURE_WIDTH, PAINT_TEXTURE_HEIGHT); + let size = Vector2I::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) -> Point2DI { - let tex_coords = Point2DI::new(paint_id.0 as i32 % PAINT_TEXTURE_WIDTH, +pub(crate) fn paint_id_to_tex_coords(paint_id: PaintId) -> Vector2I { + let tex_coords = Vector2I::new(paint_id.0 as i32 % PAINT_TEXTURE_WIDTH, paint_id.0 as i32 / PAINT_TEXTURE_WIDTH); - tex_coords.scale(256) + Point2DI::new(128, 128) + tex_coords.scale(256) + Vector2I::new(128, 128) } diff --git a/renderer/src/scene.rs b/renderer/src/scene.rs index 478bee58..45cc1c44 100644 --- a/renderer/src/scene.rs +++ b/renderer/src/scene.rs @@ -16,7 +16,7 @@ use crate::options::{PreparedRenderOptions, PreparedRenderTransform}; use crate::options::{RenderCommandListener, RenderOptions}; use crate::paint::{Paint, PaintId}; use hashbrown::HashMap; -use pathfinder_geometry::basic::point::Point2DF; +use pathfinder_geometry::basic::vector::Vector2F; use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::color::ColorU; @@ -121,7 +121,7 @@ impl Scene { }; if options.subpixel_aa_enabled { transform = transform - .post_mul(&Transform2DF::from_scale(Point2DF::new(3.0, 1.0))) + .post_mul(&Transform2DF::from_scale(Vector2F::new(3.0, 1.0))) } outline.transform(&transform); } @@ -158,7 +158,7 @@ impl Scene { #[inline] pub(crate) fn effective_view_box(&self, render_options: &PreparedRenderOptions) -> RectF { if render_options.subpixel_aa_enabled { - self.view_box.scale_xy(Point2DF::new(3.0, 1.0)) + self.view_box.scale_xy(Vector2F::new(3.0, 1.0)) } else { self.view_box } diff --git a/renderer/src/tile_map.rs b/renderer/src/tile_map.rs index fa74fce2..a280df3b 100644 --- a/renderer/src/tile_map.rs +++ b/renderer/src/tile_map.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; use pathfinder_geometry::basic::rect::RectI; #[derive(Debug)] @@ -43,7 +43,7 @@ impl DenseTileMap { } #[inline] - pub fn coords_to_index(&self, coords: Point2DI) -> Option { + pub fn coords_to_index(&self, coords: Vector2I) -> 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: Point2DI) -> usize { + pub fn coords_to_index_unchecked(&self, coords: Vector2I) -> 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) -> Point2DI { + pub fn index_to_coords(&self, index: usize) -> Vector2I { let (width, index) = (self.rect.size().x(), index as i32); - self.rect.origin() + Point2DI::new(index % width, index / width) + self.rect.origin() + Vector2I::new(index % width, index / width) } } diff --git a/renderer/src/tiles.rs b/renderer/src/tiles.rs index e3c567a9..3f5eb89a 100644 --- a/renderer/src/tiles.rs +++ b/renderer/src/tiles.rs @@ -12,8 +12,8 @@ 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::LineSegmentF; -use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::line_segment::LineSegment2F; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; use pathfinder_geometry::basic::rect::{RectF, RectI}; use pathfinder_geometry::outline::{Contour, Outline, PointIndex}; use pathfinder_geometry::segment::Segment; @@ -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 = Point2DI::new(current_tile_x, tile_y); + let current_tile_coords = Vector2I::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 = Point2DI::new(current_tile_x, tile_y); + let current_tile_coords = Vector2I::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 = Point2DI::new(current_tile_x, tile_y); + let current_tile_coords = Vector2I::new(current_tile_x, tile_y); self.built_object.add_active_fill( self.builder, current_x, @@ -355,7 +355,7 @@ impl<'a> Tiler<'a> { } pub fn round_rect_out_to_tile_bounds(rect: RectF) -> RectI { - rect.scale_xy(Point2DF::new( + rect.scale_xy(Vector2F::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: Point2DF, + crossing: Vector2F, } impl ActiveEdge { @@ -416,7 +416,7 @@ impl ActiveEdge { ActiveEdge::from_segment_and_crossing(segment, &crossing) } - fn from_segment_and_crossing(segment: &Segment, crossing: &Point2DF) -> ActiveEdge { + fn from_segment_and_crossing(segment: &Segment, crossing: &Vector2F) -> 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 = - LineSegmentF::new(self.crossing, segment.baseline.upper_point()).orient(winding); + LineSegment2F::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: &LineSegmentF, + line_segment: &LineSegment2F, 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: Point2DI, + fn new(tile_coords: Vector2I, backdrop: i8, object_index: u16, tile_index: u16, - origin_uv: Point2DI) + origin_uv: Vector2I) -> AlphaTileBatchPrimitive { AlphaTileBatchPrimitive { tile_x_lo: (tile_coords.x() & 0xff) as u8, @@ -554,8 +554,8 @@ impl AlphaTileBatchPrimitive { } #[inline] - pub fn tile_coords(&self) -> Point2DI { - Point2DI::new( + pub fn tile_coords(&self) -> Vector2I { + Vector2I::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 bd0c66bf..889cc666 100644 --- a/renderer/src/z_buffer.rs +++ b/renderer/src/z_buffer.rs @@ -15,7 +15,7 @@ use crate::paint; use crate::scene::PathObject; use crate::tile_map::DenseTileMap; use crate::tiles; -use pathfinder_geometry::basic::point::Point2DI; +use pathfinder_geometry::basic::vector::Vector2I; use pathfinder_geometry::basic::rect::RectF; use std::ops::Range; use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering}; @@ -32,13 +32,13 @@ impl ZBuffer { } } - pub fn test(&self, coords: Point2DI, object_index: u32) -> bool { + pub fn test(&self, coords: Vector2I, 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: Point2DI, object_index: u16) { + pub fn update(&self, coords: Vector2I, 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: Point2DI, object_index: u16, origin_uv: Point2DI) + fn new(tile_coords: Vector2I, object_index: u16, origin_uv: Vector2I) -> SolidTileBatchPrimitive { SolidTileBatchPrimitive { tile_x: tile_coords.x() as i16, diff --git a/simd/src/x86/mod.rs b/simd/src/x86/mod.rs index 5452480b..c4af9a93 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 `Point3DF`! + // FIXME(pcwalton): Move to `Vector4F`! #[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 246b91e0..ab664535 100644 --- a/svg/src/lib.rs +++ b/svg/src/lib.rs @@ -13,8 +13,8 @@ #[macro_use] extern crate bitflags; -use pathfinder_geometry::basic::line_segment::LineSegmentF; -use pathfinder_geometry::basic::point::Point2DF; +use pathfinder_geometry::basic::line_segment::LineSegment2F; +use pathfinder_geometry::basic::vector::Vector2F; use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::basic::transform2d::{Transform2DF, Transform2DFPathIter}; use pathfinder_geometry::color::ColorU; @@ -268,8 +268,8 @@ impl PaintExt for Paint { 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), + Vector2F::new(rect.x as f32, rect.y as f32), + Vector2F::new(rect.width as f32, rect.height as f32), ) } @@ -289,8 +289,8 @@ where I: Iterator, { iter: I, - first_subpath_point: Point2DF, - last_subpath_point: Point2DF, + first_subpath_point: Vector2F, + last_subpath_point: Vector2F, just_moved: bool, } @@ -301,8 +301,8 @@ where fn new(iter: I) -> UsvgPathToSegments { UsvgPathToSegments { iter, - first_subpath_point: Point2DF::default(), - last_subpath_point: Point2DF::default(), + first_subpath_point: Vector2F::default(), + last_subpath_point: Vector2F::default(), just_moved: false, } } @@ -317,15 +317,15 @@ where fn next(&mut self) -> Option { match self.iter.next()? { UsvgPathSegment::MoveTo { x, y } => { - let to = Point2DF::new(x as f32, y as f32); + let to = Vector2F::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 = Point2DF::new(x as f32, y as f32); - let mut segment = Segment::line(&LineSegmentF::new(self.last_subpath_point, to)); + let to = Vector2F::new(x as f32, y as f32); + let mut segment = Segment::line(&LineSegment2F::new(self.last_subpath_point, to)); if self.just_moved { segment.flags.insert(SegmentFlags::FIRST_IN_SUBPATH); } @@ -341,12 +341,12 @@ where x, y, } => { - 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 ctrl0 = Vector2F::new(x1 as f32, y1 as f32); + let ctrl1 = Vector2F::new(x2 as f32, y2 as f32); + let to = Vector2F::new(x as f32, y as f32); let mut segment = Segment::cubic( - &LineSegmentF::new(self.last_subpath_point, to), - &LineSegmentF::new(ctrl0, ctrl1), + &LineSegment2F::new(self.last_subpath_point, to), + &LineSegment2F::new(ctrl0, ctrl1), ); if self.just_moved { segment.flags.insert(SegmentFlags::FIRST_IN_SUBPATH); @@ -356,7 +356,7 @@ where Some(segment) } UsvgPathSegment::ClosePath => { - let mut segment = Segment::line(&LineSegmentF::new( + let mut segment = Segment::line(&LineSegment2F::new( self.last_subpath_point, self.first_subpath_point, )); diff --git a/text/src/lib.rs b/text/src/lib.rs index d859b944..cbf56765 100644 --- a/text/src/lib.rs +++ b/text/src/lib.rs @@ -13,7 +13,7 @@ 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::Point2DF; +use pathfinder_geometry::basic::vector::Vector2F; use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::outline::{Contour, Outline}; use pathfinder_geometry::stroke::{OutlineStrokeToFill, StrokeStyle}; @@ -88,11 +88,11 @@ impl SceneExt for Scene { paint_id: PaintId) -> Result<(), GlyphLoadingError> { for glyph in &layout.glyphs { - let offset = Point2DF::new(glyph.offset.x, glyph.offset.y); + let offset = Vector2F::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 = Point2DF::new(scale, -scale); + let scale = Vector2F::new(scale, -scale); let transform = Transform2DF::from_scale(scale).post_mul(transform).post_translate(offset); self.push_glyph(font, @@ -147,8 +147,8 @@ impl OutlinePathBuilder { } } - fn convert_point(&self, point: Point2D) -> Point2DF { - self.transform.transform_point(Point2DF::new(point.x, point.y)) + fn convert_point(&self, point: Point2D) -> Vector2F { + self.transform.transform_point(Vector2F::new(point.x, point.y)) } } diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 940af245..0955dbf7 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -17,7 +17,7 @@ extern crate serde_derive; use hashbrown::HashMap; -use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; use pathfinder_geometry::basic::rect::RectI; use pathfinder_geometry::color::ColorU; use pathfinder_gpu::resources::ResourceLoader; @@ -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: Point2DF, + pub mouse_position: Vector2F, - framebuffer_size: Point2DI, + framebuffer_size: Vector2I, 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: Point2DI) + pub fn new(device: &D, resources: &dyn ResourceLoader, framebuffer_size: Vector2I) -> 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: Point2DF::default(), + mouse_position: Vector2F::default(), framebuffer_size, @@ -114,11 +114,11 @@ impl UIPresenter where D: Device { } } - pub fn framebuffer_size(&self) -> Point2DI { + pub fn framebuffer_size(&self) -> Vector2I { self.framebuffer_size } - pub fn set_framebuffer_size(&mut self, window_size: Point2DI) { + pub fn set_framebuffer_size(&mut self, window_size: Vector2I) { self.framebuffer_size = window_size; } @@ -183,7 +183,7 @@ impl UIPresenter where D: Device { }); } - pub fn draw_text(&self, device: &D, string: &str, origin: Point2DI, invert: bool) { + pub fn draw_text(&self, device: &D, string: &str, origin: Vector2I, 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 = - 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)); + RectI::new(Vector2I::new(next.x() - info.origin_x, next.y() - info.origin_y), + Vector2I::new(info.width as i32, info.height as i32)); + let tex_coord_rect = RectI::new(Vector2I::new(info.x, info.y), + Vector2I::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: Point2DI, + origin: Vector2I, texture: &D::Texture, color: ColorU) { let position_rect = RectI::new(origin, device.texture_size(&texture)); - let tex_coord_rect = RectI::new(Point2DI::default(), position_rect.size()); + let tex_coord_rect = RectI::new(Vector2I::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()), @@ -316,7 +316,7 @@ impl UIPresenter where D: Device { } // TODO(pcwalton): `LineSegmentI32`. - fn draw_line(&self, device: &D, from: Point2DI, to: Point2DI, color: ColorU) { + fn draw_line(&self, device: &D, from: Vector2I, to: Vector2I, 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 = RectI::new(Point2DI::default(), corner_size); + let tex_coord_rect = RectI::new(Vector2I::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: Point2DI, texture: &D::Texture) -> bool { - let button_rect = RectI::new(origin, Point2DI::new(BUTTON_WIDTH, BUTTON_HEIGHT)); + pub fn draw_button(&mut self, device: &D, origin: Vector2I, texture: &D::Texture) -> bool { + let button_rect = RectI::new(origin, Vector2I::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 + Point2DI::new(PADDING, PADDING), + origin + Vector2I::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: Point2DI, + mut origin: Vector2I, segment_labels: &[&str], mut value: u8) -> u8 { @@ -436,15 +436,15 @@ impl UIPresenter where D: Device { value = new_value; } - origin = origin + Point2DI::new(0, BUTTON_TEXT_OFFSET); + origin = origin + Vector2I::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 + Point2DI::new(offset, 0), + origin + Vector2I::new(offset, 0), segment_index as u8 == value); - origin += Point2DI::new(SEGMENT_SIZE + 1, 0); + origin += Vector2I::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: Point2DI, + mut origin: Vector2I, 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 = Point2DI::new(SEGMENT_SIZE / 2 - texture_width / 2, PADDING); + let offset = Vector2I::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 += Point2DI::new(SEGMENT_SIZE + 1, 0); + origin += Vector2I::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: Point2DI, + origin: Vector2I, mut value: Option, segment_count: u8) -> Option { let widget_width = self.measure_segmented_control(segment_count); - let widget_rect = RectI::new(origin, Point2DI::new(widget_width, BUTTON_HEIGHT)); + let widget_rect = RectI::new(origin, Vector2I::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 = Point2DI::new(SEGMENT_SIZE, BUTTON_HEIGHT); + let highlight_size = Vector2I::new(SEGMENT_SIZE, BUTTON_HEIGHT); let x_offset = value as i32 * SEGMENT_SIZE + (value as i32 - 1); self.draw_solid_rounded_rect(device, - RectI::new(origin + Point2DI::new(x_offset, 0), + RectI::new(origin + Vector2I::new(x_offset, 0), highlight_size), TEXT_COLOR); } - let mut segment_origin = origin + Point2DI::new(SEGMENT_SIZE + 1, 0); + let mut segment_origin = origin + Vector2I::new(SEGMENT_SIZE + 1, 0); for next_segment_index in 1..segment_count { let prev_segment_index = next_segment_index - 1; match value { @@ -521,11 +521,11 @@ impl UIPresenter where D: Device { _ => { self.draw_line(device, segment_origin, - segment_origin + Point2DI::new(0, BUTTON_HEIGHT), + segment_origin + Vector2I::new(0, BUTTON_HEIGHT), TEXT_COLOR); } } - segment_origin = segment_origin + Point2DI::new(SEGMENT_SIZE + 1, 0); + segment_origin = segment_origin + Vector2I::new(SEGMENT_SIZE + 1, 0); } clicked_segment @@ -537,13 +537,13 @@ impl UIPresenter where D: Device { } let text_size = self.measure_text(string); - let window_size = Point2DI::new(text_size + PADDING * 2, TOOLTIP_HEIGHT); - let origin = rect.origin() - Point2DI::new(0, window_size.y() + PADDING); + let window_size = Vector2I::new(text_size + PADDING * 2, TOOLTIP_HEIGHT); + let origin = rect.origin() - Vector2I::new(0, window_size.y() + PADDING); self.draw_solid_rounded_rect(device, RectI::new(origin, window_size), WINDOW_COLOR); self.draw_text(device, string, - origin + Point2DI::new(PADDING, PADDING + FONT_ASCENT), + origin + Vector2I::new(PADDING, PADDING + FONT_ASCENT), false); } } @@ -668,7 +668,7 @@ struct DebugTextureVertex { } impl DebugTextureVertex { - fn new(position: Point2DI, tex_coord: Point2DI) -> DebugTextureVertex { + fn new(position: Vector2I, tex_coord: Vector2I) -> DebugTextureVertex { DebugTextureVertex { position_x: position.x() as i16, position_y: position.y() as i16, @@ -687,7 +687,7 @@ struct DebugSolidVertex { } impl DebugSolidVertex { - fn new(position: Point2DI) -> DebugSolidVertex { + fn new(position: Vector2I) -> DebugSolidVertex { DebugSolidVertex { position_x: position.x() as i16, position_y: position.y() as i16 } } } @@ -704,8 +704,8 @@ impl CornerRects { let size = device.texture_size(texture); CornerRects { 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), + upper_right: RectI::new(rect.upper_right() - Vector2I::new(size.x(), 0), size), + lower_left: RectI::new(rect.lower_left() - Vector2I::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: RectI) -> 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: RectI) -> 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: Point2DI, - pub relative: Point2DI, + pub absolute: Vector2I, + pub relative: Vector2I, } #[derive(Deserialize)]