Rename `Point2DF` to `Vector2F`, `Point3DF` to `Vector4F`, and `LineSegmentF`

to `LineSegment2F`.

Straw poll on Twitter suggested that these names were preferred.
This commit is contained in:
Patrick Walton 2019-06-03 12:39:29 -07:00
parent 678b6f12c7
commit a1b0df0a42
41 changed files with 661 additions and 661 deletions

View File

@ -55,20 +55,20 @@ struct PFColorF {
float r, g, b, a; float r, g, b, a;
}; };
typedef struct PFColorF PFColorF; typedef struct PFColorF PFColorF;
struct PFPoint2DF { struct PFVector2F {
float x, y; float x, y;
}; };
typedef struct PFPoint2DF PFPoint2DF; typedef struct PFVector2F PFVector2F;
struct PFPoint2DI { struct PFVector2I {
int32_t x, y; int32_t x, y;
}; };
typedef struct PFPoint2DI PFPoint2DI; typedef struct PFVector2I PFVector2I;
struct PFRectF { struct PFRectF {
PFPoint2DF origin, lower_right; PFVector2F origin, lower_right;
}; };
typedef struct PFRectF PFRectF; typedef struct PFRectF PFRectF;
struct PFRectI { struct PFRectI {
PFPoint2DI origin, lower_right; PFVector2I origin, lower_right;
}; };
typedef struct PFRectI PFRectI; typedef struct PFRectI PFRectI;
@ -112,7 +112,7 @@ typedef struct PFSceneProxy *PFSceneProxyRef;
// `canvas` // `canvas`
PFCanvasRef PFCanvasCreate(PFCanvasFontContextRef font_context, const PFPoint2DF *size); PFCanvasRef PFCanvasCreate(PFCanvasFontContextRef font_context, const PFVector2F *size);
void PFCanvasDestroy(PFCanvasRef canvas); void PFCanvasDestroy(PFCanvasRef canvas);
PFCanvasFontContextRef PFCanvasFontContextCreate(); PFCanvasFontContextRef PFCanvasFontContextCreate();
void PFCanvasFontContextDestroy(PFCanvasFontContextRef font_context); void PFCanvasFontContextDestroy(PFCanvasFontContextRef font_context);
@ -126,18 +126,18 @@ void PFCanvasStrokePath(PFCanvasRef canvas, PFPathRef path);
PFPathRef PFPathCreate(); PFPathRef PFPathCreate();
void PFPathDestroy(PFPathRef path); void PFPathDestroy(PFPathRef path);
PFPathRef PFPathClone(PFPathRef path); PFPathRef PFPathClone(PFPathRef path);
void PFPathMoveTo(PFPathRef path, const PFPoint2DF *to); void PFPathMoveTo(PFPathRef path, const PFVector2F *to);
void PFPathLineTo(PFPathRef path, const PFPoint2DF *to); void PFPathLineTo(PFPathRef path, const PFVector2F *to);
void PFPathQuadraticCurveTo(PFPathRef path, const PFPoint2DF *ctrl, const PFPoint2DF *to); void PFPathQuadraticCurveTo(PFPathRef path, const PFVector2F *ctrl, const PFVector2F *to);
void PFPathBezierCurveTo(PFPathRef path, void PFPathBezierCurveTo(PFPathRef path,
const PFPoint2DF *ctrl0, const PFVector2F *ctrl0,
const PFPoint2DF *ctrl1, const PFVector2F *ctrl1,
const PFPoint2DF *to); const PFVector2F *to);
void PFPathClosePath(PFPathRef path); void PFPathClosePath(PFPathRef path);
// `gl` // `gl`
PFGLDestFramebufferRef PFGLDestFramebufferCreateFullWindow(const PFPoint2DI *window_size); PFGLDestFramebufferRef PFGLDestFramebufferCreateFullWindow(const PFVector2I *window_size);
void PFGLDestFramebufferDestroy(PFGLDestFramebufferRef dest_framebuffer); void PFGLDestFramebufferDestroy(PFGLDestFramebufferRef dest_framebuffer);
PFGLDeviceRef PFGLDeviceCreate(PFGLVersion version, uint32_t default_framebuffer); PFGLDeviceRef PFGLDeviceCreate(PFGLVersion version, uint32_t default_framebuffer);
void PFGLDeviceDestroy(PFGLDeviceRef device); void PFGLDeviceDestroy(PFGLDeviceRef device);

View File

@ -12,7 +12,7 @@
use gl; use gl;
use pathfinder_canvas::{CanvasFontContext, CanvasRenderingContext2D, Path2D}; 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::basic::rect::{RectF, RectI};
use pathfinder_geometry::color::ColorF; use pathfinder_geometry::color::ColorF;
use pathfinder_geometry::stroke::LineCap; use pathfinder_geometry::stroke::LineCap;
@ -49,24 +49,24 @@ pub type PFLineCap = u8;
// `geometry` // `geometry`
#[repr(C)] #[repr(C)]
pub struct PFPoint2DF { pub struct PFVector2F {
pub x: f32, pub x: f32,
pub y: f32, pub y: f32,
} }
#[repr(C)] #[repr(C)]
pub struct PFPoint2DI { pub struct PFVector2I {
pub x: i32, pub x: i32,
pub y: i32, pub y: i32,
} }
#[repr(C)] #[repr(C)]
pub struct PFRectF { pub struct PFRectF {
pub origin: PFPoint2DF, pub origin: PFVector2F,
pub lower_right: PFPoint2DF, pub lower_right: PFVector2F,
} }
#[repr(C)] #[repr(C)]
pub struct PFRectI { pub struct PFRectI {
pub origin: PFPoint2DI, pub origin: PFVector2I,
pub lower_right: PFPoint2DI, pub lower_right: PFVector2I,
} }
#[repr(C)] #[repr(C)]
pub struct PFColorF { pub struct PFColorF {
@ -110,7 +110,7 @@ pub struct PFRenderOptions {
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn PFCanvasCreate(font_context: PFCanvasFontContextRef, pub unsafe extern "C" fn PFCanvasCreate(font_context: PFCanvasFontContextRef,
size: *const PFPoint2DF) size: *const PFVector2F)
-> PFCanvasRef { -> PFCanvasRef {
Box::into_raw(Box::new(CanvasRenderingContext2D::new(*Box::from_raw(font_context), Box::into_raw(Box::new(CanvasRenderingContext2D::new(*Box::from_raw(font_context),
(*size).to_rust()))) (*size).to_rust())))
@ -189,27 +189,27 @@ pub unsafe extern "C" fn PFPathClone(path: PFPathRef) -> PFPathRef {
} }
#[no_mangle] #[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()) (*path).move_to((*to).to_rust())
} }
#[no_mangle] #[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()) (*path).line_to((*to).to_rust())
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn PFPathQuadraticCurveTo(path: PFPathRef, pub unsafe extern "C" fn PFPathQuadraticCurveTo(path: PFPathRef,
ctrl: *const PFPoint2DF, ctrl: *const PFVector2F,
to: *const PFPoint2DF) { to: *const PFVector2F) {
(*path).quadratic_curve_to((*ctrl).to_rust(), (*to).to_rust()) (*path).quadratic_curve_to((*ctrl).to_rust(), (*to).to_rust())
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn PFPathBezierCurveTo(path: PFPathRef, pub unsafe extern "C" fn PFPathBezierCurveTo(path: PFPathRef,
ctrl0: *const PFPoint2DF, ctrl0: *const PFVector2F,
ctrl1: *const PFPoint2DF, ctrl1: *const PFVector2F,
to: *const PFPoint2DF) { to: *const PFVector2F) {
(*path).bezier_curve_to((*ctrl0).to_rust(), (*ctrl1).to_rust(), (*to).to_rust()) (*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` // `gpu`
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn PFGLDestFramebufferCreateFullWindow(window_size: *const PFPoint2DI) pub unsafe extern "C" fn PFGLDestFramebufferCreateFullWindow(window_size: *const PFVector2I)
-> PFGLDestFramebufferRef { -> PFGLDestFramebufferRef {
Box::into_raw(Box::new(DestFramebuffer::full_window((*window_size).to_rust()))) Box::into_raw(Box::new(DestFramebuffer::full_window((*window_size).to_rust())))
} }
@ -337,17 +337,17 @@ impl PFRectI {
} }
} }
impl PFPoint2DF { impl PFVector2F {
#[inline] #[inline]
pub fn to_rust(&self) -> Point2DF { pub fn to_rust(&self) -> Vector2F {
Point2DF::new(self.x, self.y) Vector2F::new(self.x, self.y)
} }
} }
impl PFPoint2DI { impl PFVector2I {
#[inline] #[inline]
pub fn to_rust(&self) -> Point2DI { pub fn to_rust(&self) -> Vector2I {
Point2DI::new(self.x, self.y) Vector2I::new(self.x, self.y)
} }
} }

View File

@ -14,8 +14,8 @@ use font_kit::family_name::FamilyName;
use font_kit::hinting::HintingOptions; use font_kit::hinting::HintingOptions;
use font_kit::properties::Properties; use font_kit::properties::Properties;
use font_kit::source::SystemSource; use font_kit::source::SystemSource;
use pathfinder_geometry::basic::line_segment::LineSegmentF; use pathfinder_geometry::basic::line_segment::LineSegment2F;
use pathfinder_geometry::basic::point::Point2DF; use pathfinder_geometry::basic::vector::Vector2F;
use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::basic::rect::RectF;
use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::basic::transform2d::Transform2DF;
use pathfinder_geometry::color::ColorU; use pathfinder_geometry::color::ColorU;
@ -44,9 +44,9 @@ pub struct CanvasRenderingContext2D {
impl CanvasRenderingContext2D { impl CanvasRenderingContext2D {
#[inline] #[inline]
pub fn new(font_context: CanvasFontContext, size: Point2DF) -> CanvasRenderingContext2D { pub fn new(font_context: CanvasFontContext, size: Vector2F) -> CanvasRenderingContext2D {
let mut scene = Scene::new(); 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) CanvasRenderingContext2D::from_scene(font_context, scene)
} }
@ -82,12 +82,12 @@ impl CanvasRenderingContext2D {
// Drawing text // 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); let paint_id = self.scene.push_paint(&self.current_state.fill_paint);
self.fill_or_stroke_text(string, position, paint_id, TextRenderMode::Fill); 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 paint_id = self.scene.push_paint(&self.current_state.stroke_paint);
let render_mode = TextRenderMode::Stroke(self.current_state.resolve_stroke_style()); let render_mode = TextRenderMode::Stroke(self.current_state.resolve_stroke_style());
self.fill_or_stroke_text(string, position, paint_id, render_mode); self.fill_or_stroke_text(string, position, paint_id, render_mode);
@ -99,7 +99,7 @@ impl CanvasRenderingContext2D {
fn fill_or_stroke_text(&mut self, fn fill_or_stroke_text(&mut self,
string: &str, string: &str,
mut position: Point2DF, mut position: Vector2F,
paint_id: PaintId, paint_id: PaintId,
render_mode: TextRenderMode) { render_mode: TextRenderMode) {
let layout = self.layout_text(string); let layout = self.layout_text(string);
@ -314,41 +314,41 @@ impl Path2D {
} }
#[inline] #[inline]
pub fn move_to(&mut self, to: Point2DF) { pub fn move_to(&mut self, to: Vector2F) {
// TODO(pcwalton): Cull degenerate contours. // TODO(pcwalton): Cull degenerate contours.
self.flush_current_contour(); self.flush_current_contour();
self.current_contour.push_endpoint(to); self.current_contour.push_endpoint(to);
} }
#[inline] #[inline]
pub fn line_to(&mut self, to: Point2DF) { pub fn line_to(&mut self, to: Vector2F) {
self.current_contour.push_endpoint(to); self.current_contour.push_endpoint(to);
} }
#[inline] #[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); self.current_contour.push_quadratic(ctrl, to);
} }
#[inline] #[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); self.current_contour.push_cubic(ctrl0, ctrl1, to);
} }
#[inline] #[inline]
pub fn arc(&mut self, pub fn arc(&mut self,
center: Point2DF, center: Vector2F,
radius: f32, radius: f32,
start_angle: f32, start_angle: f32,
end_angle: f32, end_angle: f32,
direction: ArcDirection) { 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)); transform = transform.post_mul(&Transform2DF::from_translation(center));
self.current_contour.push_arc(&transform, start_angle, end_angle, direction); self.current_contour.push_arc(&transform, start_angle, end_angle, direction);
} }
#[inline] #[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? // FIXME(pcwalton): What should we do if there's no initial point?
let from = self.current_contour.last_position().unwrap_or_default(); let from = self.current_contour.last_position().unwrap_or_default();
let (v0, v1) = (from - ctrl, to - ctrl); let (v0, v1) = (from - ctrl, to - ctrl);
@ -357,11 +357,11 @@ impl Path2D {
let bisector = vu0 + vu1; let bisector = vu0 + vu1;
let center = ctrl + bisector.scale(hypot / bisector.length()); 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)); transform = transform.post_mul(&Transform2DF::from_translation(center));
let chord = LineSegmentF::new(vu0.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(Point2DF::new(1.0, -1.0))); vu1.yx().scale_xy(Vector2F::new(1.0, -1.0)));
// FIXME(pcwalton): Is clockwise direction correct? // FIXME(pcwalton): Is clockwise direction correct?
self.current_contour.push_arc_from_unit_chord(&transform, chord, ArcDirection::CW); self.current_contour.push_arc_from_unit_chord(&transform, chord, ArcDirection::CW);
@ -377,8 +377,8 @@ impl Path2D {
} }
pub fn ellipse(&mut self, pub fn ellipse(&mut self,
center: Point2DF, center: Vector2F,
axes: Point2DF, axes: Vector2F,
rotation: f32, rotation: f32,
start_angle: f32, start_angle: f32,
end_angle: f32) { end_angle: f32) {

View File

@ -16,7 +16,7 @@ use jni::{JNIEnv, JavaVM};
use pathfinder_demo::window::{Event, SVGPath, View, Window, WindowSize}; use pathfinder_demo::window::{Event, SVGPath, View, Window, WindowSize};
use pathfinder_demo::DemoApp; use pathfinder_demo::DemoApp;
use pathfinder_demo::Options; use pathfinder_demo::Options;
use pathfinder_geometry::basic::point::Point2DI; use pathfinder_geometry::basic::vector::Vector2I;
use pathfinder_geometry::basic::rect::RectI; use pathfinder_geometry::basic::rect::RectI;
use pathfinder_gl::GLVersion; use pathfinder_gl::GLVersion;
use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::resources::ResourceLoader;
@ -48,7 +48,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder
width: i32, width: i32,
height: i32, height: i32,
) { ) {
let logical_size = Point2DI::new(width, height); let logical_size = Vector2I::new(width, height);
let window_size = WindowSize { let window_size = WindowSize {
logical_size, logical_size,
backing_scale_factor: 1.0, backing_scale_factor: 1.0,
@ -119,7 +119,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder
.lock() .lock()
.unwrap() .unwrap()
.push(Event::WindowResized(WindowSize { .push(Event::WindowResized(WindowSize {
logical_size: Point2DI::new(width, height), logical_size: Vector2I::new(width, height),
backing_scale_factor: 1.0, backing_scale_factor: 1.0,
})) }))
} }
@ -134,7 +134,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder
EVENT_QUEUE EVENT_QUEUE
.lock() .lock()
.unwrap() .unwrap()
.push(Event::MouseDown(Point2DI::new(x, y))) .push(Event::MouseDown(Vector2I::new(x, y)))
} }
#[no_mangle] #[no_mangle]
@ -147,7 +147,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder
EVENT_QUEUE EVENT_QUEUE
.lock() .lock()
.unwrap() .unwrap()
.push(Event::MouseDragged(Point2DI::new(x, y))) .push(Event::MouseDragged(Vector2I::new(x, y)))
} }
#[no_mangle] #[no_mangle]
@ -161,7 +161,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder
EVENT_QUEUE EVENT_QUEUE
.lock() .lock()
.unwrap() .unwrap()
.push(Event::Zoom(factor, Point2DI::new(center_x, center_y))) .push(Event::Zoom(factor, Vector2I::new(center_x, center_y)))
} }
#[no_mangle] #[no_mangle]
@ -188,7 +188,7 @@ pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_Pathfinder
} }
struct WindowImpl { struct WindowImpl {
size: Point2DI, size: Vector2I,
} }
impl Window for WindowImpl { impl Window for WindowImpl {
@ -204,8 +204,8 @@ impl Window for WindowImpl {
width = width / 2; width = width / 2;
offset_x = (index as i32) * width; offset_x = (index as i32) * width;
} }
let size = Point2DI::new(width, height); let size = Vector2I::new(width, height);
let offset = Point2DI::new(offset_x, 0); let offset = Vector2I::new(offset_x, 0);
RectI::new(offset, size) RectI::new(offset, size)
} }

View File

@ -14,7 +14,7 @@
// proper. // proper.
use crate::window::{OcularTransform, View}; 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::rect::RectF;
use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::basic::transform2d::Transform2DF;
use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF}; use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF};
@ -39,12 +39,12 @@ pub enum Camera {
// The modelview transform from world coordinates to SVG coordinates // The modelview transform from world coordinates to SVG coordinates
modelview_transform: CameraTransform3D, modelview_transform: CameraTransform3D,
// The camera's velocity (in world coordinates) // The camera's velocity (in world coordinates)
velocity: Point3DF, velocity: Vector4F,
}, },
} }
impl Camera { 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 { if mode == Mode::TwoD {
Camera::new_2d(view_box, viewport_size) Camera::new_2d(view_box, viewport_size)
} else { } 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 let scale = i32::min(viewport_size.x(), viewport_size.y()) as f32
* scale_factor_for_view_box(view_box); * scale_factor_for_view_box(view_box);
let origin = viewport_size.to_f32().scale(0.5) - view_box.size().scale(scale * 0.5); 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 viewport_count = mode.viewport_count();
let fov_y = FRAC_PI_4; let fov_y = FRAC_PI_4;
@ -96,7 +96,7 @@ impl Camera {
scene_transform, scene_transform,
eye_transforms, eye_transforms,
modelview_transform: CameraTransform3D::new(view_box), modelview_transform: CameraTransform3D::new(view_box),
velocity: Point3DF::default(), velocity: Vector4F::default(),
} }
} }
@ -120,7 +120,7 @@ impl Camera {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct CameraTransform3D { pub struct CameraTransform3D {
position: Point3DF, position: Vector4F,
pub yaw: f32, pub yaw: f32,
pub pitch: f32, pub pitch: f32,
scale: f32, scale: f32,
@ -130,7 +130,7 @@ impl CameraTransform3D {
fn new(view_box: RectF) -> CameraTransform3D { fn new(view_box: RectF) -> CameraTransform3D {
let scale = scale_factor_for_view_box(view_box); let scale = scale_factor_for_view_box(view_box);
CameraTransform3D { CameraTransform3D {
position: Point3DF::new( position: Vector4F::new(
0.5 * view_box.max_x(), 0.5 * view_box.max_x(),
-0.5 * view_box.max_y(), -0.5 * view_box.max_y(),
1.5 / scale, 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(); let update = !vector.is_zero();
if update { if update {
let rotation = Transform3DF::from_rotation(-self.yaw, -self.pitch, 0.0); let rotation = Transform3DF::from_rotation(-self.yaw, -self.pitch, 0.0);

View File

@ -19,7 +19,7 @@ use crate::device::{GroundProgram, GroundVertexArray};
use crate::ui::{DemoUIModel, DemoUIPresenter, ScreenshotInfo, ScreenshotType, UIAction}; use crate::ui::{DemoUIModel, DemoUIPresenter, ScreenshotInfo, ScreenshotType, UIAction};
use crate::window::{Event, Keycode, SVGPath, Window, WindowSize}; use crate::window::{Event, Keycode, SVGPath, Window, WindowSize};
use clap::{App, Arg}; 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::rect::RectF;
use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::basic::transform2d::Transform2DF;
use pathfinder_geometry::color::ColorU; use pathfinder_geometry::color::ColorU;
@ -99,7 +99,7 @@ pub struct DemoApp<W> where W: Window {
pub dirty: bool, pub dirty: bool,
expire_message_event_id: u32, expire_message_event_id: u32,
message_epoch: u32, message_epoch: u32,
last_mouse_position: Point2DI, last_mouse_position: Vector2I,
current_frame: Option<Frame>, current_frame: Option<Frame>,
build_time: Option<Duration>, build_time: Option<Duration>,
@ -181,7 +181,7 @@ impl<W> DemoApp<W> where W: Window {
dirty: true, dirty: true,
expire_message_event_id, expire_message_event_id,
message_epoch, message_epoch,
last_mouse_position: Point2DI::default(), last_mouse_position: Vector2I::default(),
current_frame: None, current_frame: None,
build_time: None, build_time: None,
@ -244,9 +244,9 @@ impl<W> DemoApp<W> where W: Window {
dilation: if self.ui_model.stem_darkening_effect_enabled { dilation: if self.ui_model.stem_darkening_effect_enabled {
let font_size = APPROX_FONT_SIZE * self.window_size.backing_scale_factor; let font_size = APPROX_FONT_SIZE * self.window_size.backing_scale_factor;
let (x, y) = (STEM_DARKENING_FACTORS[0], STEM_DARKENING_FACTORS[1]); 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 { } else {
Point2DF::default() Vector2F::default()
}, },
subpixel_aa_enabled: self.ui_model.subpixel_aa_effect_enabled, subpixel_aa_enabled: self.ui_model.subpixel_aa_effect_enabled,
}; };
@ -267,7 +267,7 @@ impl<W> DemoApp<W> where W: Window {
Event::WindowResized(new_size) => { Event::WindowResized(new_size) => {
self.window_size = new_size; self.window_size = new_size;
let viewport = self.window.viewport(self.ui_model.mode.view(0)); 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())); viewport.size().to_f32()));
self.renderer self.renderer
.set_main_framebuffer_size(self.window_size.device_size()); .set_main_framebuffer_size(self.window_size.device_size());
@ -304,7 +304,7 @@ impl<W> DemoApp<W> where W: Window {
let position = position.to_f32().scale(backing_scale_factor); let position = position.to_f32().scale(backing_scale_factor);
*transform = transform.post_translate(-position); *transform = transform.post_translate(-position);
let scale_delta = 1.0 + d_dist * CAMERA_SCALE_SPEED_2D; 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); *transform = transform.post_translate(position);
} }
} }
@ -431,7 +431,7 @@ impl<W> DemoApp<W> where W: Window {
ui_events 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 absolute = new_position.scale(self.window_size.backing_scale_factor as i32);
let relative = absolute - self.last_mouse_position; let relative = absolute - self.last_mouse_position;
self.last_mouse_position = absolute; self.last_mouse_position = absolute;
@ -557,7 +557,7 @@ impl<W> DemoApp<W> where W: Window {
} }
UIAction::ZoomIn => { UIAction::ZoomIn => {
if let Camera::TwoD(ref mut transform) = self.camera { 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); let center = center_of_window(&self.window_size);
*transform = transform *transform = transform
.post_translate(-center) .post_translate(-center)
@ -568,7 +568,7 @@ impl<W> DemoApp<W> where W: Window {
} }
UIAction::ZoomOut => { UIAction::ZoomOut => {
if let Camera::TwoD(ref mut transform) = self.camera { 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); let center = center_of_window(&self.window_size);
*transform = transform *transform = transform
.post_translate(-center) .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()) 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) window_size.device_size().to_f32().scale(0.5)
} }
@ -807,10 +807,10 @@ struct SceneMetadata {
impl SceneMetadata { impl SceneMetadata {
// FIXME(pcwalton): The fact that this mutates the scene is really ugly! // FIXME(pcwalton): The fact that this mutates the scene is really ugly!
// Can we simplify this? // 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 view_box = scene.view_box();
let monochrome_color = scene.monochrome_color(); 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 } SceneMetadata { view_box, monochrome_color }
} }
} }

View File

@ -11,7 +11,7 @@
use crate::camera::Mode; use crate::camera::Mode;
use crate::window::Window; use crate::window::Window;
use crate::{BackgroundColor, Options}; use crate::{BackgroundColor, Options};
use pathfinder_geometry::basic::point::Point2DI; use pathfinder_geometry::basic::vector::Vector2I;
use pathfinder_geometry::basic::rect::RectI; use pathfinder_geometry::basic::rect::RectI;
use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::resources::ResourceLoader;
use pathfinder_gpu::Device; use pathfinder_gpu::Device;
@ -152,9 +152,9 @@ where
// Draw button strip. // Draw button strip.
let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING; 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. // Draw text effects button.
if self.show_text_effects { if self.show_text_effects {
@ -170,7 +170,7 @@ where
RectI::new(position, button_size), RectI::new(position, button_size),
); );
} }
position += Point2DI::new(button_size.x() + PADDING, 0); position += Vector2I::new(button_size.x() + PADDING, 0);
} }
// Draw open button. // Draw open button.
@ -182,7 +182,7 @@ where
debug_ui_presenter.ui_presenter.draw_tooltip(device, debug_ui_presenter.ui_presenter.draw_tooltip(device,
"Open SVG", "Open SVG",
RectI::new(position, button_size)); RectI::new(position, button_size));
position += Point2DI::new(BUTTON_WIDTH + PADDING, 0); position += Vector2I::new(BUTTON_WIDTH + PADDING, 0);
// Draw screenshot button. // Draw screenshot button.
if debug_ui_presenter.ui_presenter.draw_button(device, if debug_ui_presenter.ui_presenter.draw_button(device,
@ -200,7 +200,7 @@ where
// Draw screenshot panel, if necessary. // Draw screenshot panel, if necessary.
self.draw_screenshot_panel(device, window, debug_ui_presenter, position.x(), action); 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. // Draw mode switch.
let new_mode = debug_ui_presenter.ui_presenter.draw_text_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_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( debug_ui_presenter.ui_presenter.draw_tooltip(
device, device,
"2D/3D/VR Mode", "2D/3D/VR Mode",
RectI::new(position, mode_switch_size), 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. // Draw background switch.
if debug_ui_presenter.ui_presenter.draw_button(device, if debug_ui_presenter.ui_presenter.draw_button(device,
@ -242,7 +242,7 @@ where
// Draw background panel, if necessary. // Draw background panel, if necessary.
self.draw_background_panel(device, debug_ui_presenter, position.x(), action, model); 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. // Draw effects panel, if necessary.
self.draw_effects_panel(device, debug_ui_presenter, model); self.draw_effects_panel(device, debug_ui_presenter, model);
@ -261,7 +261,7 @@ where
RectI::new(position, button_size)); RectI::new(position, button_size));
} }
self.draw_rotate_panel(device, debug_ui_presenter, position.x(), action, model); 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. // Draw zoom control.
self.draw_zoom_control(device, debug_ui_presenter, position, action); self.draw_zoom_control(device, debug_ui_presenter, position, action);
@ -271,13 +271,13 @@ where
&mut self, &mut self,
device: &D, device: &D,
debug_ui_presenter: &mut DebugUIPresenter<D>, debug_ui_presenter: &mut DebugUIPresenter<D>,
position: Point2DI, position: Vector2I,
action: &mut UIAction, action: &mut UIAction,
) { ) {
let zoom_segmented_control_width = let zoom_segmented_control_width =
debug_ui_presenter.ui_presenter.measure_segmented_control(3); debug_ui_presenter.ui_presenter.measure_segmented_control(3);
let zoom_segmented_control_rect = 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); debug_ui_presenter.ui_presenter.draw_tooltip(device, "Zoom", zoom_segmented_control_rect);
let zoom_textures = &[ let zoom_textures = &[
@ -306,8 +306,8 @@ where
} }
let message_size = debug_ui_presenter.ui_presenter.measure_text(&model.message); let message_size = debug_ui_presenter.ui_presenter.measure_text(&model.message);
let window_origin = Point2DI::new(PADDING, PADDING); let window_origin = Vector2I::new(PADDING, PADDING);
let window_size = Point2DI::new(PADDING * 2 + message_size, TOOLTIP_HEIGHT); let window_size = Vector2I::new(PADDING * 2 + message_size, TOOLTIP_HEIGHT);
debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( debug_ui_presenter.ui_presenter.draw_solid_rounded_rect(
device, device,
RectI::new(window_origin, window_size), RectI::new(window_origin, window_size),
@ -316,7 +316,7 @@ where
debug_ui_presenter.ui_presenter.draw_text( debug_ui_presenter.ui_presenter.draw_text(
device, device,
&model.message, &model.message,
window_origin + Point2DI::new(PADDING, PADDING + FONT_ASCENT), window_origin + Vector2I::new(PADDING, PADDING + FONT_ASCENT),
false, false,
); );
} }
@ -334,8 +334,8 @@ where
debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( debug_ui_presenter.ui_presenter.draw_solid_rounded_rect(
device, device,
RectI::new( RectI::new(
Point2DI::new(PADDING, effects_panel_y), Vector2I::new(PADDING, effects_panel_y),
Point2DI::new(EFFECTS_PANEL_WIDTH, EFFECTS_PANEL_HEIGHT), Vector2I::new(EFFECTS_PANEL_WIDTH, EFFECTS_PANEL_HEIGHT),
), ),
WINDOW_COLOR, WINDOW_COLOR,
); );
@ -380,12 +380,12 @@ where
let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING; let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING;
let panel_y = bottom - (BUTTON_HEIGHT + PADDING + SCREENSHOT_PANEL_HEIGHT); 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( debug_ui_presenter.ui_presenter.draw_solid_rounded_rect(
device, device,
RectI::new( RectI::new(
panel_position, panel_position,
Point2DI::new(SCREENSHOT_PANEL_WIDTH, SCREENSHOT_PANEL_HEIGHT), Vector2I::new(SCREENSHOT_PANEL_WIDTH, SCREENSHOT_PANEL_HEIGHT),
), ),
WINDOW_COLOR, WINDOW_COLOR,
); );
@ -422,12 +422,12 @@ where
let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING; let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING;
let panel_y = bottom - (BUTTON_HEIGHT + PADDING + BACKGROUND_PANEL_HEIGHT); 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( debug_ui_presenter.ui_presenter.draw_solid_rounded_rect(
device, device,
RectI::new( RectI::new(
panel_position, panel_position,
Point2DI::new(BACKGROUND_PANEL_WIDTH, BACKGROUND_PANEL_HEIGHT), Vector2I::new(BACKGROUND_PANEL_WIDTH, BACKGROUND_PANEL_HEIGHT),
), ),
WINDOW_COLOR, WINDOW_COLOR,
); );
@ -472,8 +472,8 @@ where
let bottom = debug_ui_presenter.ui_presenter.framebuffer_size().y() - PADDING; 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_y = bottom - (BUTTON_HEIGHT + PADDING + ROTATE_PANEL_HEIGHT);
let rotate_panel_origin = Point2DI::new(rotate_panel_x, rotate_panel_y); let rotate_panel_origin = Vector2I::new(rotate_panel_x, rotate_panel_y);
let rotate_panel_size = Point2DI::new(ROTATE_PANEL_WIDTH, ROTATE_PANEL_HEIGHT); let rotate_panel_size = Vector2I::new(ROTATE_PANEL_WIDTH, ROTATE_PANEL_HEIGHT);
debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( debug_ui_presenter.ui_presenter.draw_solid_rounded_rect(
device, device,
RectI::new(rotate_panel_origin, rotate_panel_size), 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_x, widget_y) = (rotate_panel_x + PADDING, rotate_panel_y + PADDING);
let widget_rect = RectI::new( let widget_rect = RectI::new(
Point2DI::new(widget_x, widget_y), Vector2I::new(widget_x, widget_y),
Point2DI::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT), Vector2I::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT),
); );
if let Some(position) = debug_ui_presenter if let Some(position) = debug_ui_presenter
.ui_presenter .ui_presenter
@ -497,8 +497,8 @@ where
let slider_track_y = let slider_track_y =
rotate_panel_y + PADDING + SLIDER_KNOB_HEIGHT / 2 - SLIDER_TRACK_HEIGHT / 2; rotate_panel_y + PADDING + SLIDER_KNOB_HEIGHT / 2 - SLIDER_TRACK_HEIGHT / 2;
let slider_track_rect = RectI::new( let slider_track_rect = RectI::new(
Point2DI::new(widget_x, slider_track_y), Vector2I::new(widget_x, slider_track_y),
Point2DI::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT), Vector2I::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT),
); );
debug_ui_presenter debug_ui_presenter
.ui_presenter .ui_presenter
@ -506,8 +506,8 @@ where
let slider_knob_x = widget_x + model.rotation - SLIDER_KNOB_WIDTH / 2; let slider_knob_x = widget_x + model.rotation - SLIDER_KNOB_WIDTH / 2;
let slider_knob_rect = RectI::new( let slider_knob_rect = RectI::new(
Point2DI::new(slider_knob_x, widget_y), Vector2I::new(slider_knob_x, widget_y),
Point2DI::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT), Vector2I::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT),
); );
debug_ui_presenter.ui_presenter.draw_solid_rect(device, slider_knob_rect, TEXT_COLOR); debug_ui_presenter.ui_presenter.draw_solid_rect(device, slider_knob_rect, TEXT_COLOR);
} }
@ -518,14 +518,14 @@ where
window: &mut W, window: &mut W,
debug_ui_presenter: &mut DebugUIPresenter<D>, debug_ui_presenter: &mut DebugUIPresenter<D>,
screenshot_type: ScreenshotType, screenshot_type: ScreenshotType,
panel_position: Point2DI, panel_position: Vector2I,
action: &mut UIAction, action: &mut UIAction,
) where W: Window { ) where W: Window {
let index = screenshot_type as i32; let index = screenshot_type as i32;
let text = format!("Save as {}...", screenshot_type.as_str()); let text = format!("Save as {}...", screenshot_type.as_str());
let widget_size = Point2DI::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); let widget_size = Vector2I::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT);
let widget_origin = panel_position + Point2DI::new(0, widget_size.y() * index); let widget_origin = panel_position + Vector2I::new(0, widget_size.y() * index);
let widget_rect = RectI::new(widget_origin, widget_size); let widget_rect = RectI::new(widget_origin, widget_size);
if self.draw_menu_item(device, debug_ui_presenter, &text, widget_rect, false) { if self.draw_menu_item(device, debug_ui_presenter, &text, widget_rect, false) {
@ -543,14 +543,14 @@ where
device: &D, device: &D,
debug_ui_presenter: &mut DebugUIPresenter<D>, debug_ui_presenter: &mut DebugUIPresenter<D>,
color: BackgroundColor, color: BackgroundColor,
panel_position: Point2DI, panel_position: Vector2I,
action: &mut UIAction, action: &mut UIAction,
model: &mut DemoUIModel, model: &mut DemoUIModel,
) { ) {
let (text, index) = (color.as_str(), color as i32); let (text, index) = (color.as_str(), color as i32);
let widget_size = Point2DI::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); let widget_size = Vector2I::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT);
let widget_origin = panel_position + Point2DI::new(0, widget_size.y() * index); let widget_origin = panel_position + Vector2I::new(0, widget_size.y() * index);
let widget_rect = RectI::new(widget_origin, widget_size); let widget_rect = RectI::new(widget_origin, widget_size);
let selected = color == model.background_color; let selected = color == model.background_color;
@ -574,7 +574,7 @@ where
} }
let (text_x, text_y) = (PADDING * 2, BUTTON_TEXT_OFFSET); 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.draw_text(device, text, text_position, selected);
debug_ui_presenter.ui_presenter debug_ui_presenter.ui_presenter
@ -596,12 +596,12 @@ where
let text_y = window_y + PADDING + BUTTON_TEXT_OFFSET + (BUTTON_HEIGHT + PADDING) * index; let text_y = window_y + PADDING + BUTTON_TEXT_OFFSET + (BUTTON_HEIGHT + PADDING) * index;
debug_ui_presenter debug_ui_presenter
.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_width = debug_ui_presenter.ui_presenter.measure_segmented_control(2);
let switch_x = PADDING + EFFECTS_PANEL_WIDTH - (switch_width + PADDING); let switch_x = PADDING + EFFECTS_PANEL_WIDTH - (switch_width + PADDING);
let switch_y = window_y + PADDING + (BUTTON_HEIGHT + PADDING) * index; 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 debug_ui_presenter
.ui_presenter .ui_presenter
.draw_text_switch(device, switch_position, &["Off", "On"], value as u8) .draw_text_switch(device, switch_position, &["Off", "On"], value as u8)

View File

@ -11,7 +11,7 @@
//! A minimal cross-platform windowing layer. //! A minimal cross-platform windowing layer.
use gl::types::GLuint; 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::rect::RectI;
use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF}; use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF};
use pathfinder_gl::GLVersion; use pathfinder_gl::GLVersion;
@ -42,10 +42,10 @@ pub enum Event {
WindowResized(WindowSize), WindowResized(WindowSize),
KeyDown(Keycode), KeyDown(Keycode),
KeyUp(Keycode), KeyUp(Keycode),
MouseDown(Point2DI), MouseDown(Vector2I),
MouseMoved(Point2DI), MouseMoved(Vector2I),
MouseDragged(Point2DI), MouseDragged(Vector2I),
Zoom(f32, Point2DI), Zoom(f32, Vector2I),
Look { Look {
pitch: f32, pitch: f32,
yaw: f32, yaw: f32,
@ -67,13 +67,13 @@ pub enum Keycode {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct WindowSize { pub struct WindowSize {
pub logical_size: Point2DI, pub logical_size: Vector2I,
pub backing_scale_factor: f32, pub backing_scale_factor: f32,
} }
impl WindowSize { impl WindowSize {
#[inline] #[inline]
pub fn device_size(&self) -> Point2DI { pub fn device_size(&self) -> Vector2I {
self.logical_size self.logical_size
.to_f32() .to_f32()
.scale(self.backing_scale_factor) .scale(self.backing_scale_factor)

View File

@ -13,7 +13,7 @@
use nfd::Response; use nfd::Response;
use pathfinder_demo::window::{Event, Keycode, SVGPath, View, Window, WindowSize}; use pathfinder_demo::window::{Event, Keycode, SVGPath, View, Window, WindowSize};
use pathfinder_demo::{DemoApp, Options}; 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_geometry::basic::rect::RectI;
use pathfinder_gl::GLVersion; use pathfinder_gl::GLVersion;
use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader}; use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader};
@ -92,7 +92,7 @@ impl Window for WindowImpl {
width = width / 2; width = width / 2;
x_offset = width * (index as i32); 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) { fn make_current(&mut self, _view: View) {
@ -189,7 +189,7 @@ impl WindowImpl {
let (logical_width, logical_height) = self.window.size(); let (logical_width, logical_height) = self.window.size();
let (drawable_width, _) = self.window.drawable_size(); let (drawable_width, _) = self.window.drawable_size();
WindowSize { 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, backing_scale_factor: drawable_width as f32 / logical_width as f32,
} }
} }
@ -221,11 +221,11 @@ impl WindowImpl {
message_type: type_, message_type: type_,
message_data: code as u32, 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 { SDLEvent::MouseMotion {
x, y, mousestate, .. x, y, mousestate, ..
} => { } => {
let position = Point2DI::new(x, y); let position = Vector2I::new(x, y);
if mousestate.left() { if mousestate.left() {
Some(Event::MouseDragged(position)) Some(Event::MouseDragged(position))
} else { } else {
@ -247,7 +247,7 @@ impl WindowImpl {
} => self.convert_sdl_keycode(sdl_keycode).map(Event::KeyUp), } => self.convert_sdl_keycode(sdl_keycode).map(Event::KeyUp),
SDLEvent::MultiGesture { d_dist, .. } => { SDLEvent::MultiGesture { d_dist, .. } => {
let mouse_state = self.event_pump.mouse_state(); 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)) Some(Event::Zoom(d_dist, center))
} }
_ => None, _ => None,

View File

@ -55,7 +55,7 @@ int main(int argc, const char **argv) {
// Create a Pathfinder renderer. // Create a Pathfinder renderer.
PFGLLoadWith(LoadGLFunction, NULL); PFGLLoadWith(LoadGLFunction, NULL);
PFGLDestFramebufferRef dest_framebuffer = PFGLDestFramebufferRef dest_framebuffer =
PFGLDestFramebufferCreateFullWindow(&(PFPoint2DI){640, 480}); PFGLDestFramebufferCreateFullWindow(&(PFVector2I){640, 480});
PFGLRendererRef renderer = PFGLRendererCreate(PFGLDeviceCreate(PF_GL_VERSION_GL3, 0), PFGLRendererRef renderer = PFGLRendererCreate(PFGLDeviceCreate(PF_GL_VERSION_GL3, 0),
PFFilesystemResourceLoaderLocate(), PFFilesystemResourceLoaderLocate(),
dest_framebuffer); dest_framebuffer);
@ -67,7 +67,7 @@ int main(int argc, const char **argv) {
// Make a canvas. We're going to draw a house. // Make a canvas. We're going to draw a house.
PFCanvasRef canvas = PFCanvasCreate(PFCanvasFontContextCreate(), PFCanvasRef canvas = PFCanvasCreate(PFCanvasFontContextCreate(),
&(PFPoint2DF){640.0f, 480.0f}); &(PFVector2F){640.0f, 480.0f});
// Set line width. // Set line width.
PFCanvasSetLineWidth(canvas, 10.0f); PFCanvasSetLineWidth(canvas, 10.0f);
@ -80,9 +80,9 @@ int main(int argc, const char **argv) {
// Draw roof. // Draw roof.
PFPathRef path = PFPathCreate(); PFPathRef path = PFPathCreate();
PFPathMoveTo(path, &(PFPoint2DF){50.0, 140.0}); PFPathMoveTo(path, &(PFVector2F){50.0, 140.0});
PFPathLineTo(path, &(PFPoint2DF){150.0, 60.0}); PFPathLineTo(path, &(PFVector2F){150.0, 60.0});
PFPathLineTo(path, &(PFPoint2DF){250.0, 140.0}); PFPathLineTo(path, &(PFVector2F){250.0, 140.0});
PFPathClosePath(path); PFPathClosePath(path);
PFCanvasStrokePath(canvas, path); PFCanvasStrokePath(canvas, path);

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
use pathfinder_canvas::{CanvasFontContext, CanvasRenderingContext2D, Path2D}; 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::basic::rect::RectF;
use pathfinder_geometry::color::ColorF; use pathfinder_geometry::color::ColorF;
use pathfinder_gl::{GLDevice, GLVersion}; use pathfinder_gl::{GLDevice, GLVersion};
@ -34,7 +34,7 @@ fn main() {
gl_attributes.set_context_version(3, 3); gl_attributes.set_context_version(3, 3);
// Open a window. // 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) let window = video.window("Minimal example", window_size.x() as u32, window_size.y() as u32)
.opengl() .opengl()
.build() .build()
@ -60,16 +60,16 @@ fn main() {
canvas.set_line_width(10.0); canvas.set_line_width(10.0);
// Draw walls. // 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. // 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. // Draw roof.
let mut path = Path2D::new(); let mut path = Path2D::new();
path.move_to(Point2DF::new(50.0, 140.0)); path.move_to(Vector2F::new(50.0, 140.0));
path.line_to(Point2DF::new(150.0, 60.0)); path.line_to(Vector2F::new(150.0, 60.0));
path.line_to(Point2DF::new(250.0, 140.0)); path.line_to(Vector2F::new(250.0, 140.0));
path.close_path(); path.close_path();
canvas.stroke_path(path); canvas.stroke_path(path);

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
use pathfinder_canvas::{CanvasFontContext, CanvasRenderingContext2D, FillStyle, Path2D}; 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_geometry::color::{ColorF, ColorU};
use pathfinder_gl::{GLDevice, GLVersion}; use pathfinder_gl::{GLDevice, GLVersion};
use pathfinder_gpu::resources::FilesystemResourceLoader; use pathfinder_gpu::resources::FilesystemResourceLoader;
@ -47,7 +47,7 @@ fn main() {
gl_attributes.set_context_version(3, 3); gl_attributes.set_context_version(3, 3);
// Open a window. // 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) let window = video.window("Moire example", window_size.x() as u32, window_size.y() as u32)
.opengl() .opengl()
.allow_highdpi() .allow_highdpi()
@ -57,7 +57,7 @@ fn main() {
// Get the real window size (for HiDPI). // Get the real window size (for HiDPI).
let (drawable_width, drawable_height) = window.drawable_size(); 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. // Create the GL context, and make it current.
let gl_context = window.gl_create_context().unwrap(); let gl_context = window.gl_create_context().unwrap();
@ -88,14 +88,14 @@ struct MoireRenderer {
font_context: CanvasFontContext, font_context: CanvasFontContext,
scene: SceneProxy, scene: SceneProxy,
frame: i32, frame: i32,
window_size: Point2DI, window_size: Vector2I,
drawable_size: Point2DI, drawable_size: Vector2I,
device_pixel_ratio: f32, device_pixel_ratio: f32,
colors: ColorGradient, colors: ColorGradient,
} }
impl MoireRenderer { impl MoireRenderer {
fn new(renderer: Renderer<GLDevice>, window_size: Point2DI, drawable_size: Point2DI) fn new(renderer: Renderer<GLDevice>, window_size: Vector2I, drawable_size: Vector2I)
-> MoireRenderer { -> MoireRenderer {
MoireRenderer { MoireRenderer {
renderer, renderer,
@ -119,9 +119,9 @@ impl MoireRenderer {
// Calculate outer and inner circle centers (circle and Leminscate of Gerono respectively). // Calculate outer and inner circle centers (circle and Leminscate of Gerono respectively).
let window_center = self.window_size.to_f32().scale(0.5); 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 + 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. // Clear to background color.
self.renderer.device.clear(&ClearParams { self.renderer.device.clear(&ClearParams {
@ -147,12 +147,12 @@ impl MoireRenderer {
self.frame += 1; 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); let center = center.scale(self.device_pixel_ratio);
for index in 0..CIRCLE_COUNT { for index in 0..CIRCLE_COUNT {
let radius = (index + 1) as f32 * CIRCLE_SPACING * self.device_pixel_ratio; let radius = (index + 1) as f32 * CIRCLE_SPACING * self.device_pixel_ratio;
let mut path = Path2D::new(); 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); canvas.stroke_path(path);
} }
} }

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
use pathfinder_canvas::{CanvasFontContext, CanvasRenderingContext2D, TextAlign}; 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_geometry::color::ColorF;
use pathfinder_gl::{GLDevice, GLVersion}; use pathfinder_gl::{GLDevice, GLVersion};
use pathfinder_gpu::resources::FilesystemResourceLoader; use pathfinder_gpu::resources::FilesystemResourceLoader;
@ -33,7 +33,7 @@ fn main() {
gl_attributes.set_context_version(3, 3); gl_attributes.set_context_version(3, 3);
// Open a window. // 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) let window = video.window("Text example", window_size.x() as u32, window_size.y() as u32)
.opengl() .opengl()
.build() .build()
@ -57,9 +57,9 @@ fn main() {
// Draw the text. // Draw the text.
canvas.set_font_size(32.0); 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.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. // Render the canvas to screen.
let scene = SceneProxy::from_scene(canvas.into_scene(), RayonExecutor); let scene = SceneProxy::from_scene(canvas.into_scene(), RayonExecutor);

View File

@ -10,38 +10,38 @@
//! Line segment types, optimized with SIMD. //! Line segment types, optimized with SIMD.
use crate::basic::point::Point2DF; use crate::basic::vector::Vector2F;
use crate::basic::transform2d::Matrix2x2F; use crate::basic::transform2d::Matrix2x2F;
use crate::util; use crate::util;
use pathfinder_simd::default::F32x4; use pathfinder_simd::default::F32x4;
use std::ops::{Add, Sub}; use std::ops::{Add, Sub};
#[derive(Clone, Copy, Debug, PartialEq, Default)] #[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct LineSegmentF(pub F32x4); pub struct LineSegment2F(pub F32x4);
impl LineSegmentF { impl LineSegment2F {
#[inline] #[inline]
pub fn new(from: Point2DF, to: Point2DF) -> LineSegmentF { pub fn new(from: Vector2F, to: Vector2F) -> LineSegment2F {
LineSegmentF(from.0.concat_xy_xy(to.0)) LineSegment2F(from.0.concat_xy_xy(to.0))
} }
#[inline] #[inline]
pub fn from(&self) -> Point2DF { pub fn from(&self) -> Vector2F {
Point2DF(self.0) Vector2F(self.0)
} }
#[inline] #[inline]
pub fn to(&self) -> Point2DF { pub fn to(&self) -> Vector2F {
Point2DF(self.0.zwxy()) Vector2F(self.0.zwxy())
} }
#[inline] #[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) self.0 = point.0.concat_xy_zw(self.0)
} }
#[inline] #[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) self.0 = self.0.concat_xy_xy(point.0)
} }
@ -88,35 +88,35 @@ impl LineSegmentF {
} }
#[inline] #[inline]
pub fn translate(&self, offset: Point2DF) -> LineSegmentF { pub fn translate(&self, offset: Vector2F) -> LineSegment2F {
LineSegmentF(self.0 + offset.0.xyxy()) LineSegment2F(self.0 + offset.0.xyxy())
} }
#[inline] #[inline]
pub fn scale(&self, factor: f32) -> LineSegmentF { pub fn scale(&self, factor: f32) -> LineSegment2F {
LineSegmentF(self.0 * F32x4::splat(factor)) LineSegment2F(self.0 * F32x4::splat(factor))
} }
#[inline] #[inline]
pub fn scale_xy(&self, factors: Point2DF) -> LineSegmentF { pub fn scale_xy(&self, factors: Vector2F) -> LineSegment2F {
LineSegmentF(self.0 * factors.0.xyxy()) LineSegment2F(self.0 * factors.0.xyxy())
} }
#[inline] #[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); debug_assert!(t >= 0.0 && t <= 1.0);
let (from_from, to_to) = (self.0.xyxy(), self.0.zwzw()); let (from_from, to_to) = (self.0.xyxy(), self.0.zwzw());
let d_d = to_to - from_from; let d_d = to_to - from_from;
let mid_mid = from_from + d_d * F32x4::splat(t); let mid_mid = from_from + d_d * F32x4::splat(t);
( (
LineSegmentF(from_from.concat_xy_xy(mid_mid)), LineSegment2F(from_from.concat_xy_xy(mid_mid)),
LineSegmentF(mid_mid.concat_xy_xy(to_to)), LineSegment2F(mid_mid.concat_xy_xy(to_to)),
) )
} }
// Returns the left segment first, followed by the right segment. // Returns the left segment first, followed by the right segment.
#[inline] #[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)); let (min_part, max_part) = self.split(self.solve_t_for_x(x));
if min_part.from_x() < max_part.from_x() { if min_part.from_x() < max_part.from_x() {
(min_part, max_part) (min_part, max_part)
@ -127,7 +127,7 @@ impl LineSegmentF {
// Returns the upper segment first, followed by the lower segment. // Returns the upper segment first, followed by the lower segment.
#[inline] #[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)); 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 // 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] #[inline]
pub fn reversed(&self) -> LineSegmentF { pub fn reversed(&self) -> LineSegment2F {
LineSegmentF(self.0.zwxy()) LineSegment2F(self.0.zwxy())
} }
#[inline] #[inline]
pub fn upper_point(&self) -> Point2DF { pub fn upper_point(&self) -> Vector2F {
if self.from_y() < self.to_y() { if self.from_y() < self.to_y() {
self.from() self.from()
} else { } else {
@ -205,7 +205,7 @@ impl LineSegmentF {
// Reverses if necessary so that the from point is above the to point. Calling this method // Reverses if necessary so that the from point is above the to point. Calling this method
// again will undo the transformation. // again will undo the transformation.
#[inline] #[inline]
pub fn orient(&self, y_winding: i32) -> LineSegmentF { pub fn orient(&self, y_winding: i32) -> LineSegment2F {
if y_winding >= 0 { if y_winding >= 0 {
*self *self
} else { } else {
@ -232,12 +232,12 @@ impl LineSegmentF {
} }
#[inline] #[inline]
pub fn vector(&self) -> Point2DF { pub fn vector(&self) -> Vector2F {
self.to() - self.from() self.to() - self.from()
} }
// http://www.cs.swan.ac.uk/~cssimon/line_intersection.html // http://www.cs.swan.ac.uk/~cssimon/line_intersection.html
pub fn intersection_t(&self, other: &LineSegmentF) -> Option<f32> { pub fn intersection_t(&self, other: &LineSegment2F) -> Option<f32> {
let p0p1 = self.vector(); let p0p1 = self.vector();
let matrix = Matrix2x2F(other.vector().0.concat_xy_xy((-p0p1).0)); let matrix = Matrix2x2F(other.vector().0.concat_xy_xy((-p0p1).0));
if f32::abs(matrix.det()) < EPSILON { if f32::abs(matrix.det()) < EPSILON {
@ -249,18 +249,18 @@ impl LineSegmentF {
} }
#[inline] #[inline]
pub fn sample(&self, t: f32) -> Point2DF { pub fn sample(&self, t: f32) -> Vector2F {
self.from() + self.vector().scale(t) self.from() + self.vector().scale(t)
} }
#[inline] #[inline]
pub fn midpoint(&self) -> Point2DF { pub fn midpoint(&self) -> Vector2F {
self.sample(0.5) self.sample(0.5)
} }
#[inline] #[inline]
pub fn offset(&self, distance: f32) -> LineSegmentF { pub fn offset(&self, distance: f32) -> LineSegment2F {
if self.is_zero_length() { if self.is_zero_length() {
*self *self
} else { } else {
@ -269,7 +269,7 @@ impl LineSegmentF {
.vector() .vector()
.yx() .yx()
.normalize() .normalize()
.scale_xy(Point2DF::new(-distance, distance)) .scale_xy(Vector2F::new(-distance, distance))
} }
} }
@ -279,19 +279,19 @@ impl LineSegmentF {
} }
} }
impl Add<Point2DF> for LineSegmentF { impl Add<Vector2F> for LineSegment2F {
type Output = LineSegmentF; type Output = LineSegment2F;
#[inline] #[inline]
fn add(self, point: Point2DF) -> LineSegmentF { fn add(self, point: Vector2F) -> LineSegment2F {
LineSegmentF(self.0 + point.0.xyxy()) LineSegment2F(self.0 + point.0.xyxy())
} }
} }
impl Sub<Point2DF> for LineSegmentF { impl Sub<Vector2F> for LineSegment2F {
type Output = LineSegmentF; type Output = LineSegment2F;
#[inline] #[inline]
fn sub(self, point: Point2DF) -> LineSegmentF { fn sub(self, point: Vector2F) -> LineSegment2F {
LineSegmentF(self.0 - point.0.xyxy()) LineSegment2F(self.0 - point.0.xyxy())
} }
} }

View File

@ -11,7 +11,7 @@
//! Basic geometry and linear algebra primitives, optimized with SIMD. //! Basic geometry and linear algebra primitives, optimized with SIMD.
pub mod line_segment; pub mod line_segment;
pub mod point;
pub mod rect; pub mod rect;
pub mod transform2d; pub mod transform2d;
pub mod transform3d; pub mod transform3d;
pub mod vector;

View File

@ -10,7 +10,7 @@
//! 2D axis-aligned rectangles, optimized with SIMD. //! 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}; use pathfinder_simd::default::{F32x4, I32x4};
#[derive(Clone, Copy, Debug, PartialEq, Default)] #[derive(Clone, Copy, Debug, PartialEq, Default)]
@ -18,42 +18,42 @@ pub struct RectF(pub F32x4);
impl RectF { impl RectF {
#[inline] #[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)) RectF(origin.0.concat_xy_xy(origin.0 + size.0))
} }
#[inline] #[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)) RectF(origin.0.concat_xy_xy(lower_right.0))
} }
#[inline] #[inline]
pub fn origin(&self) -> Point2DF { pub fn origin(&self) -> Vector2F {
Point2DF(self.0) Vector2F(self.0)
} }
#[inline] #[inline]
pub fn size(&self) -> Point2DF { pub fn size(&self) -> Vector2F {
Point2DF(self.0.zwxy() - self.0.xyxy()) Vector2F(self.0.zwxy() - self.0.xyxy())
} }
#[inline] #[inline]
pub fn upper_right(&self) -> Point2DF { pub fn upper_right(&self) -> Vector2F {
Point2DF(self.0.zyxw()) Vector2F(self.0.zyxw())
} }
#[inline] #[inline]
pub fn lower_left(&self) -> Point2DF { pub fn lower_left(&self) -> Vector2F {
Point2DF(self.0.xwzy()) Vector2F(self.0.xwzy())
} }
#[inline] #[inline]
pub fn lower_right(&self) -> Point2DF { pub fn lower_right(&self) -> Vector2F {
Point2DF(self.0.zwxy()) Vector2F(self.0.zwxy())
} }
#[inline] #[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.origin <= point && point <= self.lower_right
self.0 self.0
.concat_xy_xy(point.0) .concat_xy_xy(point.0)
@ -76,7 +76,7 @@ impl RectF {
} }
#[inline] #[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)) RectF::from_points(self.origin().min(point), self.lower_right().max(point))
} }
@ -130,7 +130,7 @@ impl RectF {
} }
#[inline] #[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)) RectF(self.0 * factors.0.concat_xy_xy(factors.0))
} }
@ -140,7 +140,7 @@ impl RectF {
} }
#[inline] #[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) RectF::from_points(self.origin() - amount, self.lower_right() + amount)
} }
@ -155,38 +155,38 @@ pub struct RectI(pub I32x4);
impl RectI { impl RectI {
#[inline] #[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)) RectI(origin.0.concat_xy_xy(origin.0 + size.0))
} }
#[inline] #[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)) RectI(origin.0.concat_xy_xy(lower_right.0))
} }
#[inline] #[inline]
pub fn origin(&self) -> Point2DI { pub fn origin(&self) -> Vector2I {
Point2DI(self.0) Vector2I(self.0)
} }
#[inline] #[inline]
pub fn size(&self) -> Point2DI { pub fn size(&self) -> Vector2I {
Point2DI(self.0.zwxy() - self.0.xyxy()) Vector2I(self.0.zwxy() - self.0.xyxy())
} }
#[inline] #[inline]
pub fn upper_right(&self) -> Point2DI { pub fn upper_right(&self) -> Vector2I {
Point2DI(self.0.zyxw()) Vector2I(self.0.zyxw())
} }
#[inline] #[inline]
pub fn lower_left(&self) -> Point2DI { pub fn lower_left(&self) -> Vector2I {
Point2DI(self.0.xwzy()) Vector2I(self.0.xwzy())
} }
#[inline] #[inline]
pub fn lower_right(&self) -> Point2DI { pub fn lower_right(&self) -> Vector2I {
Point2DI(self.0.zwxy()) Vector2I(self.0.zwxy())
} }
#[inline] #[inline]
@ -210,9 +210,9 @@ impl RectI {
} }
#[inline] #[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 // 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 self.0
.concat_xy_xy(point.0) .concat_xy_xy(point.0)
.packed_le(point.0.concat_xy_xy(lower_right.0)) .packed_le(point.0.concat_xy_xy(lower_right.0))

View File

@ -10,8 +10,8 @@
//! 2D affine transforms. //! 2D affine transforms.
use crate::basic::line_segment::LineSegmentF; use crate::basic::line_segment::LineSegment2F;
use crate::basic::point::Point2DF; use crate::basic::vector::Vector2F;
use crate::basic::rect::RectF; use crate::basic::rect::RectF;
use crate::basic::transform3d::Transform3DF; use crate::basic::transform3d::Transform3DF;
use crate::segment::Segment; use crate::segment::Segment;
@ -26,13 +26,13 @@ pub struct Matrix2x2F(pub F32x4);
impl Default for Matrix2x2F { impl Default for Matrix2x2F {
#[inline] #[inline]
fn default() -> Matrix2x2F { fn default() -> Matrix2x2F {
Self::from_scale(Point2DF::splat(1.0)) Self::from_scale(Vector2F::splat(1.0))
} }
} }
impl Matrix2x2F { impl Matrix2x2F {
#[inline] #[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())) Matrix2x2F(F32x4::new(scale.x(), 0.0, 0.0, scale.y()))
} }
@ -72,9 +72,9 @@ impl Matrix2x2F {
} }
#[inline] #[inline]
pub fn transform_point(&self, point: Point2DF) -> Point2DF { pub fn transform_point(&self, point: Vector2F) -> Vector2F {
let halves = self.0 * point.0.xxyy(); let halves = self.0 * point.0.xxyy();
Point2DF(halves + halves.zwzw()) Vector2F(halves + halves.zwzw())
} }
#[inline] #[inline]
@ -118,22 +118,22 @@ impl Sub<Matrix2x2F> for Matrix2x2F {
pub struct Transform2DF { pub struct Transform2DF {
// Row-major order. // Row-major order.
matrix: Matrix2x2F, matrix: Matrix2x2F,
vector: Point2DF, vector: Vector2F,
} }
impl Default for Transform2DF { impl Default for Transform2DF {
#[inline] #[inline]
fn default() -> Transform2DF { fn default() -> Transform2DF {
Self::from_scale(Point2DF::splat(1.0)) Self::from_scale(Vector2F::splat(1.0))
} }
} }
impl Transform2DF { impl Transform2DF {
#[inline] #[inline]
pub fn from_scale(scale: Point2DF) -> Transform2DF { pub fn from_scale(scale: Vector2F) -> Transform2DF {
Transform2DF { Transform2DF {
matrix: Matrix2x2F::from_scale(scale), matrix: Matrix2x2F::from_scale(scale),
vector: Point2DF::default(), vector: Vector2F::default(),
} }
} }
@ -141,7 +141,7 @@ impl Transform2DF {
pub fn from_rotation(theta: f32) -> Transform2DF { pub fn from_rotation(theta: f32) -> Transform2DF {
Transform2DF { Transform2DF {
matrix: Matrix2x2F::from_rotation(theta), 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 { pub fn from_rotation_vector(vector: UnitVector) -> Transform2DF {
Transform2DF { Transform2DF {
matrix: Matrix2x2F::from_rotation_vector(vector), matrix: Matrix2x2F::from_rotation_vector(vector),
vector: Point2DF::default(), vector: Vector2F::default(),
} }
} }
#[inline] #[inline]
pub fn from_translation(vector: Point2DF) -> Transform2DF { pub fn from_translation(vector: Vector2F) -> Transform2DF {
Transform2DF { matrix: Matrix2x2F::default(), vector } Transform2DF { matrix: Matrix2x2F::default(), vector }
} }
#[inline] #[inline]
pub fn from_scale_rotation_translation( pub fn from_scale_rotation_translation(
scale: Point2DF, scale: Vector2F,
theta: f32, theta: f32,
translation: Point2DF, translation: Vector2F,
) -> Transform2DF { ) -> Transform2DF {
let rotation = Transform2DF::from_rotation(theta); let rotation = Transform2DF::from_rotation(theta);
let translation = Transform2DF::from_translation(translation); 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 { pub fn row_major(m11: f32, m12: f32, m21: f32, m22: f32, m31: f32, m32: f32) -> Transform2DF {
Transform2DF { Transform2DF {
matrix: Matrix2x2F::row_major(m11, m12, m21, m22), matrix: Matrix2x2F::row_major(m11, m12, m21, m22),
vector: Point2DF::new(m31, m32), vector: Vector2F::new(m31, m32),
} }
} }
#[inline] #[inline]
pub fn transform_point(&self, point: Point2DF) -> Point2DF { pub fn transform_point(&self, point: Vector2F) -> Vector2F {
self.matrix.transform_point(point) + self.vector self.matrix.transform_point(point) + self.vector
} }
#[inline] #[inline]
pub fn transform_line_segment(&self, line_segment: &LineSegmentF) -> LineSegmentF { pub fn transform_line_segment(&self, line_segment: &LineSegment2F) -> LineSegment2F {
LineSegmentF::new(self.transform_point(line_segment.from()), LineSegment2F::new(self.transform_point(line_segment.from()),
self.transform_point(line_segment.to())) self.transform_point(line_segment.to()))
} }
@ -257,7 +257,7 @@ impl Transform2DF {
} }
#[inline] #[inline]
pub fn post_translate(&self, vector: Point2DF) -> Transform2DF { pub fn post_translate(&self, vector: Vector2F) -> Transform2DF {
self.post_mul(&Transform2DF::from_translation(vector)) self.post_mul(&Transform2DF::from_translation(vector))
} }
@ -267,7 +267,7 @@ impl Transform2DF {
} }
#[inline] #[inline]
pub fn post_scale(&self, scale: Point2DF) -> Transform2DF { pub fn post_scale(&self, scale: Vector2F) -> Transform2DF {
self.post_mul(&Transform2DF::from_scale(scale)) 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. /// This decomposition assumes that scale, rotation, and translation are applied in that order.
#[inline] #[inline]
pub fn translation(&self) -> Point2DF { pub fn translation(&self) -> Vector2F {
self.vector self.vector
} }
@ -292,7 +292,7 @@ impl Transform2DF {
/// This decomposition assumes that scale, rotation, and translation are applied in that order. /// This decomposition assumes that scale, rotation, and translation are applied in that order.
#[inline] #[inline]
pub fn scale_factor(&self) -> f32 { pub fn scale_factor(&self) -> f32 {
Point2DF(self.matrix.0.zwxy()).length() Vector2F(self.matrix.0.zwxy()).length()
} }
} }

View File

@ -10,7 +10,7 @@
//! 3D transforms that can be applied to paths. //! 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::rect::RectF;
use crate::basic::transform2d::Matrix2x2F; use crate::basic::transform2d::Matrix2x2F;
use crate::segment::Segment; use crate::segment::Segment;
@ -236,12 +236,12 @@ impl Transform3DF {
} }
#[inline] #[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 term0 = self.c0 * F32x4::splat(point.x());
let term1 = self.c1 * F32x4::splat(point.y()); let term1 = self.c1 * F32x4::splat(point.y());
let term2 = self.c2 * F32x4::splat(point.z()); let term2 = self.c2 * F32x4::splat(point.z());
let term3 = self.c3 * F32x4::splat(point.w()); let term3 = self.c3 * F32x4::splat(point.w());
Point3DF(term0 + term1 + term2 + term3) Vector4F(term0 + term1 + term2 + term3)
} }
#[inline] #[inline]
@ -319,12 +319,12 @@ impl Neg for Matrix2x2F {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Perspective { pub struct Perspective {
pub transform: Transform3DF, pub transform: Transform3DF,
pub window_size: Point2DI, pub window_size: Vector2I,
} }
impl Perspective { impl Perspective {
#[inline] #[inline]
pub fn new(transform: &Transform3DF, window_size: Point2DI) -> Perspective { pub fn new(transform: &Transform3DF, window_size: Vector2I) -> Perspective {
Perspective { Perspective {
transform: *transform, transform: *transform,
window_size, window_size,
@ -332,14 +332,14 @@ impl Perspective {
} }
#[inline] #[inline]
pub fn transform_point_2d(&self, point: &Point2DF) -> Point2DF { pub fn transform_point_2d(&self, point: &Vector2F) -> Vector2F {
let point = self let point = self
.transform .transform
.transform_point(point.to_3d()) .transform_point(point.to_3d())
.perspective_divide() .perspective_divide()
.to_2d() .to_2d()
* Point2DF::new(1.0, -1.0); * Vector2F::new(1.0, -1.0);
(point + Point2DF::splat(1.0)) * self.window_size.to_f32().scale(0.5) (point + Vector2F::splat(1.0)) * self.window_size.to_f32().scale(0.5)
} }
// TODO(pcwalton): SIMD? // TODO(pcwalton): SIMD?
@ -420,7 +420,7 @@ where
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::basic::point::Point3DF; use crate::basic::vector::Vector4F;
use crate::basic::transform3d::Transform3DF; use crate::basic::transform3d::Transform3DF;
#[test] #[test]
@ -458,8 +458,8 @@ mod test {
let a = Transform3DF::row_major( let a = Transform3DF::row_major(
3.0, 1.0, 4.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0, 8.0, 9.0, 7.0, 9.0, 3.0, 2.0, 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 p = Vector4F::new(3.0, 8.0, 4.0, 6.0);
let q = Point3DF::new(63.0, 97.0, 135.0, 117.0); let q = Vector4F::new(63.0, 97.0, 135.0, 117.0);
assert_eq!(a.transform_point(p), q); 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.12969608, 0.0946466, 0.43248631, 0.63480505, 0.08154603, 0.50305436, 0.48359687,
0.51057162, 0.24812012, 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 p1 = m.transform_point(p0);
let m_inv = m.inverse(); let m_inv = m.inverse();
let m_inv_exp = Transform3DF::row_major( let m_inv_exp = Transform3DF::row_major(

View File

@ -15,22 +15,22 @@ use std::ops::{Add, AddAssign, Mul, Neg, Sub};
/// 2D points with 32-bit floating point coordinates. /// 2D points with 32-bit floating point coordinates.
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug, Default)]
pub struct Point2DF(pub F32x4); pub struct Vector2F(pub F32x4);
impl Point2DF { impl Vector2F {
#[inline] #[inline]
pub fn new(x: f32, y: f32) -> Point2DF { pub fn new(x: f32, y: f32) -> Vector2F {
Point2DF(F32x4::new(x, y, 0.0, 0.0)) Vector2F(F32x4::new(x, y, 0.0, 0.0))
} }
#[inline] #[inline]
pub fn splat(value: f32) -> Point2DF { pub fn splat(value: f32) -> Vector2F {
Point2DF(F32x4::splat(value)) Vector2F(F32x4::splat(value))
} }
#[inline] #[inline]
pub fn to_3d(self) -> Point3DF { pub fn to_3d(self) -> Vector4F {
Point3DF(self.0.concat_xy_xy(F32x4::new(0.0, 1.0, 0.0, 0.0))) Vector4F(self.0.concat_xy_xy(F32x4::new(0.0, 1.0, 0.0, 0.0)))
} }
#[inline] #[inline]
@ -54,49 +54,49 @@ impl Point2DF {
} }
#[inline] #[inline]
pub fn min(&self, other: Point2DF) -> Point2DF { pub fn min(&self, other: Vector2F) -> Vector2F {
Point2DF(self.0.min(other.0)) Vector2F(self.0.min(other.0))
} }
#[inline] #[inline]
pub fn max(&self, other: Point2DF) -> Point2DF { pub fn max(&self, other: Vector2F) -> Vector2F {
Point2DF(self.0.max(other.0)) Vector2F(self.0.max(other.0))
} }
#[inline] #[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) self.max(min_val).min(max_val)
} }
#[inline] #[inline]
pub fn det(&self, other: Point2DF) -> f32 { pub fn det(&self, other: Vector2F) -> f32 {
self.x() * other.y() - self.y() * other.x() self.x() * other.y() - self.y() * other.x()
} }
#[inline] #[inline]
pub fn dot(&self, other: Point2DF) -> f32 { pub fn dot(&self, other: Vector2F) -> f32 {
let xy = self.0 * other.0; let xy = self.0 * other.0;
xy.x() + xy.y() xy.x() + xy.y()
} }
#[inline] #[inline]
pub fn scale(&self, x: f32) -> Point2DF { pub fn scale(&self, x: f32) -> Vector2F {
Point2DF(self.0 * F32x4::splat(x)) Vector2F(self.0 * F32x4::splat(x))
} }
#[inline] #[inline]
pub fn scale_xy(&self, factors: Point2DF) -> Point2DF { pub fn scale_xy(&self, factors: Vector2F) -> Vector2F {
Point2DF(self.0 * factors.0) Vector2F(self.0 * factors.0)
} }
#[inline] #[inline]
pub fn floor(&self) -> Point2DF { pub fn floor(&self) -> Vector2F {
Point2DF(self.0.floor()) Vector2F(self.0.floor())
} }
#[inline] #[inline]
pub fn ceil(&self) -> Point2DF { pub fn ceil(&self) -> Vector2F {
Point2DF(self.0.ceil()) Vector2F(self.0.ceil())
} }
/// Treats this point as a vector and calculates its squared length. /// 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. /// Treats this point as a vector and normalizes it.
#[inline] #[inline]
pub fn normalize(&self) -> Point2DF { pub fn normalize(&self) -> Vector2F {
self.scale(1.0 / self.length()) self.scale(1.0 / self.length())
} }
/// Swaps y and x. /// Swaps y and x.
#[inline] #[inline]
pub fn yx(&self) -> Point2DF { pub fn yx(&self) -> Vector2F {
Point2DF(self.0.yxwz()) Vector2F(self.0.yxwz())
} }
#[inline] #[inline]
pub fn is_zero(&self) -> bool { pub fn is_zero(&self) -> bool {
*self == Point2DF::default() *self == Vector2F::default()
} }
#[inline] #[inline]
pub fn lerp(&self, other: Point2DF, t: f32) -> Point2DF { pub fn lerp(&self, other: Vector2F, t: f32) -> Vector2F {
*self + (other - *self).scale(t) *self + (other - *self).scale(t)
} }
#[inline] #[inline]
pub fn to_i32(&self) -> Point2DI { pub fn to_i32(&self) -> Vector2I {
Point2DI(self.0.to_i32x4()) Vector2I(self.0.to_i32x4())
} }
} }
impl PartialEq for Point2DF { impl PartialEq for Vector2F {
#[inline] #[inline]
fn eq(&self, other: &Point2DF) -> bool { fn eq(&self, other: &Vector2F) -> bool {
let results = self.0.packed_eq(other.0); let results = self.0.packed_eq(other.0);
results[0] != 0 && results[1] != 0 results[0] != 0 && results[1] != 0
} }
} }
impl Add<Point2DF> for Point2DF { impl Add<Vector2F> for Vector2F {
type Output = Point2DF; type Output = Vector2F;
#[inline] #[inline]
fn add(self, other: Point2DF) -> Point2DF { fn add(self, other: Vector2F) -> Vector2F {
Point2DF(self.0 + other.0) Vector2F(self.0 + other.0)
} }
} }
impl Sub<Point2DF> for Point2DF { impl Sub<Vector2F> for Vector2F {
type Output = Point2DF; type Output = Vector2F;
#[inline] #[inline]
fn sub(self, other: Point2DF) -> Point2DF { fn sub(self, other: Vector2F) -> Vector2F {
Point2DF(self.0 - other.0) Vector2F(self.0 - other.0)
} }
} }
impl Mul<Point2DF> for Point2DF { impl Mul<Vector2F> for Vector2F {
type Output = Point2DF; type Output = Vector2F;
#[inline] #[inline]
fn mul(self, other: Point2DF) -> Point2DF { fn mul(self, other: Vector2F) -> Vector2F {
Point2DF(self.0 * other.0) Vector2F(self.0 * other.0)
} }
} }
impl Neg for Point2DF { impl Neg for Vector2F {
type Output = Point2DF; type Output = Vector2F;
#[inline] #[inline]
fn neg(self) -> Point2DF { fn neg(self) -> Vector2F {
Point2DF(-self.0) Vector2F(-self.0)
} }
} }
/// 2D points with 32-bit signed integer coordinates. /// 2D points with 32-bit signed integer coordinates.
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug, Default)]
pub struct Point2DI(pub I32x4); pub struct Vector2I(pub I32x4);
impl Point2DI { impl Vector2I {
#[inline] #[inline]
pub fn new(x: i32, y: i32) -> Point2DI { pub fn new(x: i32, y: i32) -> Vector2I {
Point2DI(I32x4::new(x, y, 0, 0)) Vector2I(I32x4::new(x, y, 0, 0))
} }
#[inline] #[inline]
pub fn splat(value: i32) -> Point2DI { pub fn splat(value: i32) -> Vector2I {
Point2DI(I32x4::splat(value)) Vector2I(I32x4::splat(value))
} }
#[inline] #[inline]
@ -216,47 +216,47 @@ impl Point2DI {
} }
#[inline] #[inline]
pub fn scale(&self, factor: i32) -> Point2DI { pub fn scale(&self, factor: i32) -> Vector2I {
Point2DI(self.0 * I32x4::splat(factor)) Vector2I(self.0 * I32x4::splat(factor))
} }
#[inline] #[inline]
pub fn scale_xy(&self, factors: Point2DI) -> Point2DI { pub fn scale_xy(&self, factors: Vector2I) -> Vector2I {
Point2DI(self.0 * factors.0) Vector2I(self.0 * factors.0)
} }
#[inline] #[inline]
pub fn to_f32(&self) -> Point2DF { pub fn to_f32(&self) -> Vector2F {
Point2DF(self.0.to_f32x4()) Vector2F(self.0.to_f32x4())
} }
} }
impl Add<Point2DI> for Point2DI { impl Add<Vector2I> for Vector2I {
type Output = Point2DI; type Output = Vector2I;
#[inline] #[inline]
fn add(self, other: Point2DI) -> Point2DI { fn add(self, other: Vector2I) -> Vector2I {
Point2DI(self.0 + other.0) Vector2I(self.0 + other.0)
} }
} }
impl AddAssign<Point2DI> for Point2DI { impl AddAssign<Vector2I> for Vector2I {
#[inline] #[inline]
fn add_assign(&mut self, other: Point2DI) { fn add_assign(&mut self, other: Vector2I) {
self.0 += other.0 self.0 += other.0
} }
} }
impl Sub<Point2DI> for Point2DI { impl Sub<Vector2I> for Vector2I {
type Output = Point2DI; type Output = Vector2I;
#[inline] #[inline]
fn sub(self, other: Point2DI) -> Point2DI { fn sub(self, other: Vector2I) -> Vector2I {
Point2DI(self.0 - other.0) Vector2I(self.0 - other.0)
} }
} }
impl PartialEq for Point2DI { impl PartialEq for Vector2I {
#[inline] #[inline]
fn eq(&self, other: &Point2DI) -> bool { fn eq(&self, other: &Vector2I) -> bool {
let results = self.0.packed_eq(other.0); let results = self.0.packed_eq(other.0);
results[0] != 0 && results[1] != 0 results[0] != 0 && results[1] != 0
} }
@ -264,22 +264,22 @@ impl PartialEq for Point2DI {
/// 3D homogeneous points. /// 3D homogeneous points.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub struct Point3DF(pub F32x4); pub struct Vector4F(pub F32x4);
impl Point3DF { impl Vector4F {
#[inline] #[inline]
pub fn new(x: f32, y: f32, z: f32, w: f32) -> Point3DF { pub fn new(x: f32, y: f32, z: f32, w: f32) -> Vector4F {
Point3DF(F32x4::new(x, y, z, w)) Vector4F(F32x4::new(x, y, z, w))
} }
#[inline] #[inline]
pub fn splat(value: f32) -> Point3DF { pub fn splat(value: f32) -> Vector4F {
Point3DF(F32x4::splat(value)) Vector4F(F32x4::splat(value))
} }
#[inline] #[inline]
pub fn to_2d(self) -> Point2DF { pub fn to_2d(self) -> Vector2F {
Point2DF(self.0) Vector2F(self.0)
} }
#[inline] #[inline]
@ -303,10 +303,10 @@ impl Point3DF {
} }
#[inline] #[inline]
pub fn scale(&self, x: f32) -> Point3DF { pub fn scale(&self, x: f32) -> Vector4F {
let mut factors = F32x4::splat(x); let mut factors = F32x4::splat(x);
factors[3] = 1.0; factors[3] = 1.0;
Point3DF(self.0 * factors) Vector4F(self.0 * factors)
} }
#[inline] #[inline]
@ -330,12 +330,12 @@ impl Point3DF {
} }
#[inline] #[inline]
pub fn perspective_divide(self) -> Point3DF { pub fn perspective_divide(self) -> Vector4F {
Point3DF(self.0 * F32x4::splat(1.0 / self.w())) Vector4F(self.0 * F32x4::splat(1.0 / self.w()))
} }
#[inline] #[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) self.0.approx_eq(other.0, epsilon)
} }
@ -349,39 +349,39 @@ impl Point3DF {
} }
#[inline] #[inline]
pub fn lerp(self, other: Point3DF, t: f32) -> Point3DF { pub fn lerp(self, other: Vector4F, t: f32) -> Vector4F {
Point3DF(self.0 + (other.0 - self.0) * F32x4::splat(t)) Vector4F(self.0 + (other.0 - self.0) * F32x4::splat(t))
} }
} }
impl Add<Point3DF> for Point3DF { impl Add<Vector4F> for Vector4F {
type Output = Point3DF; type Output = Vector4F;
#[inline] #[inline]
fn add(self, other: Point3DF) -> Point3DF { fn add(self, other: Vector4F) -> Vector4F {
Point3DF(self.0 + other.0) Vector4F(self.0 + other.0)
} }
} }
impl AddAssign for Point3DF { impl AddAssign for Vector4F {
#[inline] #[inline]
fn add_assign(&mut self, other: Point3DF) { fn add_assign(&mut self, other: Vector4F) {
self.0 += other.0 self.0 += other.0
} }
} }
impl Mul<Point3DF> for Point3DF { impl Mul<Vector4F> for Vector4F {
type Output = Point3DF; type Output = Vector4F;
#[inline] #[inline]
fn mul(self, other: Point3DF) -> Point3DF { fn mul(self, other: Vector4F) -> Vector4F {
Point3DF(self.0 * other.0) Vector4F(self.0 * other.0)
} }
} }
impl Default for Point3DF { impl Default for Vector4F {
#[inline] #[inline]
fn default() -> Point3DF { fn default() -> Vector4F {
let mut point = F32x4::default(); let mut point = F32x4::default();
point.set_w(1.0); point.set_w(1.0);
Point3DF(point) Vector4F(point)
} }
} }

View File

@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::basic::line_segment::LineSegmentF; use crate::basic::line_segment::LineSegment2F;
use crate::basic::point::{Point2DF, Point3DF}; use crate::basic::vector::{Vector2F, Vector4F};
use crate::basic::rect::RectF; use crate::basic::rect::RectF;
use crate::outline::{Contour, PointFlags, PushSegmentFlags}; use crate::outline::{Contour, PointFlags, PushSegmentFlags};
use crate::segment::{CubicSegment, Segment}; use crate::segment::{CubicSegment, Segment};
@ -20,17 +20,17 @@ use std::fmt::Debug;
use std::mem; use std::mem;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
struct Edge(LineSegmentF); struct Edge(LineSegment2F);
impl TEdge for Edge { impl TEdge for Edge {
#[inline] #[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()); let area = (self.0.to() - self.0.from()).det(*point - self.0.from());
debug!("point_is_inside({:?}, {:?}), area={}", self, point, area); debug!("point_is_inside({:?}, {:?}), area={}", self, point, area);
area >= 0.0 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(); let mut results = ArrayVec::new();
if let Some(t) = segment.intersection_t(&self.0) { if let Some(t) = segment.intersection_t(&self.0) {
if t >= 0.0 && t <= 1.0 { if t >= 0.0 && t <= 1.0 {
@ -51,7 +51,7 @@ enum AxisAlignedEdge {
impl TEdge for AxisAlignedEdge { impl TEdge for AxisAlignedEdge {
#[inline] #[inline]
fn point_is_inside(&self, point: &Point2DF) -> bool { fn point_is_inside(&self, point: &Vector2F) -> bool {
match *self { match *self {
AxisAlignedEdge::Left(x) => point.x() >= x, AxisAlignedEdge::Left(x) => point.x() >= x,
AxisAlignedEdge::Top(y) => point.y() >= y, 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 mut results = ArrayVec::new();
let t = match *self { let t = match *self {
AxisAlignedEdge::Left(x) | AxisAlignedEdge::Right(x) => segment.solve_t_for_x(x), AxisAlignedEdge::Left(x) | AxisAlignedEdge::Right(x) => segment.solve_t_for_x(x),
@ -74,8 +74,8 @@ impl TEdge for AxisAlignedEdge {
} }
trait TEdge: Debug { trait TEdge: Debug {
fn point_is_inside(&self, point: &Point2DF) -> bool; fn point_is_inside(&self, point: &Vector2F) -> bool;
fn intersect_line_segment(&self, segment: &LineSegmentF) -> ArrayVec<[f32; 3]>; fn intersect_line_segment(&self, segment: &LineSegment2F) -> ArrayVec<[f32; 3]>;
fn trivially_test_segment(&self, segment: &Segment) -> EdgeRelativeLocation { fn trivially_test_segment(&self, segment: &Segment) -> EdgeRelativeLocation {
let from_inside = self.point_is_inside(&segment.baseline.from()); let from_inside = self.point_is_inside(&segment.baseline.from());
@ -294,7 +294,7 @@ enum FastClipResult {
// General convex polygon clipping in 2D // General convex polygon clipping in 2D
pub(crate) struct ContourPolygonClipper { pub(crate) struct ContourPolygonClipper {
clip_polygon: SmallVec<[Point2DF; 4]>, clip_polygon: SmallVec<[Vector2F; 4]>,
contour: Contour, contour: Contour,
} }
@ -309,7 +309,7 @@ impl ContourClipper for ContourPolygonClipper {
impl ContourPolygonClipper { impl ContourPolygonClipper {
#[inline] #[inline]
pub(crate) fn new(clip_polygon: &[Point2DF], contour: Contour) -> ContourPolygonClipper { pub(crate) fn new(clip_polygon: &[Vector2F], contour: Contour) -> ContourPolygonClipper {
ContourPolygonClipper { ContourPolygonClipper {
clip_polygon: SmallVec::from_slice(clip_polygon), clip_polygon: SmallVec::from_slice(clip_polygon),
contour, contour,
@ -325,7 +325,7 @@ impl ContourPolygonClipper {
Some(prev) => *prev, Some(prev) => *prev,
}; };
for &next in &clip_polygon { for &next in &clip_polygon {
self.clip_against(Edge(LineSegmentF::new(prev, next))); self.clip_against(Edge(LineSegment2F::new(prev, next)));
prev = next; prev = next;
} }
@ -379,16 +379,16 @@ impl ContourRectClipper {
// 3D quad clipping // 3D quad clipping
pub struct PolygonClipper3D { pub struct PolygonClipper3D {
subject: Vec<Point3DF>, subject: Vec<Vector4F>,
} }
impl PolygonClipper3D { impl PolygonClipper3D {
#[inline] #[inline]
pub fn new(subject: Vec<Point3DF>) -> PolygonClipper3D { pub fn new(subject: Vec<Vector4F>) -> PolygonClipper3D {
PolygonClipper3D { subject } PolygonClipper3D { subject }
} }
pub fn clip(mut self) -> Vec<Point3DF> { pub fn clip(mut self) -> Vec<Vector4F> {
// TODO(pcwalton): Fast path for completely contained polygon? // TODO(pcwalton): Fast path for completely contained polygon?
debug!("before clipping against bottom: {:?}", self.subject); debug!("before clipping against bottom: {:?}", self.subject);
@ -440,7 +440,7 @@ enum Edge3D {
impl Edge3D { impl Edge3D {
#[inline] #[inline]
fn point_is_inside(self, point: Point3DF) -> bool { fn point_is_inside(self, point: Vector4F) -> bool {
let w = point.w(); let w = point.w();
match self { match self {
Edge3D::Left => point.x() >= -w, Edge3D::Left => point.x() >= -w,
@ -453,7 +453,7 @@ impl Edge3D {
} }
// Blinn & Newell, "Clipping using homogeneous coordinates", SIGGRAPH 1978. // 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 { let (x0, x1) = match self {
Edge3D::Left | Edge3D::Right => (prev.x(), next.x()), Edge3D::Left | Edge3D::Right => (prev.x(), next.x()),
Edge3D::Bottom | Edge3D::Top => (prev.y(), next.y()), Edge3D::Bottom | Edge3D::Top => (prev.y(), next.y()),
@ -472,7 +472,7 @@ impl Edge3D {
/// Coarse collision detection /// Coarse collision detection
// Separating axis theorem. Requires that the polygon be convex. // 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(); let mut outcode = Outcode::all();
for point in polygon_points { for point in polygon_points {
if point.x() > rect.min_x() { 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. // 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! // FIXME(pcwalton): Check winding!
let rect_points = [ let rect_points = [
rect.origin(), rect.origin(),

View File

@ -8,20 +8,20 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::basic::point::Point2DF; use crate::basic::vector::Vector2F;
use crate::orientation::Orientation; use crate::orientation::Orientation;
use crate::outline::Contour; use crate::outline::Contour;
pub struct ContourDilator<'a> { pub struct ContourDilator<'a> {
contour: &'a mut Contour, contour: &'a mut Contour,
amount: Point2DF, amount: Vector2F,
orientation: Orientation, orientation: Orientation,
} }
impl<'a> ContourDilator<'a> { impl<'a> ContourDilator<'a> {
pub fn new( pub fn new(
contour: &'a mut Contour, contour: &'a mut Contour,
amount: Point2DF, amount: Vector2F,
orientation: Orientation, orientation: Orientation,
) -> ContourDilator<'a> { ) -> ContourDilator<'a> {
ContourDilator { ContourDilator {
@ -34,8 +34,8 @@ impl<'a> ContourDilator<'a> {
pub fn dilate(&mut self) { pub fn dilate(&mut self) {
// Determine orientation. // Determine orientation.
let scale = self.amount.scale_xy(match self.orientation { let scale = self.amount.scale_xy(match self.orientation {
Orientation::Ccw => Point2DF::new(1.0, -1.0), Orientation::Ccw => Vector2F::new(1.0, -1.0),
Orientation::Cw => Point2DF::new(-1.0, 1.0), Orientation::Cw => Vector2F::new(-1.0, 1.0),
}); });
// Find the starting and previous positions. // Find the starting and previous positions.
@ -84,7 +84,7 @@ impl<'a> ContourDilator<'a> {
let bisector = prev_vector.yx() + next_vector.yx(); let bisector = prev_vector.yx() + next_vector.yx();
let bisector_length = bisector.length(); let bisector_length = bisector.length();
let scaled_bisector = if bisector_length == 0.0 { let scaled_bisector = if bisector_length == 0.0 {
Point2DF::default() Vector2F::default()
} else { } else {
bisector.scale_xy(scale).scale(1.0 / bisector_length) bisector.scale_xy(scale).scale(1.0 / bisector_length)
}; };

View File

@ -10,8 +10,8 @@
//! A compressed in-memory representation of paths. //! A compressed in-memory representation of paths.
use crate::basic::line_segment::LineSegmentF; use crate::basic::line_segment::LineSegment2F;
use crate::basic::point::Point2DF; use crate::basic::vector::Vector2F;
use crate::basic::rect::RectF; use crate::basic::rect::RectF;
use crate::basic::transform2d::Transform2DF; use crate::basic::transform2d::Transform2DF;
use crate::basic::transform3d::Perspective; use crate::basic::transform3d::Perspective;
@ -32,7 +32,7 @@ pub struct Outline {
#[derive(Clone)] #[derive(Clone)]
pub struct Contour { pub struct Contour {
pub(crate) points: Vec<Point2DF>, pub(crate) points: Vec<Vector2F>,
pub(crate) flags: Vec<PointFlags>, pub(crate) flags: Vec<PointFlags>,
pub(crate) bounds: RectF, pub(crate) bounds: RectF,
pub(crate) closed: bool, pub(crate) closed: bool,
@ -156,7 +156,7 @@ impl Outline {
self.bounds = new_bounds.unwrap_or_else(|| RectF::default()); 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); let orientation = Orientation::from_outline(self);
self.contours self.contours
.iter_mut() .iter_mut()
@ -174,15 +174,15 @@ impl Outline {
.unwrap_or_else(|| RectF::default()); .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) 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) 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. // Quick check.
if self.is_inside_polygon(clip_polygon) { if self.is_inside_polygon(clip_polygon) {
return; return;
@ -271,33 +271,33 @@ impl Contour {
} }
#[inline] #[inline]
pub fn position_of(&self, index: u32) -> Point2DF { pub fn position_of(&self, index: u32) -> Vector2F {
self.points[index as usize] self.points[index as usize]
} }
#[inline] #[inline]
pub fn last_position(&self) -> Option<Point2DF> { pub fn last_position(&self) -> Option<Vector2F> {
self.points.last().cloned() self.points.last().cloned()
} }
#[inline] #[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] self.points[self.points.len() - index as usize]
} }
#[inline] #[inline]
pub fn push_endpoint(&mut self, point: Point2DF) { pub fn push_endpoint(&mut self, point: Vector2F) {
self.push_point(point, PointFlags::empty(), true); self.push_point(point, PointFlags::empty(), true);
} }
#[inline] #[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(ctrl, PointFlags::CONTROL_POINT_0, true);
self.push_point(point, PointFlags::empty(), true); self.push_point(point, PointFlags::empty(), true);
} }
#[inline] #[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(ctrl0, PointFlags::CONTROL_POINT_0, true);
self.push_point(ctrl1, PointFlags::CONTROL_POINT_1, true); self.push_point(ctrl1, PointFlags::CONTROL_POINT_1, true);
self.push_point(point, PointFlags::empty(), true); self.push_point(point, PointFlags::empty(), true);
@ -311,7 +311,7 @@ impl Contour {
// TODO(pcwalton): SIMD. // TODO(pcwalton): SIMD.
#[inline] #[inline]
pub(crate) fn push_point(&mut self, pub(crate) fn push_point(&mut self,
point: Point2DF, point: Vector2F,
flags: PointFlags, flags: PointFlags,
update_bounds: bool) { update_bounds: bool) {
debug_assert!(!point.x().is_nan() && !point.y().is_nan()); debug_assert!(!point.x().is_nan() && !point.y().is_nan());
@ -360,20 +360,20 @@ impl Contour {
if end_angle - start_angle >= PI * 2.0 { if end_angle - start_angle >= PI * 2.0 {
self.push_ellipse(transform); self.push_ellipse(transform);
} else { } else {
let start = Point2DF::new(f32::cos(start_angle), f32::sin(start_angle)); let start = Vector2F::new(f32::cos(start_angle), f32::sin(start_angle));
let end = Point2DF::new(f32::cos(end_angle), f32::sin(end_angle)); let end = Vector2F::new(f32::cos(end_angle), f32::sin(end_angle));
self.push_arc_from_unit_chord(transform, LineSegmentF::new(start, end), direction); self.push_arc_from_unit_chord(transform, LineSegment2F::new(start, end), direction);
} }
} }
pub fn push_arc_from_unit_chord(&mut self, pub fn push_arc_from_unit_chord(&mut self,
transform: &Transform2DF, transform: &Transform2DF,
mut chord: LineSegmentF, mut chord: LineSegment2F,
direction: ArcDirection) { direction: ArcDirection) {
let mut direction_transform = Transform2DF::default(); let mut direction_transform = Transform2DF::default();
if direction == ArcDirection::CCW { if direction == ArcDirection::CCW {
chord = chord.scale_xy(Point2DF::new(-1.0, 1.0)); chord = chord.scale_xy(Vector2F::new(-1.0, 1.0));
direction_transform = Transform2DF::from_scale(Point2DF::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())); let (mut vector, end_vector) = (UnitVector(chord.from()), UnitVector(chord.to()));
@ -385,7 +385,7 @@ impl Contour {
let mut segment; let mut segment;
if !last { 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(); segment = Segment::quarter_circle_arc();
} else { } else {
segment = Segment::arc_from_cos(sweep_vector.0.x()); segment = Segment::arc_from_cos(sweep_vector.0.x());
@ -418,13 +418,13 @@ impl Contour {
let mut rotation; let mut rotation;
self.push_segment(&segment.transform(transform), self.push_segment(&segment.transform(transform),
PushSegmentFlags::UPDATE_BOUNDS | PushSegmentFlags::INCLUDE_FROM_POINT); 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)), self.push_segment(&segment.transform(&rotation.post_mul(&transform)),
PushSegmentFlags::UPDATE_BOUNDS); 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)), self.push_segment(&segment.transform(&rotation.post_mul(&transform)),
PushSegmentFlags::UPDATE_BOUNDS); 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)), self.push_segment(&segment.transform(&rotation.post_mul(&transform)),
PushSegmentFlags::UPDATE_BOUNDS); PushSegmentFlags::UPDATE_BOUNDS);
} }
@ -460,9 +460,9 @@ impl Contour {
} }
#[inline] #[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); 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[prev_point_index as usize],
self.points[next_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(); ContourDilator::new(self, amount, orientation).dilate();
self.bounds = self.bounds.dilate(amount); self.bounds = self.bounds.dilate(amount);
} }
@ -600,7 +600,7 @@ impl Contour {
} else { } else {
point_index point_index
}; };
let baseline = LineSegmentF::new( let baseline = LineSegment2F::new(
contour.points[last_endpoint_index as usize], contour.points[last_endpoint_index as usize],
contour.points[position_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 first_ctrl_point_index = last_endpoint_index as usize + 1;
let ctrl_position_0 = &contour.points[first_ctrl_point_index + 0]; let ctrl_position_0 = &contour.points[first_ctrl_point_index + 0];
let ctrl_position_1 = &contour.points[first_ctrl_point_index + 1]; 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)); handle_cubic(self, &Segment::cubic(&baseline, &ctrl));
} }
@ -802,21 +802,21 @@ impl<'a> Iterator for ContourIter<'a> {
if self.index == contour.len() { if self.index == contour.len() {
let point1 = contour.position_of(0); let point1 = contour.position_of(0);
self.index += 1; self.index += 1;
return Some(Segment::line(&LineSegmentF::new(point0, point1))); return Some(Segment::line(&LineSegment2F::new(point0, point1)));
} }
let point1_index = self.index; let point1_index = self.index;
self.index += 1; self.index += 1;
let point1 = contour.position_of(point1_index); let point1 = contour.position_of(point1_index);
if contour.point_is_endpoint(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_index = self.index;
let point2 = contour.position_of(point2_index); let point2 = contour.position_of(point2_index);
self.index += 1; self.index += 1;
if contour.point_is_endpoint(point2_index) { 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; let point3_index = self.index;
@ -824,8 +824,8 @@ impl<'a> Iterator for ContourIter<'a> {
self.index += 1; self.index += 1;
debug_assert!(contour.point_is_endpoint(point3_index)); debug_assert!(contour.point_is_endpoint(point3_index));
return Some(Segment::cubic( return Some(Segment::cubic(
&LineSegmentF::new(point0, point3), &LineSegment2F::new(point0, point3),
&LineSegmentF::new(point1, point2), &LineSegment2F::new(point1, point2),
)); ));
} }
} }
@ -837,7 +837,7 @@ pub enum ArcDirection {
} }
#[inline] #[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 { if first {
*bounds = RectF::from_points(new_point, new_point); *bounds = RectF::from_points(new_point, new_point);
} else { } else {

View File

@ -10,8 +10,8 @@
//! Line or curve segments, optimized with SIMD. //! Line or curve segments, optimized with SIMD.
use crate::basic::line_segment::LineSegmentF; use crate::basic::line_segment::LineSegment2F;
use crate::basic::point::Point2DF; use crate::basic::vector::Vector2F;
use crate::basic::transform2d::Transform2DF; use crate::basic::transform2d::Transform2DF;
use crate::util::{self, EPSILON}; use crate::util::{self, EPSILON};
use pathfinder_simd::default::F32x4; use pathfinder_simd::default::F32x4;
@ -21,8 +21,8 @@ const MAX_NEWTON_ITERATIONS: u32 = 32;
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub struct Segment { pub struct Segment {
pub baseline: LineSegmentF, pub baseline: LineSegment2F,
pub ctrl: LineSegmentF, pub ctrl: LineSegment2F,
pub kind: SegmentKind, pub kind: SegmentKind,
pub flags: SegmentFlags, pub flags: SegmentFlags,
} }
@ -31,35 +31,35 @@ impl Segment {
#[inline] #[inline]
pub fn none() -> Segment { pub fn none() -> Segment {
Segment { Segment {
baseline: LineSegmentF::default(), baseline: LineSegment2F::default(),
ctrl: LineSegmentF::default(), ctrl: LineSegment2F::default(),
kind: SegmentKind::None, kind: SegmentKind::None,
flags: SegmentFlags::empty(), flags: SegmentFlags::empty(),
} }
} }
#[inline] #[inline]
pub fn line(line: &LineSegmentF) -> Segment { pub fn line(line: &LineSegment2F) -> Segment {
Segment { Segment {
baseline: *line, baseline: *line,
ctrl: LineSegmentF::default(), ctrl: LineSegment2F::default(),
kind: SegmentKind::Line, kind: SegmentKind::Line,
flags: SegmentFlags::empty(), flags: SegmentFlags::empty(),
} }
} }
#[inline] #[inline]
pub fn quadratic(baseline: &LineSegmentF, ctrl: Point2DF) -> Segment { pub fn quadratic(baseline: &LineSegment2F, ctrl: Vector2F) -> Segment {
Segment { Segment {
baseline: *baseline, baseline: *baseline,
ctrl: LineSegmentF::new(ctrl, Point2DF::default()), ctrl: LineSegment2F::new(ctrl, Vector2F::default()),
kind: SegmentKind::Quadratic, kind: SegmentKind::Quadratic,
flags: SegmentFlags::empty(), flags: SegmentFlags::empty(),
} }
} }
#[inline] #[inline]
pub fn cubic(baseline: &LineSegmentF, ctrl: &LineSegmentF) -> Segment { pub fn cubic(baseline: &LineSegment2F, ctrl: &LineSegment2F) -> Segment {
Segment { Segment {
baseline: *baseline, baseline: *baseline,
ctrl: *ctrl, ctrl: *ctrl,
@ -91,20 +91,20 @@ impl Segment {
let (p0x, p0y) = (p3p0.z(), p3p0.w()); let (p0x, p0y) = (p3p0.z(), p3p0.w());
let (p1x, p1y) = (4.0 - p0x, (1.0 - p0x) * (3.0 - p0x) / p0y); 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); 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] #[inline]
pub fn quarter_circle_arc() -> Segment { pub fn quarter_circle_arc() -> Segment {
let p0 = Point2DF::splat(SQRT_2 * 0.5); let p0 = Vector2F::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 p1 = Vector2F::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 flip = Vector2F::new(1.0, -1.0);
let (p2, p3) = (p1.scale_xy(flip), p0.scale_xy(flip)); 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] #[inline]
pub fn as_line_segment(&self) -> LineSegmentF { pub fn as_line_segment(&self) -> LineSegment2F {
debug_assert!(self.is_line()); debug_assert!(self.is_line());
self.baseline self.baseline
} }
@ -146,7 +146,7 @@ impl Segment {
let mut new_segment = *self; let mut new_segment = *self;
let p1_2 = self.ctrl.from() + self.ctrl.from(); let p1_2 = self.ctrl.from() + self.ctrl.from();
new_segment.ctrl = 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); .scale(1.0 / 3.0);
new_segment.kind = SegmentKind::Cubic; new_segment.kind = SegmentKind::Cubic;
new_segment new_segment
@ -205,7 +205,7 @@ impl Segment {
} }
#[inline] #[inline]
pub fn sample(self, t: f32) -> Point2DF { pub fn sample(self, t: f32) -> Vector2F {
// FIXME(pcwalton): Don't degree elevate! // FIXME(pcwalton): Don't degree elevate!
if self.is_line() { if self.is_line() {
self.as_line_segment().sample(t) self.as_line_segment().sample(t)
@ -262,16 +262,16 @@ impl<'s> CubicSegment<'s> {
let (baseline0, ctrl0, baseline1, ctrl1); let (baseline0, ctrl0, baseline1, ctrl1);
if t <= 0.0 { if t <= 0.0 {
let from = &self.0.baseline.from(); let from = &self.0.baseline.from();
baseline0 = LineSegmentF::new(*from, *from); baseline0 = LineSegment2F::new(*from, *from);
ctrl0 = LineSegmentF::new(*from, *from); ctrl0 = LineSegment2F::new(*from, *from);
baseline1 = self.0.baseline; baseline1 = self.0.baseline;
ctrl1 = self.0.ctrl; ctrl1 = self.0.ctrl;
} else if t >= 1.0 { } else if t >= 1.0 {
let to = &self.0.baseline.to(); let to = &self.0.baseline.to();
baseline0 = self.0.baseline; baseline0 = self.0.baseline;
ctrl0 = self.0.ctrl; ctrl0 = self.0.ctrl;
baseline1 = LineSegmentF::new(*to, *to); baseline1 = LineSegment2F::new(*to, *to);
ctrl1 = LineSegmentF::new(*to, *to); ctrl1 = LineSegment2F::new(*to, *to);
} else { } else {
let tttt = F32x4::splat(t); let tttt = F32x4::splat(t);
@ -290,10 +290,10 @@ impl<'s> CubicSegment<'s> {
// p0123 = lerp(p012, p123, t) // p0123 = lerp(p012, p123, t)
let p0123 = p012p123 + tttt * (p123 - p012p123); let p0123 = p012p123 + tttt * (p123 - p012p123);
baseline0 = LineSegmentF(p0p3.concat_xy_xy(p0123)); baseline0 = LineSegment2F(p0p3.concat_xy_xy(p0123));
ctrl0 = LineSegmentF(p01p12.concat_xy_xy(p012p123)); ctrl0 = LineSegment2F(p01p12.concat_xy_xy(p012p123));
baseline1 = LineSegmentF(p0123.concat_xy_zw(p0p3)); baseline1 = LineSegment2F(p0123.concat_xy_zw(p0p3));
ctrl1 = LineSegmentF(p012p123.concat_zw_zw(p12p23)); ctrl1 = LineSegment2F(p012p123.concat_zw_zw(p12p23));
} }
( (
@ -324,7 +324,7 @@ impl<'s> CubicSegment<'s> {
// FIXME(pcwalton): Use Horner's method! // FIXME(pcwalton): Use Horner's method!
#[inline] #[inline]
pub fn sample(self, t: f32) -> Point2DF { pub fn sample(self, t: f32) -> Vector2F {
self.split(t).0.baseline.to() self.split(t).0.baseline.to()
} }

View File

@ -10,8 +10,8 @@
//! Utilities for converting path strokes to fills. //! Utilities for converting path strokes to fills.
use crate::basic::line_segment::LineSegmentF; use crate::basic::line_segment::LineSegment2F;
use crate::basic::point::Point2DF; use crate::basic::vector::Vector2F;
use crate::basic::rect::RectF; use crate::basic::rect::RectF;
use crate::basic::transform2d::Transform2DF; use crate::basic::transform2d::Transform2DF;
use crate::outline::{ArcDirection, Contour, Outline, PushSegmentFlags}; use crate::outline::{ArcDirection, Contour, Outline, PushSegmentFlags};
@ -100,7 +100,7 @@ impl<'a> OutlineStrokeToFill<'a> {
// Add join if necessary. // Add join if necessary.
if closed && stroker.output.might_need_join(self.style.line_join) { 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 (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, stroker.output.add_join(self.style.line_width * 0.5,
self.style.line_join, self.style.line_join,
stroker.input.position_of(0), stroker.input.position_of(0),
@ -127,7 +127,7 @@ impl<'a> OutlineStrokeToFill<'a> {
let offset = gradient.scale(width * 0.5); let offset = gradient.scale(width * 0.5);
let p2 = p1 + offset; 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; let p4 = p3 - offset;
contour.push_endpoint(p2); contour.push_endpoint(p2);
@ -136,12 +136,12 @@ impl<'a> OutlineStrokeToFill<'a> {
} }
LineCap::Round => { LineCap::Round => {
let scale = Point2DF::splat(width * 0.5); let scale = Vector2F::splat(width * 0.5);
let offset = gradient.yx().scale_xy(Point2DF::new(-1.0, 1.0)); let offset = gradient.yx().scale_xy(Vector2F::new(-1.0, 1.0));
let mut transform = Transform2DF::from_scale(scale); let mut transform = Transform2DF::from_scale(scale);
let translation = p1 + offset.scale(width * 0.5); let translation = p1 + offset.scale(width * 0.5);
transform = transform.post_mul(&Transform2DF::from_translation(translation)); 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); contour.push_arc_from_unit_chord(&transform, chord, ArcDirection::CW);
} }
} }
@ -191,7 +191,7 @@ trait Offset {
fn add_to_contour(&self, fn add_to_contour(&self,
distance: f32, distance: f32,
join: LineJoin, join: LineJoin,
join_point: Point2DF, join_point: Vector2F,
contour: &mut Contour); contour: &mut Contour);
fn offset_once(&self, distance: f32) -> Self; fn offset_once(&self, distance: f32) -> Self;
fn error_is_within_tolerance(&self, other: &Segment, distance: f32) -> bool; fn error_is_within_tolerance(&self, other: &Segment, distance: f32) -> bool;
@ -222,7 +222,7 @@ impl Offset for Segment {
fn add_to_contour(&self, fn add_to_contour(&self,
distance: f32, distance: f32,
join: LineJoin, join: LineJoin,
join_point: Point2DF, join_point: Vector2F,
contour: &mut Contour) { contour: &mut Contour) {
// Add join if necessary. // Add join if necessary.
if contour.might_need_join(join) { if contour.might_need_join(join) {
@ -235,7 +235,7 @@ impl Offset for Segment {
self.ctrl.from() 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. // Push segment.
@ -249,51 +249,51 @@ impl Offset for Segment {
} }
if self.is_quadratic() { if self.is_quadratic() {
let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.from()); let mut segment_0 = LineSegment2F::new(self.baseline.from(), self.ctrl.from());
let mut segment_1 = LineSegmentF::new(self.ctrl.from(), self.baseline.to()); let mut segment_1 = LineSegment2F::new(self.ctrl.from(), self.baseline.to());
segment_0 = segment_0.offset(distance); segment_0 = segment_0.offset(distance);
segment_1 = segment_1.offset(distance); segment_1 = segment_1.offset(distance);
let ctrl = match segment_0.intersection_t(&segment_1) { let ctrl = match segment_0.intersection_t(&segment_1) {
Some(t) => segment_0.sample(t), Some(t) => segment_0.sample(t),
None => segment_0.to().lerp(segment_1.from(), 0.5), 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); return Segment::quadratic(&baseline, ctrl);
} }
debug_assert!(self.is_cubic()); debug_assert!(self.is_cubic());
if self.baseline.from() == self.ctrl.from() { if self.baseline.from() == self.ctrl.from() {
let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.to()); let mut segment_0 = LineSegment2F::new(self.baseline.from(), self.ctrl.to());
let mut segment_1 = LineSegmentF::new(self.ctrl.to(), self.baseline.to()); let mut segment_1 = LineSegment2F::new(self.ctrl.to(), self.baseline.to());
segment_0 = segment_0.offset(distance); segment_0 = segment_0.offset(distance);
segment_1 = segment_1.offset(distance); segment_1 = segment_1.offset(distance);
let ctrl = match segment_0.intersection_t(&segment_1) { let ctrl = match segment_0.intersection_t(&segment_1) {
Some(t) => segment_0.sample(t), Some(t) => segment_0.sample(t),
None => segment_0.to().lerp(segment_1.from(), 0.5), 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());
let ctrl = LineSegmentF::new(segment_0.from(), ctrl); let ctrl = LineSegment2F::new(segment_0.from(), ctrl);
return Segment::cubic(&baseline, &ctrl); return Segment::cubic(&baseline, &ctrl);
} }
if self.ctrl.to() == self.baseline.to() { if self.ctrl.to() == self.baseline.to() {
let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.from()); let mut segment_0 = LineSegment2F::new(self.baseline.from(), self.ctrl.from());
let mut segment_1 = LineSegmentF::new(self.ctrl.from(), self.baseline.to()); let mut segment_1 = LineSegment2F::new(self.ctrl.from(), self.baseline.to());
segment_0 = segment_0.offset(distance); segment_0 = segment_0.offset(distance);
segment_1 = segment_1.offset(distance); segment_1 = segment_1.offset(distance);
let ctrl = match segment_0.intersection_t(&segment_1) { let ctrl = match segment_0.intersection_t(&segment_1) {
Some(t) => segment_0.sample(t), Some(t) => segment_0.sample(t),
None => segment_0.to().lerp(segment_1.from(), 0.5), 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());
let ctrl = LineSegmentF::new(ctrl, segment_1.to()); let ctrl = LineSegment2F::new(ctrl, segment_1.to());
return Segment::cubic(&baseline, &ctrl); return Segment::cubic(&baseline, &ctrl);
} }
let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.from()); let mut segment_0 = LineSegment2F::new(self.baseline.from(), self.ctrl.from());
let mut segment_1 = LineSegmentF::new(self.ctrl.from(), self.ctrl.to()); let mut segment_1 = LineSegment2F::new(self.ctrl.from(), self.ctrl.to());
let mut segment_2 = LineSegmentF::new(self.ctrl.to(), self.baseline.to()); let mut segment_2 = LineSegment2F::new(self.ctrl.to(), self.baseline.to());
segment_0 = segment_0.offset(distance); segment_0 = segment_0.offset(distance);
segment_1 = segment_1.offset(distance); segment_1 = segment_1.offset(distance);
segment_2 = segment_2.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), segment_1.to().lerp(segment_2.from(), 0.5),
), ),
}; };
let baseline = LineSegmentF::new(segment_0.from(), segment_2.to()); let baseline = LineSegment2F::new(segment_0.from(), segment_2.to());
let ctrl = LineSegmentF::new(ctrl_0, ctrl_1); let ctrl = LineSegment2F::new(ctrl_0, ctrl_1);
Segment::cubic(&baseline, &ctrl) Segment::cubic(&baseline, &ctrl)
} }
@ -356,10 +356,10 @@ impl Contour {
fn add_join(&mut self, fn add_join(&mut self,
distance: f32, distance: f32,
join: LineJoin, join: LineJoin,
join_point: Point2DF, join_point: Vector2F,
next_tangent: &LineSegmentF) { next_tangent: &LineSegment2F) {
let (p0, p1) = (self.position_of_last(2), self.position_of_last(1)); 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 { match join {
LineJoin::Bevel => {} LineJoin::Bevel => {}
@ -373,12 +373,12 @@ impl Contour {
} }
} }
LineJoin::Round => { LineJoin::Round => {
let scale = Point2DF::splat(distance.abs()); let scale = Vector2F::splat(distance.abs());
let mut transform = Transform2DF::from_scale(scale); let mut transform = Transform2DF::from_scale(scale);
transform = transform.post_mul(&Transform2DF::from_translation(join_point)); transform = transform.post_mul(&Transform2DF::from_translation(join_point));
let chord_from = (prev_tangent.to() - join_point).normalize(); let chord_from = (prev_tangent.to() - join_point).normalize();
let chord_to = (next_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); self.push_arc_from_unit_chord(&transform, chord, ArcDirection::CW);
} }
} }

View File

@ -10,30 +10,30 @@
//! A utility module that allows unit vectors to be treated like angles. //! 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; use pathfinder_simd::default::F32x4;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct UnitVector(pub Point2DF); pub struct UnitVector(pub Vector2F);
impl UnitVector { impl UnitVector {
#[inline] #[inline]
pub fn from_angle(theta: f32) -> UnitVector { pub fn from_angle(theta: f32) -> UnitVector {
UnitVector(Point2DF::new(theta.cos(), theta.sin())) UnitVector(Vector2F::new(theta.cos(), theta.sin()))
} }
/// Angle addition formula. /// Angle addition formula.
#[inline] #[inline]
pub fn rotate_by(&self, other: UnitVector) -> UnitVector { pub fn rotate_by(&self, other: UnitVector) -> UnitVector {
let products = (self.0).0.xyyx() * (other.0).0.xyxy(); 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. /// Angle subtraction formula.
#[inline] #[inline]
pub fn rev_rotate_by(&self, other: UnitVector) -> UnitVector { pub fn rev_rotate_by(&self, other: UnitVector) -> UnitVector {
let products = (self.0).0.xyyx() * (other.0).0.xyxy(); 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. /// Half angle formula.
@ -41,6 +41,6 @@ impl UnitVector {
pub fn halve_angle(&self) -> UnitVector { pub fn halve_angle(&self) -> UnitVector {
let x = self.0.x(); let x = self.0.x();
let term = F32x4::new(x, -x, 0.0, 0.0); 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()))
} }
} }

View File

@ -14,7 +14,7 @@
extern crate log; extern crate log;
use gl::types::{GLboolean, GLchar, GLenum, GLfloat, GLint, GLsizei, GLsizeiptr, GLuint, GLvoid}; 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_geometry::basic::rect::RectI;
use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::resources::ResourceLoader;
use pathfinder_gpu::{BlendState, BufferData, BufferTarget, BufferUploadMode, ClearParams}; use pathfinder_gpu::{BlendState, BufferData, BufferTarget, BufferUploadMode, ClearParams};
@ -164,7 +164,7 @@ impl Device for GLDevice {
type VertexArray = GLVertexArray; type VertexArray = GLVertexArray;
type VertexAttr = GLVertexAttr; 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); let (gl_internal_format, gl_format, gl_type);
match format { match format {
TextureFormat::R8 => { TextureFormat::R8 => {
@ -203,7 +203,7 @@ impl Device for GLDevice {
texture 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); assert!(data.len() >= size.x() as usize * size.y() as usize);
let mut texture = GLTexture { gl_texture: 0, size }; let mut texture = GLTexture { gl_texture: 0, size };
@ -450,11 +450,11 @@ impl Device for GLDevice {
} }
#[inline] #[inline]
fn texture_size(&self, texture: &Self::Texture) -> Point2DI { fn texture_size(&self, texture: &Self::Texture) -> Vector2I {
texture.size 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); assert!(data.len() >= size.x() as usize * size.y() as usize * 4);
unsafe { unsafe {
self.bind_texture(texture, 0); self.bind_texture(texture, 0);
@ -472,7 +472,7 @@ impl Device for GLDevice {
self.set_texture_parameters(texture); self.set_texture_parameters(texture);
} }
fn read_pixels_from_default_framebuffer(&self, size: Point2DI) -> Vec<u8> { fn read_pixels_from_default_framebuffer(&self, size: Vector2I) -> Vec<u8> {
let mut pixels = vec![0; size.x() as usize * size.y() as usize * 4]; let mut pixels = vec![0; size.x() as usize * size.y() as usize * 4];
unsafe { unsafe {
gl::BindFramebuffer(gl::FRAMEBUFFER, self.default_framebuffer); ck(); gl::BindFramebuffer(gl::FRAMEBUFFER, self.default_framebuffer); ck();
@ -799,7 +799,7 @@ impl Drop for GLShader {
pub struct GLTexture { pub struct GLTexture {
gl_texture: GLuint, gl_texture: GLuint,
pub size: Point2DI, pub size: Vector2I,
} }
pub struct GLTimerQuery { pub struct GLTimerQuery {

View File

@ -12,7 +12,7 @@
use crate::resources::ResourceLoader; use crate::resources::ResourceLoader;
use image::ImageFormat; 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::rect::RectI;
use pathfinder_geometry::basic::transform3d::Transform3DF; use pathfinder_geometry::basic::transform3d::Transform3DF;
use pathfinder_geometry::color::ColorF; use pathfinder_geometry::color::ColorF;
@ -41,8 +41,8 @@ pub trait Device {
type VertexArray; type VertexArray;
type VertexAttr; type VertexAttr;
fn create_texture(&self, format: TextureFormat, size: Point2DI) -> Self::Texture; fn create_texture(&self, format: TextureFormat, size: Vector2I) -> Self::Texture;
fn create_texture_from_data(&self, size: Point2DI, data: &[u8]) -> Self::Texture; fn create_texture_from_data(&self, size: Vector2I, data: &[u8]) -> Self::Texture;
fn create_shader_from_source( fn create_shader_from_source(
&self, &self,
resources: &dyn ResourceLoader, resources: &dyn ResourceLoader,
@ -74,9 +74,9 @@ pub trait Device {
mode: BufferUploadMode, mode: BufferUploadMode,
); );
fn framebuffer_texture<'f>(&self, framebuffer: &'f Self::Framebuffer) -> &'f Self::Texture; fn framebuffer_texture<'f>(&self, framebuffer: &'f Self::Framebuffer) -> &'f Self::Texture;
fn texture_size(&self, texture: &Self::Texture) -> Point2DI; fn texture_size(&self, texture: &Self::Texture) -> Vector2I;
fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI, data: &[u8]); fn upload_to_texture(&self, texture: &Self::Texture, size: Vector2I, data: &[u8]);
fn read_pixels_from_default_framebuffer(&self, size: Point2DI) -> Vec<u8>; fn read_pixels_from_default_framebuffer(&self, size: Vector2I) -> Vec<u8>;
fn clear(&self, params: &ClearParams); fn clear(&self, params: &ClearParams);
fn draw_arrays(&self, primitive: Primitive, index_count: u32, render_state: &RenderState); fn draw_arrays(&self, primitive: Primitive, index_count: u32, render_state: &RenderState);
fn draw_elements(&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) let image = image::load_from_memory_with_format(&data, ImageFormat::PNG)
.unwrap() .unwrap()
.to_luma(); .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) self.create_texture_from_data(size, &image)
} }

View File

@ -17,8 +17,8 @@ use crate::scene::Scene;
use crate::tile_map::DenseTileMap; use crate::tile_map::DenseTileMap;
use crate::tiles::{self, TILE_HEIGHT, TILE_WIDTH, Tiler}; use crate::tiles::{self, TILE_HEIGHT, TILE_WIDTH, Tiler};
use crate::z_buffer::ZBuffer; use crate::z_buffer::ZBuffer;
use pathfinder_geometry::basic::line_segment::{LineSegmentF, LineSegmentU4, LineSegmentU8}; use pathfinder_geometry::basic::line_segment::{LineSegment2F, LineSegmentU4, LineSegmentU8};
use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; use pathfinder_geometry::basic::vector::{Vector2F, Vector2I};
use pathfinder_geometry::basic::rect::{RectF, RectI}; use pathfinder_geometry::basic::rect::{RectF, RectI};
use pathfinder_geometry::util; use pathfinder_geometry::util;
use pathfinder_simd::default::{F32x4, I32x4}; use pathfinder_simd::default::{F32x4, I32x4};
@ -160,8 +160,8 @@ impl BuiltObject {
fn add_fill( fn add_fill(
&mut self, &mut self,
builder: &SceneBuilder, builder: &SceneBuilder,
segment: &LineSegmentF, segment: &LineSegment2F,
tile_coords: Point2DI, tile_coords: Vector2I,
) { ) {
debug!("add_fill({:?} ({:?}))", segment, tile_coords); debug!("add_fill({:?} ({:?}))", segment, tile_coords);
@ -214,7 +214,7 @@ impl BuiltObject {
fn get_or_allocate_alpha_tile_index( fn get_or_allocate_alpha_tile_index(
&mut self, &mut self,
builder: &SceneBuilder, builder: &SceneBuilder,
tile_coords: Point2DI, tile_coords: Vector2I,
) -> u16 { ) -> u16 {
let local_tile_index = self.tiles.coords_to_index_unchecked(tile_coords); 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; let alpha_tile_index = self.tiles.data[local_tile_index].alpha_tile_index;
@ -235,16 +235,16 @@ impl BuiltObject {
left: f32, left: f32,
right: f32, right: f32,
mut winding: i32, mut winding: i32,
tile_coords: Point2DI, tile_coords: Vector2I,
) { ) {
let tile_origin_y = (tile_coords.y() * TILE_HEIGHT as i32) as f32; let tile_origin_y = (tile_coords.y() * TILE_HEIGHT as i32) as f32;
let left = Point2DF::new(left, tile_origin_y); let left = Vector2F::new(left, tile_origin_y);
let right = Point2DF::new(right, tile_origin_y); let right = Vector2F::new(right, tile_origin_y);
let segment = if winding < 0 { let segment = if winding < 0 {
LineSegmentF::new(left, right) LineSegment2F::new(left, right)
} else { } else {
LineSegmentF::new(right, left) LineSegment2F::new(right, left)
}; };
debug!( debug!(
@ -268,7 +268,7 @@ impl BuiltObject {
pub(crate) fn generate_fill_primitives_for_line( pub(crate) fn generate_fill_primitives_for_line(
&mut self, &mut self,
builder: &SceneBuilder, builder: &SceneBuilder,
mut segment: LineSegmentF, mut segment: LineSegment2F,
tile_y: i32, tile_y: i32,
) { ) {
debug!( debug!(
@ -303,29 +303,29 @@ impl BuiltObject {
((i32::from(subsegment_tile_x) + 1) * TILE_HEIGHT as i32) as f32; ((i32::from(subsegment_tile_x) + 1) * TILE_HEIGHT as i32) as f32;
if subsegment_tile_right < segment_right { if subsegment_tile_right < segment_right {
let x = subsegment_tile_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 { if !winding {
fill_to = point; fill_to = point;
segment = LineSegmentF::new(point, segment.to()); segment = LineSegment2F::new(point, segment.to());
} else { } else {
fill_from = point; 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_segment = LineSegment2F::new(fill_from, fill_to);
let fill_tile_coords = Point2DI::new(subsegment_tile_x, tile_y); let fill_tile_coords = Vector2I::new(subsegment_tile_x, tile_y);
self.add_fill(builder, &fill_segment, fill_tile_coords); self.add_fill(builder, &fill_segment, fill_tile_coords);
} }
} }
#[inline] #[inline]
pub(crate) fn tile_coords_to_local_index(&self, coords: Point2DI) -> Option<u32> { pub(crate) fn tile_coords_to_local_index(&self, coords: Vector2I) -> Option<u32> {
self.tiles.coords_to_index(coords).map(|index| index as u32) self.tiles.coords_to_index(coords).map(|index| index as u32)
} }
#[inline] #[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) self.tiles.index_to_coords(tile_index as usize)
} }
} }

View File

@ -16,7 +16,7 @@
//! The debug font atlas was generated using: https://evanw.github.io/font-texture-generator/ //! The debug font atlas was generated using: https://evanw.github.io/font-texture-generator/
use crate::gpu::renderer::{RenderStats, RenderTime}; 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_geometry::basic::rect::RectI;
use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::resources::ResourceLoader;
use pathfinder_gpu::Device; use pathfinder_gpu::Device;
@ -50,7 +50,7 @@ where
pub fn new( pub fn new(
device: &D, device: &D,
resources: &dyn ResourceLoader, resources: &dyn ResourceLoader,
framebuffer_size: Point2DI, framebuffer_size: Vector2I,
) -> DebugUIPresenter<D> { ) -> DebugUIPresenter<D> {
let ui_presenter = UIPresenter::new(device, resources, framebuffer_size); let ui_presenter = UIPresenter::new(device, resources, framebuffer_size);
DebugUIPresenter { DebugUIPresenter {
@ -85,16 +85,16 @@ where
let framebuffer_size = self.ui_presenter.framebuffer_size(); let framebuffer_size = self.ui_presenter.framebuffer_size();
let bottom = framebuffer_size.y() - PADDING; let bottom = framebuffer_size.y() - PADDING;
let window_rect = RectI::new( let window_rect = RectI::new(
Point2DI::new( Vector2I::new(
framebuffer_size.x() - PADDING - STATS_WINDOW_WIDTH, framebuffer_size.x() - PADDING - STATS_WINDOW_WIDTH,
bottom - PERFORMANCE_WINDOW_HEIGHT - PADDING - STATS_WINDOW_HEIGHT, 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); 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( self.ui_presenter.draw_text(
device, device,
&format!("Paths: {}", mean_cpu_sample.stats.path_count), &format!("Paths: {}", mean_cpu_sample.stats.path_count),
@ -104,19 +104,19 @@ where
self.ui_presenter.draw_text( self.ui_presenter.draw_text(
device, device,
&format!("Solid Tiles: {}", mean_cpu_sample.stats.solid_tile_count), &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, false,
); );
self.ui_presenter.draw_text( self.ui_presenter.draw_text(
device, device,
&format!("Alpha Tiles: {}", mean_cpu_sample.stats.alpha_tile_count), &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, false,
); );
self.ui_presenter.draw_text( self.ui_presenter.draw_text(
device, device,
&format!("Fills: {}", mean_cpu_sample.stats.fill_count), &format!("Fills: {}", mean_cpu_sample.stats.fill_count),
origin + Point2DI::new(0, LINE_HEIGHT * 3), origin + Vector2I::new(0, LINE_HEIGHT * 3),
false, false,
); );
} }
@ -125,16 +125,16 @@ where
let framebuffer_size = self.ui_presenter.framebuffer_size(); let framebuffer_size = self.ui_presenter.framebuffer_size();
let bottom = framebuffer_size.y() - PADDING; let bottom = framebuffer_size.y() - PADDING;
let window_rect = RectI::new( let window_rect = RectI::new(
Point2DI::new( Vector2I::new(
framebuffer_size.x() - PADDING - PERFORMANCE_WINDOW_WIDTH, framebuffer_size.x() - PADDING - PERFORMANCE_WINDOW_WIDTH,
bottom - PERFORMANCE_WINDOW_HEIGHT, 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); 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( self.ui_presenter.draw_text(
device, device,
&format!( &format!(
@ -152,7 +152,7 @@ where
"Stage 0 GPU: {:.3} ms", "Stage 0 GPU: {:.3} ms",
duration_to_ms(mean_gpu_sample.time.stage_0) duration_to_ms(mean_gpu_sample.time.stage_0)
), ),
origin + Point2DI::new(0, LINE_HEIGHT * 1), origin + Vector2I::new(0, LINE_HEIGHT * 1),
false, false,
); );
self.ui_presenter.draw_text( self.ui_presenter.draw_text(
@ -161,7 +161,7 @@ where
"Stage 1 GPU: {:.3} ms", "Stage 1 GPU: {:.3} ms",
duration_to_ms(mean_gpu_sample.time.stage_1) duration_to_ms(mean_gpu_sample.time.stage_1)
), ),
origin + Point2DI::new(0, LINE_HEIGHT * 2), origin + Vector2I::new(0, LINE_HEIGHT * 2),
false, false,
); );
@ -171,7 +171,7 @@ where
self.ui_presenter.draw_text( self.ui_presenter.draw_text(
device, device,
&format!("Wallclock: {:.3} ms", wallclock_time), &format!("Wallclock: {:.3} ms", wallclock_time),
origin + Point2DI::new(0, LINE_HEIGHT * 3), origin + Vector2I::new(0, LINE_HEIGHT * 3),
false, false,
); );
} }

View File

@ -13,7 +13,7 @@ use crate::gpu_data::{AlphaTileBatchPrimitive, FillBatchPrimitive, PaintData};
use crate::gpu_data::{RenderCommand, SolidTileBatchPrimitive}; use crate::gpu_data::{RenderCommand, SolidTileBatchPrimitive};
use crate::post::DefringingKernel; use crate::post::DefringingKernel;
use crate::tiles::{TILE_HEIGHT, TILE_WIDTH}; 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::rect::RectI;
use pathfinder_geometry::basic::transform3d::Transform3DF; use pathfinder_geometry::basic::transform3d::Transform3DF;
use pathfinder_geometry::color::ColorF; use pathfinder_geometry::color::ColorF;
@ -182,7 +182,7 @@ where
); );
let mask_framebuffer_size = let mask_framebuffer_size =
Point2DI::new(MASK_FRAMEBUFFER_WIDTH, MASK_FRAMEBUFFER_HEIGHT); Vector2I::new(MASK_FRAMEBUFFER_WIDTH, MASK_FRAMEBUFFER_HEIGHT);
let mask_framebuffer_texture = let mask_framebuffer_texture =
device.create_texture(TextureFormat::R16F, mask_framebuffer_size); device.create_texture(TextureFormat::R16F, mask_framebuffer_size);
let mask_framebuffer = device.create_framebuffer(mask_framebuffer_texture); let mask_framebuffer = device.create_framebuffer(mask_framebuffer_texture);
@ -334,7 +334,7 @@ where
} }
#[inline] #[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); 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.device.allocate_buffer(
&self.stencil_vertex_array.vertex_buffer, &self.stencil_vertex_array.vertex_buffer,
BufferData::Memory(quad_positions), BufferData::Memory(quad_positions),
@ -876,8 +876,8 @@ where
defringing_kernel: Some(..), defringing_kernel: Some(..),
.. ..
} => { } => {
let scale = Point2DI::new(3, 1); let scale = Vector2I::new(3, 1);
RectI::new(Point2DI::default(), main_viewport.size().scale_xy(scale)) RectI::new(Vector2I::default(), main_viewport.size().scale_xy(scale))
} }
_ => main_viewport, _ => main_viewport,
} }
@ -890,7 +890,7 @@ where
let size = self let size = self
.device .device
.texture_size(self.device.framebuffer_texture(framebuffer)); .texture_size(self.device.framebuffer_texture(framebuffer));
RectI::new(Point2DI::default(), size) RectI::new(Vector2I::default(), size)
} }
} }
} }
@ -1555,7 +1555,7 @@ where
{ {
Default { Default {
viewport: RectI, viewport: RectI,
window_size: Point2DI, window_size: Vector2I,
}, },
Other(D::Framebuffer), Other(D::Framebuffer),
} }
@ -1565,12 +1565,12 @@ where
D: Device, D: Device,
{ {
#[inline] #[inline]
pub fn full_window(window_size: Point2DI) -> DestFramebuffer<D> { pub fn full_window(window_size: Vector2I) -> DestFramebuffer<D> {
let viewport = RectI::new(Point2DI::default(), window_size); let viewport = RectI::new(Vector2I::default(), window_size);
DestFramebuffer::Default { viewport, window_size } DestFramebuffer::Default { viewport, window_size }
} }
fn window_size(&self, device: &D) -> Point2DI { fn window_size(&self, device: &D) -> Vector2I {
match *self { match *self {
DestFramebuffer::Default { window_size, .. } => window_size, DestFramebuffer::Default { window_size, .. } => window_size,
DestFramebuffer::Other(ref framebuffer) => { DestFramebuffer::Other(ref framebuffer) => {

View File

@ -13,7 +13,7 @@
use crate::options::BoundingQuad; use crate::options::BoundingQuad;
use crate::tile_map::DenseTileMap; use crate::tile_map::DenseTileMap;
use pathfinder_geometry::basic::line_segment::{LineSegmentU4, LineSegmentU8}; 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 pathfinder_geometry::basic::rect::RectF;
use std::fmt::{Debug, Formatter, Result as DebugResult}; use std::fmt::{Debug, Formatter, Result as DebugResult};
use std::time::Duration; use std::time::Duration;
@ -38,7 +38,7 @@ pub enum RenderCommand {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct PaintData { pub struct PaintData {
pub size: Point2DI, pub size: Vector2I,
pub texels: Vec<u8>, pub texels: Vec<u8>,
} }

View File

@ -11,7 +11,7 @@
//! Options that control how rendering is to be performed. //! Options that control how rendering is to be performed.
use crate::gpu_data::RenderCommand; 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::rect::RectF;
use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::basic::transform2d::Transform2DF;
use pathfinder_geometry::basic::transform3d::Perspective; use pathfinder_geometry::basic::transform3d::Perspective;
@ -34,7 +34,7 @@ where
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct RenderOptions { pub struct RenderOptions {
pub transform: RenderTransform, pub transform: RenderTransform,
pub dilation: Point2DF, pub dilation: Vector2F,
pub subpixel_aa_enabled: bool, pub subpixel_aa_enabled: bool,
} }
@ -121,7 +121,7 @@ impl RenderTransform {
pub(crate) struct PreparedRenderOptions { pub(crate) struct PreparedRenderOptions {
pub(crate) transform: PreparedRenderTransform, pub(crate) transform: PreparedRenderTransform,
pub(crate) dilation: Point2DF, pub(crate) dilation: Vector2F,
pub(crate) subpixel_aa_enabled: bool, pub(crate) subpixel_aa_enabled: bool,
} }
@ -130,20 +130,20 @@ impl PreparedRenderOptions {
pub(crate) fn bounding_quad(&self) -> BoundingQuad { pub(crate) fn bounding_quad(&self) -> BoundingQuad {
match self.transform { match self.transform {
PreparedRenderTransform::Perspective { quad, .. } => quad, 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 { pub(crate) enum PreparedRenderTransform {
None, None,
Transform2D(Transform2DF), Transform2D(Transform2DF),
Perspective { Perspective {
perspective: Perspective, perspective: Perspective,
clip_polygon: Vec<Point2DF>, clip_polygon: Vec<Vector2F>,
quad: [Point3DF; 4], quad: [Vector4F; 4],
}, },
} }

View File

@ -10,7 +10,7 @@
use crate::gpu_data::PaintData; use crate::gpu_data::PaintData;
use crate::scene::Scene; use crate::scene::Scene;
use pathfinder_geometry::basic::point::Point2DI; use pathfinder_geometry::basic::vector::Vector2I;
use pathfinder_geometry::color::ColorU; use pathfinder_geometry::color::ColorU;
const PAINT_TEXTURE_WIDTH: i32 = 256; const PAINT_TEXTURE_WIDTH: i32 = 256;
@ -32,7 +32,7 @@ impl Paint {
impl Scene { impl Scene {
pub fn build_paint_data(&self) -> PaintData { 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]; let mut texels = vec![0; size.x() as usize * size.y() as usize * 4];
for (paint_index, paint) in self.paints.iter().enumerate() { for (paint_index, paint) in self.paints.iter().enumerate() {
texels[paint_index * 4 + 0] = paint.color.r; 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 { pub(crate) fn paint_id_to_tex_coords(paint_id: PaintId) -> Vector2I {
let tex_coords = Point2DI::new(paint_id.0 as i32 % PAINT_TEXTURE_WIDTH, let tex_coords = Vector2I::new(paint_id.0 as i32 % PAINT_TEXTURE_WIDTH,
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)
} }

View File

@ -16,7 +16,7 @@ use crate::options::{PreparedRenderOptions, PreparedRenderTransform};
use crate::options::{RenderCommandListener, RenderOptions}; use crate::options::{RenderCommandListener, RenderOptions};
use crate::paint::{Paint, PaintId}; use crate::paint::{Paint, PaintId};
use hashbrown::HashMap; 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::rect::RectF;
use pathfinder_geometry::basic::transform2d::Transform2DF; use pathfinder_geometry::basic::transform2d::Transform2DF;
use pathfinder_geometry::color::ColorU; use pathfinder_geometry::color::ColorU;
@ -121,7 +121,7 @@ impl Scene {
}; };
if options.subpixel_aa_enabled { if options.subpixel_aa_enabled {
transform = transform 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); outline.transform(&transform);
} }
@ -158,7 +158,7 @@ impl Scene {
#[inline] #[inline]
pub(crate) fn effective_view_box(&self, render_options: &PreparedRenderOptions) -> RectF { pub(crate) fn effective_view_box(&self, render_options: &PreparedRenderOptions) -> RectF {
if render_options.subpixel_aa_enabled { 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 { } else {
self.view_box self.view_box
} }

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use pathfinder_geometry::basic::point::Point2DI; use pathfinder_geometry::basic::vector::Vector2I;
use pathfinder_geometry::basic::rect::RectI; use pathfinder_geometry::basic::rect::RectI;
#[derive(Debug)] #[derive(Debug)]
@ -43,7 +43,7 @@ impl<T> DenseTileMap<T> {
} }
#[inline] #[inline]
pub fn coords_to_index(&self, coords: Point2DI) -> Option<usize> { pub fn coords_to_index(&self, coords: Vector2I) -> Option<usize> {
// TODO(pcwalton): SIMD? // TODO(pcwalton): SIMD?
if coords.x() < self.rect.min_x() if coords.x() < self.rect.min_x()
|| coords.x() >= self.rect.max_x() || coords.x() >= self.rect.max_x()
@ -56,14 +56,14 @@ impl<T> DenseTileMap<T> {
} }
#[inline] #[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.y() - self.rect.min_y()) as usize * self.rect.size().x() as usize
+ (coords.x() - self.rect.min_x()) as usize + (coords.x() - self.rect.min_x()) as usize
} }
#[inline] #[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); 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)
} }
} }

View File

@ -12,8 +12,8 @@ use crate::builder::SceneBuilder;
use crate::gpu_data::{AlphaTileBatchPrimitive, BuiltObject, TileObjectPrimitive}; use crate::gpu_data::{AlphaTileBatchPrimitive, BuiltObject, TileObjectPrimitive};
use crate::paint::{self, PaintId}; use crate::paint::{self, PaintId};
use crate::sorted_vector::SortedVector; use crate::sorted_vector::SortedVector;
use pathfinder_geometry::basic::line_segment::LineSegmentF; use pathfinder_geometry::basic::line_segment::LineSegment2F;
use pathfinder_geometry::basic::point::{Point2DF, Point2DI}; use pathfinder_geometry::basic::vector::{Vector2F, Vector2I};
use pathfinder_geometry::basic::rect::{RectF, RectI}; use pathfinder_geometry::basic::rect::{RectF, RectI};
use pathfinder_geometry::outline::{Contour, Outline, PointIndex}; use pathfinder_geometry::outline::{Contour, Outline, PointIndex};
use pathfinder_geometry::segment::Segment; use pathfinder_geometry::segment::Segment;
@ -194,7 +194,7 @@ impl<'a> Tiler<'a> {
let current_x = let current_x =
(i32::from(current_tile_x) * TILE_WIDTH as i32) as f32 + current_subtile_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 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.built_object.add_active_fill(
self.builder, self.builder,
current_x, current_x,
@ -212,7 +212,7 @@ impl<'a> Tiler<'a> {
"... emitting backdrop {} @ tile {}", "... emitting backdrop {} @ tile {}",
current_winding, current_tile_x 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 if let Some(tile_index) = self
.built_object .built_object
.tile_coords_to_local_index(current_tile_coords) .tile_coords_to_local_index(current_tile_coords)
@ -233,7 +233,7 @@ impl<'a> Tiler<'a> {
if segment_subtile_x > current_subtile_x { if segment_subtile_x > current_subtile_x {
let current_x = let current_x =
(i32::from(current_tile_x) * TILE_WIDTH as i32) as f32 + current_subtile_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.built_object.add_active_fill(
self.builder, self.builder,
current_x, current_x,
@ -355,7 +355,7 @@ impl<'a> Tiler<'a> {
} }
pub fn round_rect_out_to_tile_bounds(rect: RectF) -> RectI { 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_WIDTH as f32,
1.0 / TILE_HEIGHT as f32, 1.0 / TILE_HEIGHT as f32,
)) ))
@ -403,7 +403,7 @@ impl PartialOrd<QueuedEndpoint> for QueuedEndpoint {
struct ActiveEdge { struct ActiveEdge {
segment: Segment, segment: Segment,
// TODO(pcwalton): Shrink `crossing` down to just one f32? // TODO(pcwalton): Shrink `crossing` down to just one f32?
crossing: Point2DF, crossing: Vector2F,
} }
impl ActiveEdge { impl ActiveEdge {
@ -416,7 +416,7 @@ impl ActiveEdge {
ActiveEdge::from_segment_and_crossing(segment, &crossing) 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 { ActiveEdge {
segment: *segment, segment: *segment,
crossing: *crossing, crossing: *crossing,
@ -451,7 +451,7 @@ impl ActiveEdge {
// If necessary, draw initial line. // If necessary, draw initial line.
if self.crossing.y() < segment.baseline.min_y() { if self.crossing.y() < segment.baseline.min_y() {
let first_line_segment = 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 if self
.process_line_segment(&first_line_segment, builder, built_object, tile_y) .process_line_segment(&first_line_segment, builder, built_object, tile_y)
.is_some() .is_some()
@ -504,11 +504,11 @@ impl ActiveEdge {
fn process_line_segment( fn process_line_segment(
&mut self, &mut self,
line_segment: &LineSegmentF, line_segment: &LineSegment2F,
builder: &SceneBuilder, builder: &SceneBuilder,
built_object: &mut BuiltObject, built_object: &mut BuiltObject,
tile_y: i32, tile_y: i32,
) -> Option<LineSegmentF> { ) -> Option<LineSegment2F> {
let tile_bottom = ((i32::from(tile_y) + 1) * TILE_HEIGHT as i32) as f32; let tile_bottom = ((i32::from(tile_y) + 1) * TILE_HEIGHT as i32) as f32;
debug!( debug!(
"process_line_segment({:?}, tile_y={}) tile_bottom={}", "process_line_segment({:?}, tile_y={}) tile_bottom={}",
@ -535,11 +535,11 @@ impl PartialOrd<ActiveEdge> for ActiveEdge {
impl AlphaTileBatchPrimitive { impl AlphaTileBatchPrimitive {
#[inline] #[inline]
fn new(tile_coords: Point2DI, fn new(tile_coords: Vector2I,
backdrop: i8, backdrop: i8,
object_index: u16, object_index: u16,
tile_index: u16, tile_index: u16,
origin_uv: Point2DI) origin_uv: Vector2I)
-> AlphaTileBatchPrimitive { -> AlphaTileBatchPrimitive {
AlphaTileBatchPrimitive { AlphaTileBatchPrimitive {
tile_x_lo: (tile_coords.x() & 0xff) as u8, tile_x_lo: (tile_coords.x() & 0xff) as u8,
@ -554,8 +554,8 @@ impl AlphaTileBatchPrimitive {
} }
#[inline] #[inline]
pub fn tile_coords(&self) -> Point2DI { pub fn tile_coords(&self) -> Vector2I {
Point2DI::new( Vector2I::new(
(self.tile_x_lo as i32) | (((self.tile_hi & 0xf) as i32) << 8), (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), (self.tile_y_lo as i32) | (((self.tile_hi & 0xf0) as i32) << 4),
) )

View File

@ -15,7 +15,7 @@ use crate::paint;
use crate::scene::PathObject; use crate::scene::PathObject;
use crate::tile_map::DenseTileMap; use crate::tile_map::DenseTileMap;
use crate::tiles; use crate::tiles;
use pathfinder_geometry::basic::point::Point2DI; use pathfinder_geometry::basic::vector::Vector2I;
use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::basic::rect::RectF;
use std::ops::Range; use std::ops::Range;
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering}; 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 tile_index = self.buffer.coords_to_index_unchecked(coords);
let existing_depth = self.buffer.data[tile_index as usize].load(AtomicOrdering::SeqCst); let existing_depth = self.buffer.data[tile_index as usize].load(AtomicOrdering::SeqCst);
existing_depth < object_index as usize + 1 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 tile_index = self.buffer.coords_to_index_unchecked(coords);
let mut old_depth = self.buffer.data[tile_index].load(AtomicOrdering::SeqCst); let mut old_depth = self.buffer.data[tile_index].load(AtomicOrdering::SeqCst);
let new_depth = (object_index + 1) as usize; let new_depth = (object_index + 1) as usize;
@ -83,7 +83,7 @@ impl ZBuffer {
} }
impl SolidTileBatchPrimitive { 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 {
SolidTileBatchPrimitive { SolidTileBatchPrimitive {
tile_x: tile_coords.x() as i16, tile_x: tile_coords.x() as i16,

View File

@ -163,7 +163,7 @@ impl F32x4 {
unsafe { F32x4(x86_64::_mm_shuffle_ps(self.0, other.0, 0b0001_1011)) } unsafe { F32x4(x86_64::_mm_shuffle_ps(self.0, other.0, 0b0001_1011)) }
} }
// FIXME(pcwalton): Move to `Point3DF`! // FIXME(pcwalton): Move to `Vector4F`!
#[inline] #[inline]
pub fn cross(&self, other: F32x4) -> F32x4 { pub fn cross(&self, other: F32x4) -> F32x4 {
self.yzxw() * other.zxyw() - self.zxyw() * other.yzxw() self.yzxw() * other.zxyw() - self.zxyw() * other.yzxw()

View File

@ -13,8 +13,8 @@
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
use pathfinder_geometry::basic::line_segment::LineSegmentF; use pathfinder_geometry::basic::line_segment::LineSegment2F;
use pathfinder_geometry::basic::point::Point2DF; use pathfinder_geometry::basic::vector::Vector2F;
use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::basic::rect::RectF;
use pathfinder_geometry::basic::transform2d::{Transform2DF, Transform2DFPathIter}; use pathfinder_geometry::basic::transform2d::{Transform2DF, Transform2DFPathIter};
use pathfinder_geometry::color::ColorU; use pathfinder_geometry::color::ColorU;
@ -268,8 +268,8 @@ impl PaintExt for Paint {
fn usvg_rect_to_euclid_rect(rect: &UsvgRect) -> RectF { fn usvg_rect_to_euclid_rect(rect: &UsvgRect) -> RectF {
RectF::new( RectF::new(
Point2DF::new(rect.x as f32, rect.y as f32), Vector2F::new(rect.x as f32, rect.y as f32),
Point2DF::new(rect.width as f32, rect.height as f32), Vector2F::new(rect.width as f32, rect.height as f32),
) )
} }
@ -289,8 +289,8 @@ where
I: Iterator<Item = UsvgPathSegment>, I: Iterator<Item = UsvgPathSegment>,
{ {
iter: I, iter: I,
first_subpath_point: Point2DF, first_subpath_point: Vector2F,
last_subpath_point: Point2DF, last_subpath_point: Vector2F,
just_moved: bool, just_moved: bool,
} }
@ -301,8 +301,8 @@ where
fn new(iter: I) -> UsvgPathToSegments<I> { fn new(iter: I) -> UsvgPathToSegments<I> {
UsvgPathToSegments { UsvgPathToSegments {
iter, iter,
first_subpath_point: Point2DF::default(), first_subpath_point: Vector2F::default(),
last_subpath_point: Point2DF::default(), last_subpath_point: Vector2F::default(),
just_moved: false, just_moved: false,
} }
} }
@ -317,15 +317,15 @@ where
fn next(&mut self) -> Option<Segment> { fn next(&mut self) -> Option<Segment> {
match self.iter.next()? { match self.iter.next()? {
UsvgPathSegment::MoveTo { x, y } => { 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.first_subpath_point = to;
self.last_subpath_point = to; self.last_subpath_point = to;
self.just_moved = true; self.just_moved = true;
self.next() self.next()
} }
UsvgPathSegment::LineTo { x, y } => { UsvgPathSegment::LineTo { x, y } => {
let to = Point2DF::new(x as f32, y as f32); let to = Vector2F::new(x as f32, y as f32);
let mut segment = Segment::line(&LineSegmentF::new(self.last_subpath_point, to)); let mut segment = Segment::line(&LineSegment2F::new(self.last_subpath_point, to));
if self.just_moved { if self.just_moved {
segment.flags.insert(SegmentFlags::FIRST_IN_SUBPATH); segment.flags.insert(SegmentFlags::FIRST_IN_SUBPATH);
} }
@ -341,12 +341,12 @@ where
x, x,
y, y,
} => { } => {
let ctrl0 = Point2DF::new(x1 as f32, y1 as f32); let ctrl0 = Vector2F::new(x1 as f32, y1 as f32);
let ctrl1 = Point2DF::new(x2 as f32, y2 as f32); let ctrl1 = Vector2F::new(x2 as f32, y2 as f32);
let to = Point2DF::new(x as f32, y as f32); let to = Vector2F::new(x as f32, y as f32);
let mut segment = Segment::cubic( let mut segment = Segment::cubic(
&LineSegmentF::new(self.last_subpath_point, to), &LineSegment2F::new(self.last_subpath_point, to),
&LineSegmentF::new(ctrl0, ctrl1), &LineSegment2F::new(ctrl0, ctrl1),
); );
if self.just_moved { if self.just_moved {
segment.flags.insert(SegmentFlags::FIRST_IN_SUBPATH); segment.flags.insert(SegmentFlags::FIRST_IN_SUBPATH);
@ -356,7 +356,7 @@ where
Some(segment) Some(segment)
} }
UsvgPathSegment::ClosePath => { UsvgPathSegment::ClosePath => {
let mut segment = Segment::line(&LineSegmentF::new( let mut segment = Segment::line(&LineSegment2F::new(
self.last_subpath_point, self.last_subpath_point,
self.first_subpath_point, self.first_subpath_point,
)); ));

View File

@ -13,7 +13,7 @@ use font_kit::error::GlyphLoadingError;
use font_kit::hinting::HintingOptions; use font_kit::hinting::HintingOptions;
use font_kit::loader::Loader; use font_kit::loader::Loader;
use lyon_path::builder::{FlatPathBuilder, PathBuilder}; 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::basic::transform2d::Transform2DF;
use pathfinder_geometry::outline::{Contour, Outline}; use pathfinder_geometry::outline::{Contour, Outline};
use pathfinder_geometry::stroke::{OutlineStrokeToFill, StrokeStyle}; use pathfinder_geometry::stroke::{OutlineStrokeToFill, StrokeStyle};
@ -88,11 +88,11 @@ impl SceneExt for Scene {
paint_id: PaintId) paint_id: PaintId)
-> Result<(), GlyphLoadingError> { -> Result<(), GlyphLoadingError> {
for glyph in &layout.glyphs { 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; let font = &*glyph.font.font;
// FIXME(pcwalton): Cache this! // FIXME(pcwalton): Cache this!
let scale = style.size / (font.metrics().units_per_em as f32); 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 = let transform =
Transform2DF::from_scale(scale).post_mul(transform).post_translate(offset); Transform2DF::from_scale(scale).post_mul(transform).post_translate(offset);
self.push_glyph(font, self.push_glyph(font,
@ -147,8 +147,8 @@ impl OutlinePathBuilder {
} }
} }
fn convert_point(&self, point: Point2D<f32>) -> Point2DF { fn convert_point(&self, point: Point2D<f32>) -> Vector2F {
self.transform.transform_point(Point2DF::new(point.x, point.y)) self.transform.transform_point(Vector2F::new(point.x, point.y))
} }
} }

View File

@ -17,7 +17,7 @@
extern crate serde_derive; extern crate serde_derive;
use hashbrown::HashMap; 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::basic::rect::RectI;
use pathfinder_geometry::color::ColorU; use pathfinder_geometry::color::ColorU;
use pathfinder_gpu::resources::ResourceLoader; 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<D> where D: Device { pub struct UIPresenter<D> where D: Device {
pub event_queue: UIEventQueue, pub event_queue: UIEventQueue,
pub mouse_position: Point2DF, pub mouse_position: Vector2F,
framebuffer_size: Point2DI, framebuffer_size: Vector2I,
texture_program: DebugTextureProgram<D>, texture_program: DebugTextureProgram<D>,
texture_vertex_array: DebugTextureVertexArray<D>, texture_vertex_array: DebugTextureVertexArray<D>,
@ -82,7 +82,7 @@ pub struct UIPresenter<D> where D: Device {
} }
impl<D> UIPresenter<D> where D: Device { impl<D> UIPresenter<D> 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<D> { -> UIPresenter<D> {
let texture_program = DebugTextureProgram::new(device, resources); let texture_program = DebugTextureProgram::new(device, resources);
let texture_vertex_array = DebugTextureVertexArray::new(device, &texture_program); let texture_vertex_array = DebugTextureVertexArray::new(device, &texture_program);
@ -98,7 +98,7 @@ impl<D> UIPresenter<D> where D: Device {
UIPresenter { UIPresenter {
event_queue: UIEventQueue::new(), event_queue: UIEventQueue::new(),
mouse_position: Point2DF::default(), mouse_position: Vector2F::default(),
framebuffer_size, framebuffer_size,
@ -114,11 +114,11 @@ impl<D> UIPresenter<D> where D: Device {
} }
} }
pub fn framebuffer_size(&self) -> Point2DI { pub fn framebuffer_size(&self) -> Vector2I {
self.framebuffer_size 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; self.framebuffer_size = window_size;
} }
@ -183,7 +183,7 @@ impl<D> UIPresenter<D> 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 mut next = origin;
let char_count = string.chars().count(); let char_count = string.chars().count();
let mut vertex_data = Vec::with_capacity(char_count * 4); let mut vertex_data = Vec::with_capacity(char_count * 4);
@ -195,10 +195,10 @@ impl<D> UIPresenter<D> where D: Device {
let info = &self.font.characters[&character]; let info = &self.font.characters[&character];
let position_rect = let position_rect =
RectI::new(Point2DI::new(next.x() - info.origin_x, next.y() - info.origin_y), RectI::new(Vector2I::new(next.x() - info.origin_x, next.y() - info.origin_y),
Point2DI::new(info.width as i32, info.height as i32)); Vector2I::new(info.width as i32, info.height as i32));
let tex_coord_rect = RectI::new(Point2DI::new(info.x, info.y), let tex_coord_rect = RectI::new(Vector2I::new(info.x, info.y),
Point2DI::new(info.width, info.height)); Vector2I::new(info.width, info.height));
let first_vertex_index = vertex_data.len(); let first_vertex_index = vertex_data.len();
vertex_data.extend_from_slice(&[ vertex_data.extend_from_slice(&[
DebugTextureVertex::new(position_rect.origin(), tex_coord_rect.origin()), DebugTextureVertex::new(position_rect.origin(), tex_coord_rect.origin()),
@ -222,11 +222,11 @@ impl<D> UIPresenter<D> where D: Device {
pub fn draw_texture(&self, pub fn draw_texture(&self,
device: &D, device: &D,
origin: Point2DI, origin: Vector2I,
texture: &D::Texture, texture: &D::Texture,
color: ColorU) { color: ColorU) {
let position_rect = RectI::new(origin, device.texture_size(&texture)); 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 = [ let vertex_data = [
DebugTextureVertex::new(position_rect.origin(), tex_coord_rect.origin()), DebugTextureVertex::new(position_rect.origin(), tex_coord_rect.origin()),
DebugTextureVertex::new(position_rect.upper_right(), tex_coord_rect.upper_right()), DebugTextureVertex::new(position_rect.upper_right(), tex_coord_rect.upper_right()),
@ -316,7 +316,7 @@ impl<D> UIPresenter<D> where D: Device {
} }
// TODO(pcwalton): `LineSegmentI32`. // 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)]; let vertex_data = vec![DebugSolidVertex::new(from), DebugSolidVertex::new(to)];
self.draw_solid_rects_with_vertex_data(device, &vertex_data, &[0, 1], color, false); self.draw_solid_rects_with_vertex_data(device, &vertex_data, &[0, 1], color, false);
@ -328,7 +328,7 @@ impl<D> UIPresenter<D> where D: Device {
texture: &D::Texture, texture: &D::Texture,
corner_rects: &CornerRects) { corner_rects: &CornerRects) {
let corner_size = device.texture_size(&texture); 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![ let vertex_data = vec![
DebugTextureVertex::new( DebugTextureVertex::new(
@ -412,12 +412,12 @@ impl<D> UIPresenter<D> where D: Device {
}); });
} }
pub fn draw_button(&mut self, device: &D, origin: Point2DI, texture: &D::Texture) -> bool { pub fn draw_button(&mut self, device: &D, origin: Vector2I, texture: &D::Texture) -> bool {
let button_rect = RectI::new(origin, Point2DI::new(BUTTON_WIDTH, BUTTON_HEIGHT)); let button_rect = RectI::new(origin, Vector2I::new(BUTTON_WIDTH, BUTTON_HEIGHT));
self.draw_solid_rounded_rect(device, button_rect, WINDOW_COLOR); self.draw_solid_rounded_rect(device, button_rect, WINDOW_COLOR);
self.draw_rounded_rect_outline(device, button_rect, OUTLINE_COLOR); self.draw_rounded_rect_outline(device, button_rect, OUTLINE_COLOR);
self.draw_texture(device, self.draw_texture(device,
origin + Point2DI::new(PADDING, PADDING), origin + Vector2I::new(PADDING, PADDING),
texture, texture,
BUTTON_ICON_COLOR); BUTTON_ICON_COLOR);
self.event_queue.handle_mouse_down_in_rect(button_rect).is_some() self.event_queue.handle_mouse_down_in_rect(button_rect).is_some()
@ -425,7 +425,7 @@ impl<D> UIPresenter<D> where D: Device {
pub fn draw_text_switch(&mut self, pub fn draw_text_switch(&mut self,
device: &D, device: &D,
mut origin: Point2DI, mut origin: Vector2I,
segment_labels: &[&str], segment_labels: &[&str],
mut value: u8) mut value: u8)
-> u8 { -> u8 {
@ -436,15 +436,15 @@ impl<D> UIPresenter<D> where D: Device {
value = new_value; 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() { for (segment_index, segment_label) in segment_labels.iter().enumerate() {
let label_width = self.measure_text(segment_label); let label_width = self.measure_text(segment_label);
let offset = SEGMENT_SIZE / 2 - label_width / 2; let offset = SEGMENT_SIZE / 2 - label_width / 2;
self.draw_text(device, self.draw_text(device,
segment_label, segment_label,
origin + Point2DI::new(offset, 0), origin + Vector2I::new(offset, 0),
segment_index as u8 == value); segment_index as u8 == value);
origin += Point2DI::new(SEGMENT_SIZE + 1, 0); origin += Vector2I::new(SEGMENT_SIZE + 1, 0);
} }
value value
@ -452,7 +452,7 @@ impl<D> UIPresenter<D> where D: Device {
pub fn draw_image_segmented_control(&mut self, pub fn draw_image_segmented_control(&mut self,
device: &D, device: &D,
mut origin: Point2DI, mut origin: Vector2I,
segment_textures: &[&D::Texture], segment_textures: &[&D::Texture],
mut value: Option<u8>) mut value: Option<u8>)
-> Option<u8> { -> Option<u8> {
@ -469,7 +469,7 @@ impl<D> UIPresenter<D> where D: Device {
for (segment_index, segment_texture) in segment_textures.iter().enumerate() { for (segment_index, segment_texture) in segment_textures.iter().enumerate() {
let texture_width = device.texture_size(segment_texture).x(); 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 { let color = if Some(segment_index as u8) == value {
WINDOW_COLOR WINDOW_COLOR
} else { } else {
@ -477,7 +477,7 @@ impl<D> UIPresenter<D> where D: Device {
}; };
self.draw_texture(device, origin + offset, segment_texture, color); 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 clicked_segment
@ -485,12 +485,12 @@ impl<D> UIPresenter<D> where D: Device {
fn draw_segmented_control(&mut self, fn draw_segmented_control(&mut self,
device: &D, device: &D,
origin: Point2DI, origin: Vector2I,
mut value: Option<u8>, mut value: Option<u8>,
segment_count: u8) segment_count: u8)
-> Option<u8> { -> Option<u8> {
let widget_width = self.measure_segmented_control(segment_count); 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; let mut clicked_segment = None;
if let Some(position) = self.event_queue.handle_mouse_down_in_rect(widget_rect) { if let Some(position) = self.event_queue.handle_mouse_down_in_rect(widget_rect) {
@ -505,15 +505,15 @@ impl<D> UIPresenter<D> where D: Device {
self.draw_rounded_rect_outline(device, widget_rect, OUTLINE_COLOR); self.draw_rounded_rect_outline(device, widget_rect, OUTLINE_COLOR);
if let Some(value) = value { 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); let x_offset = value as i32 * SEGMENT_SIZE + (value as i32 - 1);
self.draw_solid_rounded_rect(device, self.draw_solid_rounded_rect(device,
RectI::new(origin + Point2DI::new(x_offset, 0), RectI::new(origin + Vector2I::new(x_offset, 0),
highlight_size), highlight_size),
TEXT_COLOR); 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 { for next_segment_index in 1..segment_count {
let prev_segment_index = next_segment_index - 1; let prev_segment_index = next_segment_index - 1;
match value { match value {
@ -521,11 +521,11 @@ impl<D> UIPresenter<D> where D: Device {
_ => { _ => {
self.draw_line(device, self.draw_line(device,
segment_origin, segment_origin,
segment_origin + Point2DI::new(0, BUTTON_HEIGHT), segment_origin + Vector2I::new(0, BUTTON_HEIGHT),
TEXT_COLOR); TEXT_COLOR);
} }
} }
segment_origin = segment_origin + Point2DI::new(SEGMENT_SIZE + 1, 0); segment_origin = segment_origin + Vector2I::new(SEGMENT_SIZE + 1, 0);
} }
clicked_segment clicked_segment
@ -537,13 +537,13 @@ impl<D> UIPresenter<D> where D: Device {
} }
let text_size = self.measure_text(string); let text_size = self.measure_text(string);
let window_size = Point2DI::new(text_size + PADDING * 2, TOOLTIP_HEIGHT); let window_size = Vector2I::new(text_size + PADDING * 2, TOOLTIP_HEIGHT);
let origin = rect.origin() - Point2DI::new(0, window_size.y() + PADDING); 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_solid_rounded_rect(device, RectI::new(origin, window_size), WINDOW_COLOR);
self.draw_text(device, self.draw_text(device,
string, string,
origin + Point2DI::new(PADDING, PADDING + FONT_ASCENT), origin + Vector2I::new(PADDING, PADDING + FONT_ASCENT),
false); false);
} }
} }
@ -668,7 +668,7 @@ struct DebugTextureVertex {
} }
impl DebugTextureVertex { impl DebugTextureVertex {
fn new(position: Point2DI, tex_coord: Point2DI) -> DebugTextureVertex { fn new(position: Vector2I, tex_coord: Vector2I) -> DebugTextureVertex {
DebugTextureVertex { DebugTextureVertex {
position_x: position.x() as i16, position_x: position.x() as i16,
position_y: position.y() as i16, position_y: position.y() as i16,
@ -687,7 +687,7 @@ struct DebugSolidVertex {
} }
impl 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 } 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); let size = device.texture_size(texture);
CornerRects { CornerRects {
upper_left: RectI::new(rect.origin(), size), upper_left: RectI::new(rect.origin(), size),
upper_right: RectI::new(rect.upper_right() - Point2DI::new(size.x(), 0), size), upper_right: RectI::new(rect.upper_right() - Vector2I::new(size.x(), 0), size),
lower_left: RectI::new(rect.lower_left() - Point2DI::new(0, size.y()), size), lower_left: RectI::new(rect.lower_left() - Vector2I::new(0, size.y()), size),
lower_right: RectI::new(rect.lower_right() - size, size), lower_right: RectI::new(rect.lower_right() - size, size),
} }
} }
@ -739,7 +739,7 @@ impl UIEventQueue {
mem::replace(&mut self.events, vec![]) mem::replace(&mut self.events, vec![])
} }
pub fn handle_mouse_down_in_rect(&mut self, rect: RectI) -> Option<Point2DI> { pub fn handle_mouse_down_in_rect(&mut self, rect: RectI) -> Option<Vector2I> {
let (mut remaining_events, mut result) = (vec![], None); let (mut remaining_events, mut result) = (vec![], None);
for event in self.events.drain(..) { for event in self.events.drain(..) {
match event { match event {
@ -753,7 +753,7 @@ impl UIEventQueue {
result result
} }
pub fn handle_mouse_down_or_dragged_in_rect(&mut self, rect: RectI) -> Option<Point2DI> { pub fn handle_mouse_down_or_dragged_in_rect(&mut self, rect: RectI) -> Option<Vector2I> {
let (mut remaining_events, mut result) = (vec![], None); let (mut remaining_events, mut result) = (vec![], None);
for event in self.events.drain(..) { for event in self.events.drain(..) {
match event { match event {
@ -771,8 +771,8 @@ impl UIEventQueue {
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct MousePosition { pub struct MousePosition {
pub absolute: Point2DI, pub absolute: Vector2I,
pub relative: Point2DI, pub relative: Vector2I,
} }
#[derive(Deserialize)] #[derive(Deserialize)]