Change the `F32` and `I32` suffixes to `F` and `I` to match the C API.

They're shorter and less noisy.
This commit is contained in:
Patrick Walton 2019-05-29 19:13:42 -07:00
parent a75b635722
commit e1bcc11ace
40 changed files with 951 additions and 951 deletions

View File

@ -12,8 +12,8 @@
use gl; use gl;
use pathfinder_canvas::{CanvasRenderingContext2D, Path2D}; use pathfinder_canvas::{CanvasRenderingContext2D, Path2D};
use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; use pathfinder_geometry::basic::point::{Point2DF, Point2DI};
use pathfinder_geometry::basic::rect::{RectF32, RectI32}; use pathfinder_geometry::basic::rect::{RectF, RectI};
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, ResourceLoader}; use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader};
@ -296,29 +296,29 @@ impl PFColorF {
impl PFRectF { impl PFRectF {
#[inline] #[inline]
pub fn to_rust(&self) -> RectF32 { pub fn to_rust(&self) -> RectF {
RectF32::from_points(self.origin.to_rust(), self.lower_right.to_rust()) RectF::from_points(self.origin.to_rust(), self.lower_right.to_rust())
} }
} }
impl PFRectI { impl PFRectI {
#[inline] #[inline]
pub fn to_rust(&self) -> RectI32 { pub fn to_rust(&self) -> RectI {
RectI32::from_points(self.origin.to_rust(), self.lower_right.to_rust()) RectI::from_points(self.origin.to_rust(), self.lower_right.to_rust())
} }
} }
impl PFPoint2DF { impl PFPoint2DF {
#[inline] #[inline]
pub fn to_rust(&self) -> Point2DF32 { pub fn to_rust(&self) -> Point2DF {
Point2DF32::new(self.x, self.y) Point2DF::new(self.x, self.y)
} }
} }
impl PFPoint2DI { impl PFPoint2DI {
#[inline] #[inline]
pub fn to_rust(&self) -> Point2DI32 { pub fn to_rust(&self) -> Point2DI {
Point2DI32::new(self.x, self.y) Point2DI::new(self.x, self.y)
} }
} }

View File

@ -14,9 +14,9 @@ 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::point::Point2DF32; use pathfinder_geometry::basic::point::Point2DF;
use pathfinder_geometry::basic::rect::RectF32; use pathfinder_geometry::basic::rect::RectF;
use pathfinder_geometry::basic::transform2d::Transform2DF32; use pathfinder_geometry::basic::transform2d::Transform2DF;
use pathfinder_geometry::color::ColorU; use pathfinder_geometry::color::ColorU;
use pathfinder_geometry::outline::{Contour, Outline}; use pathfinder_geometry::outline::{Contour, Outline};
use pathfinder_geometry::stroke::{LineCap, LineJoin, OutlineStrokeToFill, StrokeStyle}; use pathfinder_geometry::stroke::{LineCap, LineJoin, OutlineStrokeToFill, StrokeStyle};
@ -44,9 +44,9 @@ pub struct CanvasRenderingContext2D {
impl CanvasRenderingContext2D { impl CanvasRenderingContext2D {
#[inline] #[inline]
pub fn new(size: Point2DF32) -> CanvasRenderingContext2D { pub fn new(size: Point2DF) -> CanvasRenderingContext2D {
let mut scene = Scene::new(); let mut scene = Scene::new();
scene.set_view_box(RectF32::new(Point2DF32::default(), size)); scene.set_view_box(RectF::new(Point2DF::default(), size));
CanvasRenderingContext2D::from_scene(scene) CanvasRenderingContext2D::from_scene(scene)
} }
@ -79,23 +79,23 @@ impl CanvasRenderingContext2D {
} }
#[inline] #[inline]
pub fn fill_rect(&mut self, rect: RectF32) { pub fn fill_rect(&mut self, rect: RectF) {
let mut path = Path2D::new(); let mut path = Path2D::new();
path.rect(rect); path.rect(rect);
self.fill_path(path); self.fill_path(path);
} }
#[inline] #[inline]
pub fn stroke_rect(&mut self, rect: RectF32) { pub fn stroke_rect(&mut self, rect: RectF) {
let mut path = Path2D::new(); let mut path = Path2D::new();
path.rect(rect); path.rect(rect);
self.stroke_path(path); self.stroke_path(path);
} }
pub fn fill_text(&mut self, string: &str, position: Point2DF32) { pub fn fill_text(&mut self, string: &str, position: Point2DF) {
// TODO(pcwalton): Report errors. // TODO(pcwalton): Report errors.
let paint_id = self.scene.push_paint(&self.current_state.fill_paint); let paint_id = self.scene.push_paint(&self.current_state.fill_paint);
let transform = Transform2DF32::from_translation(position).post_mul(&self.current_state let transform = Transform2DF::from_translation(position).post_mul(&self.current_state
.transform); .transform);
drop(self.scene.push_text(string, drop(self.scene.push_text(string,
&TextStyle { size: self.current_state.font_size }, &TextStyle { size: self.current_state.font_size },
@ -106,10 +106,10 @@ impl CanvasRenderingContext2D {
paint_id)); paint_id));
} }
pub fn stroke_text(&mut self, string: &str, position: Point2DF32) { pub fn stroke_text(&mut self, string: &str, position: Point2DF) {
// TODO(pcwalton): Report errors. // TODO(pcwalton): Report errors.
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 transform = Transform2DF32::from_translation(position).post_mul(&self.current_state let transform = Transform2DF::from_translation(position).post_mul(&self.current_state
.transform); .transform);
drop(self.scene.push_text(string, drop(self.scene.push_text(string,
&TextStyle { size: self.current_state.font_size }, &TextStyle { size: self.current_state.font_size },
@ -186,18 +186,18 @@ impl CanvasRenderingContext2D {
// Transformations // Transformations
#[inline] #[inline]
pub fn current_transform(&self) -> Transform2DF32 { pub fn current_transform(&self) -> Transform2DF {
self.current_state.transform self.current_state.transform
} }
#[inline] #[inline]
pub fn set_current_transform(&mut self, new_transform: &Transform2DF32) { pub fn set_current_transform(&mut self, new_transform: &Transform2DF) {
self.current_state.transform = *new_transform; self.current_state.transform = *new_transform;
} }
#[inline] #[inline]
pub fn reset_transform(&mut self) { pub fn reset_transform(&mut self) {
self.current_state.transform = Transform2DF32::default(); self.current_state.transform = Transform2DF::default();
} }
// Compositing // Compositing
@ -229,7 +229,7 @@ impl CanvasRenderingContext2D {
#[derive(Clone)] #[derive(Clone)]
pub struct State { pub struct State {
transform: Transform2DF32, transform: Transform2DF,
font_collection: Arc<FontCollection>, font_collection: Arc<FontCollection>,
font_size: f32, font_size: f32,
fill_paint: Paint, fill_paint: Paint,
@ -241,7 +241,7 @@ pub struct State {
impl State { impl State {
fn default(default_font_collection: Arc<FontCollection>) -> State { fn default(default_font_collection: Arc<FontCollection>) -> State {
State { State {
transform: Transform2DF32::default(), transform: Transform2DF::default(),
font_collection: default_font_collection, font_collection: default_font_collection,
font_size: DEFAULT_FONT_SIZE, font_size: DEFAULT_FONT_SIZE,
fill_paint: Paint { color: ColorU::black() }, fill_paint: Paint { color: ColorU::black() },
@ -276,33 +276,33 @@ impl Path2D {
} }
#[inline] #[inline]
pub fn move_to(&mut self, to: Point2DF32) { pub fn move_to(&mut self, to: Point2DF) {
// 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: Point2DF32) { pub fn line_to(&mut self, to: Point2DF) {
self.current_contour.push_endpoint(to); self.current_contour.push_endpoint(to);
} }
#[inline] #[inline]
pub fn quadratic_curve_to(&mut self, ctrl: Point2DF32, to: Point2DF32) { pub fn quadratic_curve_to(&mut self, ctrl: Point2DF, to: Point2DF) {
self.current_contour.push_quadratic(ctrl, to); self.current_contour.push_quadratic(ctrl, to);
} }
#[inline] #[inline]
pub fn bezier_curve_to(&mut self, ctrl0: Point2DF32, ctrl1: Point2DF32, to: Point2DF32) { pub fn bezier_curve_to(&mut self, ctrl0: Point2DF, ctrl1: Point2DF, to: Point2DF) {
self.current_contour.push_cubic(ctrl0, ctrl1, to); self.current_contour.push_cubic(ctrl0, ctrl1, to);
} }
#[inline] #[inline]
pub fn arc(&mut self, center: Point2DF32, radius: f32, start_angle: f32, end_angle: f32) { pub fn arc(&mut self, center: Point2DF, radius: f32, start_angle: f32, end_angle: f32) {
self.current_contour.push_arc(center, radius, start_angle, end_angle); self.current_contour.push_arc(center, radius, start_angle, end_angle);
} }
pub fn rect(&mut self, rect: RectF32) { pub fn rect(&mut self, rect: RectF) {
self.flush_current_contour(); self.flush_current_contour();
self.current_contour.push_endpoint(rect.origin()); self.current_contour.push_endpoint(rect.origin());
self.current_contour.push_endpoint(rect.upper_right()); self.current_contour.push_endpoint(rect.upper_right());

View File

@ -16,8 +16,8 @@ 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::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::rect::RectI;
use pathfinder_gl::GLVersion; use pathfinder_gl::GLVersion;
use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::resources::ResourceLoader;
use std::cell::RefCell; use std::cell::RefCell;
@ -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 = Point2DI32::new(width, height); let logical_size = Point2DI::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: Point2DI32::new(width, height), logical_size: Point2DI::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(Point2DI32::new(x, y))) .push(Event::MouseDown(Point2DI::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(Point2DI32::new(x, y))) .push(Event::MouseDragged(Point2DI::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, Point2DI32::new(center_x, center_y))) .push(Event::Zoom(factor, Point2DI::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: Point2DI32, size: Point2DI,
} }
impl Window for WindowImpl { impl Window for WindowImpl {
@ -196,7 +196,7 @@ impl Window for WindowImpl {
GLVersion::GLES3 GLVersion::GLES3
} }
fn viewport(&self, view: View) -> RectI32 { fn viewport(&self, view: View) -> RectI {
let mut width = self.size.x(); let mut width = self.size.x();
let mut offset_x = 0; let mut offset_x = 0;
let height = self.size.y(); let height = self.size.y();
@ -204,9 +204,9 @@ impl Window for WindowImpl {
width = width / 2; width = width / 2;
offset_x = (index as i32) * width; offset_x = (index as i32) * width;
} }
let size = Point2DI32::new(width, height); let size = Point2DI::new(width, height);
let offset = Point2DI32::new(offset_x, 0); let offset = Point2DI::new(offset_x, 0);
RectI32::new(offset, size) RectI::new(offset, size)
} }
fn make_current(&mut self, _view: View) {} fn make_current(&mut self, _view: View) {}

View File

@ -14,10 +14,10 @@
// proper. // proper.
use crate::window::{OcularTransform, View}; use crate::window::{OcularTransform, View};
use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32, Point3DF32}; use pathfinder_geometry::basic::point::{Point2DF, Point2DI, Point3DF};
use pathfinder_geometry::basic::rect::RectF32; use pathfinder_geometry::basic::rect::RectF;
use pathfinder_geometry::basic::transform2d::Transform2DF32; use pathfinder_geometry::basic::transform2d::Transform2DF;
use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF32}; use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF};
use std::f32::consts::FRAC_PI_4; use std::f32::consts::FRAC_PI_4;
const NEAR_CLIP_PLANE: f32 = 0.01; const NEAR_CLIP_PLANE: f32 = 0.01;
@ -27,7 +27,7 @@ const FAR_CLIP_PLANE: f32 = 10.0;
const DEFAULT_EYE_OFFSET: f32 = 0.025; const DEFAULT_EYE_OFFSET: f32 = 0.025;
pub enum Camera { pub enum Camera {
TwoD(Transform2DF32), TwoD(Transform2DF),
ThreeD { ThreeD {
// The ocular transform used for rendering of the scene to the scene framebuffer. If we are // The ocular transform used for rendering of the scene to the scene framebuffer. If we are
// performing stereoscopic rendering, this is then reprojected according to the eye // performing stereoscopic rendering, this is then reprojected according to the eye
@ -39,12 +39,12 @@ pub enum Camera {
// The modelview transform from world coordinates to SVG coordinates // 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: Point3DF32, velocity: Point3DF,
}, },
} }
impl Camera { impl Camera {
pub fn new(mode: Mode, view_box: RectF32, viewport_size: Point2DI32) -> Camera { pub fn new(mode: Mode, view_box: RectF, viewport_size: Point2DI) -> Camera {
if mode == Mode::TwoD { if mode == Mode::TwoD {
Camera::new_2d(view_box, viewport_size) Camera::new_2d(view_box, viewport_size)
} else { } else {
@ -52,20 +52,20 @@ impl Camera {
} }
} }
fn new_2d(view_box: RectF32, viewport_size: Point2DI32) -> Camera { fn new_2d(view_box: RectF, viewport_size: Point2DI) -> Camera {
let scale = i32::min(viewport_size.x(), viewport_size.y()) as f32 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(Transform2DF32::from_scale(Point2DF32::splat(scale)).post_translate(origin)) Camera::TwoD(Transform2DF::from_scale(Point2DF::splat(scale)).post_translate(origin))
} }
fn new_3d(mode: Mode, view_box: RectF32, viewport_size: Point2DI32) -> Camera { fn new_3d(mode: Mode, view_box: RectF, viewport_size: Point2DI) -> Camera {
let viewport_count = mode.viewport_count(); let viewport_count = mode.viewport_count();
let fov_y = FRAC_PI_4; let fov_y = FRAC_PI_4;
let aspect = viewport_size.x() as f32 / viewport_size.y() as f32; let aspect = viewport_size.x() as f32 / viewport_size.y() as f32;
let projection = let projection =
Transform3DF32::from_perspective(fov_y, aspect, NEAR_CLIP_PLANE, FAR_CLIP_PLANE); Transform3DF::from_perspective(fov_y, aspect, NEAR_CLIP_PLANE, FAR_CLIP_PLANE);
let perspective = Perspective::new(&projection, viewport_size); let perspective = Perspective::new(&projection, viewport_size);
// Create a scene transform by moving the camera back from the center of the eyes so that // Create a scene transform by moving the camera back from the center of the eyes so that
@ -73,7 +73,7 @@ impl Camera {
let z_offset = -DEFAULT_EYE_OFFSET * projection.c0.x(); let z_offset = -DEFAULT_EYE_OFFSET * projection.c0.x();
let scene_transform = OcularTransform { let scene_transform = OcularTransform {
perspective, perspective,
modelview_to_eye: Transform3DF32::from_translation(0.0, 0.0, z_offset), modelview_to_eye: Transform3DF::from_translation(0.0, 0.0, z_offset),
}; };
// For now, initialize the eye transforms as copies of the scene transform. // For now, initialize the eye transforms as copies of the scene transform.
@ -87,7 +87,7 @@ impl Camera {
}; };
OcularTransform { OcularTransform {
perspective, perspective,
modelview_to_eye: Transform3DF32::from_translation(this_eye_offset, 0.0, 0.0), modelview_to_eye: Transform3DF::from_translation(this_eye_offset, 0.0, 0.0),
} }
}) })
.collect(); .collect();
@ -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: Point3DF32::default(), velocity: Point3DF::default(),
} }
} }
@ -120,17 +120,17 @@ impl Camera {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct CameraTransform3D { pub struct CameraTransform3D {
position: Point3DF32, position: Point3DF,
pub yaw: f32, pub yaw: f32,
pub pitch: f32, pub pitch: f32,
scale: f32, scale: f32,
} }
impl CameraTransform3D { impl CameraTransform3D {
fn new(view_box: RectF32) -> 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: Point3DF32::new( position: Point3DF::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,26 +142,26 @@ impl CameraTransform3D {
} }
} }
pub fn offset(&mut self, vector: Point3DF32) -> bool { pub fn offset(&mut self, vector: Point3DF) -> bool {
let update = !vector.is_zero(); let update = !vector.is_zero();
if update { if update {
let rotation = Transform3DF32::from_rotation(-self.yaw, -self.pitch, 0.0); let rotation = Transform3DF::from_rotation(-self.yaw, -self.pitch, 0.0);
self.position = self.position + rotation.transform_point(vector); self.position = self.position + rotation.transform_point(vector);
} }
update update
} }
pub fn to_transform(&self) -> Transform3DF32 { pub fn to_transform(&self) -> Transform3DF {
let mut transform = Transform3DF32::from_rotation(self.yaw, self.pitch, 0.0); let mut transform = Transform3DF::from_rotation(self.yaw, self.pitch, 0.0);
transform = transform.post_mul(&Transform3DF32::from_uniform_scale(2.0 * self.scale)); transform = transform.post_mul(&Transform3DF::from_uniform_scale(2.0 * self.scale));
transform = transform.post_mul(&Transform3DF32::from_translation( transform = transform.post_mul(&Transform3DF::from_translation(
-self.position.x(), -self.position.x(),
-self.position.y(), -self.position.y(),
-self.position.z(), -self.position.z(),
)); ));
// Flip Y. // Flip Y.
transform = transform.post_mul(&Transform3DF32::from_scale(1.0, -1.0, 1.0)); transform = transform.post_mul(&Transform3DF::from_scale(1.0, -1.0, 1.0));
transform transform
} }
@ -190,6 +190,6 @@ impl Mode {
} }
} }
pub fn scale_factor_for_view_box(view_box: RectF32) -> f32 { pub fn scale_factor_for_view_box(view_box: RectF) -> f32 {
1.0 / f32::min(view_box.size().x(), view_box.size().y()) 1.0 / f32::min(view_box.size().x(), view_box.size().y())
} }

View File

@ -19,9 +19,9 @@ 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::{Point2DF32, Point2DI32}; use pathfinder_geometry::basic::point::{Point2DF, Point2DI};
use pathfinder_geometry::basic::rect::RectF32; use pathfinder_geometry::basic::rect::RectF;
use pathfinder_geometry::basic::transform2d::Transform2DF32; use pathfinder_geometry::basic::transform2d::Transform2DF;
use pathfinder_geometry::color::ColorU; use pathfinder_geometry::color::ColorU;
use pathfinder_gl::GLDevice; use pathfinder_gl::GLDevice;
use pathfinder_gpu::Device; use pathfinder_gpu::Device;
@ -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: Point2DI32, last_mouse_position: Point2DI,
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: Point2DI32::default(), last_mouse_position: Point2DI::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]);
Point2DF32::new(x, y).scale(font_size) Point2DF::new(x, y).scale(font_size)
} else { } else {
Point2DF32::default() Point2DF::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(RectF32::new(Point2DF32::default(), self.scene_proxy.set_view_box(RectF::new(Point2DF::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(Point2DF32::splat(scale_delta)); *transform = transform.post_scale(Point2DF::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: Point2DI32) -> MousePosition { fn process_mouse_position(&mut self, new_position: Point2DI) -> MousePosition {
let absolute = new_position.scale(self.window_size.backing_scale_factor as i32); let 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 = Point2DF32::splat(1.0 + CAMERA_ZOOM_AMOUNT_2D); let scale = Point2DF::splat(1.0 + CAMERA_ZOOM_AMOUNT_2D);
let center = center_of_window(&self.window_size); 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 = Point2DF32::splat(1.0 - CAMERA_ZOOM_AMOUNT_2D); let scale = Point2DF::splat(1.0 - CAMERA_ZOOM_AMOUNT_2D);
let center = center_of_window(&self.window_size); let center = center_of_window(&self.window_size);
*transform = transform *transform = transform
.post_translate(-center) .post_translate(-center)
@ -579,7 +579,7 @@ impl<W> DemoApp<W> where W: Window {
} }
UIAction::ZoomActualSize => { UIAction::ZoomActualSize => {
if let Camera::TwoD(ref mut transform) = self.camera { if let Camera::TwoD(ref mut transform) = self.camera {
*transform = Transform2DF32::default(); *transform = Transform2DF::default();
self.dirty = true; self.dirty = true;
} }
} }
@ -729,7 +729,7 @@ fn load_scene(resource_loader: &dyn ResourceLoader, input_path: &SVGPath) -> Bui
BuiltSVG::from_tree(Tree::from_data(&data, &UsvgOptions::default()).unwrap()) BuiltSVG::from_tree(Tree::from_data(&data, &UsvgOptions::default()).unwrap())
} }
fn center_of_window(window_size: &WindowSize) -> Point2DF32 { fn center_of_window(window_size: &WindowSize) -> Point2DF {
window_size.device_size().to_f32().scale(0.5) window_size.device_size().to_f32().scale(0.5)
} }
@ -800,17 +800,17 @@ impl BackgroundColor {
} }
struct SceneMetadata { struct SceneMetadata {
view_box: RectF32, view_box: RectF,
monochrome_color: Option<ColorU>, monochrome_color: Option<ColorU>,
} }
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: Point2DI32) -> SceneMetadata { fn new_clipping_view_box(scene: &mut Scene, viewport_size: Point2DI) -> 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(RectF32::new(Point2DF32::default(), viewport_size.to_f32())); scene.set_view_box(RectF::new(Point2DF::default(), viewport_size.to_f32()));
SceneMetadata { view_box, monochrome_color } SceneMetadata { view_box, monochrome_color }
} }
} }

View File

@ -17,7 +17,7 @@ use image::ColorType;
use pathfinder_geometry::color::{ColorF, ColorU}; use pathfinder_geometry::color::{ColorF, ColorU};
use pathfinder_gpu::{ClearParams, DepthFunc, DepthState, Device, Primitive, RenderState}; use pathfinder_gpu::{ClearParams, DepthFunc, DepthState, Device, Primitive, RenderState};
use pathfinder_gpu::{TextureFormat, UniformData}; use pathfinder_gpu::{TextureFormat, UniformData};
use pathfinder_geometry::basic::transform3d::Transform3DF32; use pathfinder_geometry::basic::transform3d::Transform3DF;
use pathfinder_renderer::gpu::renderer::{DestFramebuffer, RenderMode}; use pathfinder_renderer::gpu::renderer::{DestFramebuffer, RenderMode};
use pathfinder_renderer::gpu_data::RenderCommand; use pathfinder_renderer::gpu_data::RenderCommand;
use pathfinder_renderer::options::RenderTransform; use pathfinder_renderer::options::RenderTransform;
@ -168,7 +168,7 @@ impl<W> DemoApp<W> where W: Window {
let scene_framebuffer = self.scene_framebuffer.as_ref().unwrap(); let scene_framebuffer = self.scene_framebuffer.as_ref().unwrap();
let scene_texture = self.renderer.device.framebuffer_texture(scene_framebuffer); let scene_texture = self.renderer.device.framebuffer_texture(scene_framebuffer);
let quad_scale_transform = Transform3DF32::from_scale( let quad_scale_transform = Transform3DF::from_scale(
self.scene_metadata.view_box.size().x(), self.scene_metadata.view_box.size().x(),
self.scene_metadata.view_box.size().y(), self.scene_metadata.view_box.size().y(),
1.0, 1.0,
@ -220,7 +220,7 @@ impl<W> DemoApp<W> where W: Window {
let ground_scale = self.scene_metadata.view_box.max_x() * 2.0; let ground_scale = self.scene_metadata.view_box.max_x() * 2.0;
let mut base_transform = perspective.transform; let mut base_transform = perspective.transform;
base_transform = base_transform.post_mul(&Transform3DF32::from_translation( base_transform = base_transform.post_mul(&Transform3DF::from_translation(
-0.5 * self.scene_metadata.view_box.max_x(), -0.5 * self.scene_metadata.view_box.max_x(),
self.scene_metadata.view_box.max_y(), self.scene_metadata.view_box.max_y(),
-0.5 * ground_scale, -0.5 * ground_scale,
@ -229,7 +229,7 @@ impl<W> DemoApp<W> where W: Window {
// Fill ground. // Fill ground.
let mut transform = base_transform; let mut transform = base_transform;
transform = transform =
transform.post_mul(&Transform3DF32::from_scale(ground_scale, 1.0, ground_scale)); transform.post_mul(&Transform3DF::from_scale(ground_scale, 1.0, ground_scale));
let device = &self.renderer.device; let device = &self.renderer.device;
device.bind_vertex_array(&self.ground_vertex_array.vertex_array); device.bind_vertex_array(&self.ground_vertex_array.vertex_array);

View File

@ -11,8 +11,8 @@
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::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::rect::RectI;
use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::resources::ResourceLoader;
use pathfinder_gpu::Device; use pathfinder_gpu::Device;
use pathfinder_renderer::gpu::debug::DebugUIPresenter; use pathfinder_renderer::gpu::debug::DebugUIPresenter;
@ -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 = Point2DI32::new(PADDING, bottom - BUTTON_HEIGHT); let mut position = Point2DI::new(PADDING, bottom - BUTTON_HEIGHT);
let button_size = Point2DI32::new(BUTTON_WIDTH, BUTTON_HEIGHT); let button_size = Point2DI::new(BUTTON_WIDTH, BUTTON_HEIGHT);
// Draw text effects button. // Draw text effects button.
if self.show_text_effects { if self.show_text_effects {
@ -167,10 +167,10 @@ where
debug_ui_presenter.ui_presenter.draw_tooltip( debug_ui_presenter.ui_presenter.draw_tooltip(
device, device,
"Text Effects", "Text Effects",
RectI32::new(position, button_size), RectI::new(position, button_size),
); );
} }
position += Point2DI32::new(button_size.x() + PADDING, 0); position += Point2DI::new(button_size.x() + PADDING, 0);
} }
// Draw open button. // Draw open button.
@ -181,8 +181,8 @@ where
} }
debug_ui_presenter.ui_presenter.draw_tooltip(device, debug_ui_presenter.ui_presenter.draw_tooltip(device,
"Open SVG", "Open SVG",
RectI32::new(position, button_size)); RectI::new(position, button_size));
position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0); position += Point2DI::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,
@ -194,13 +194,13 @@ where
debug_ui_presenter.ui_presenter.draw_tooltip( debug_ui_presenter.ui_presenter.draw_tooltip(
device, device,
"Take Screenshot", "Take Screenshot",
RectI32::new(position, button_size), RectI::new(position, button_size),
); );
} }
// 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 += Point2DI32::new(button_size.x() + PADDING, 0); position += Point2DI::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 = Point2DI32::new(mode_switch_width, BUTTON_HEIGHT); let mode_switch_size = Point2DI::new(mode_switch_width, BUTTON_HEIGHT);
debug_ui_presenter.ui_presenter.draw_tooltip( debug_ui_presenter.ui_presenter.draw_tooltip(
device, device,
"2D/3D/VR Mode", "2D/3D/VR Mode",
RectI32::new(position, mode_switch_size), RectI::new(position, mode_switch_size),
); );
position += Point2DI32::new(mode_switch_width + PADDING, 0); position += Point2DI::new(mode_switch_width + PADDING, 0);
// Draw background switch. // Draw background switch.
if debug_ui_presenter.ui_presenter.draw_button(device, if debug_ui_presenter.ui_presenter.draw_button(device,
@ -236,13 +236,13 @@ where
debug_ui_presenter.ui_presenter.draw_tooltip( debug_ui_presenter.ui_presenter.draw_tooltip(
device, device,
"Background Color", "Background Color",
RectI32::new(position, button_size), RectI::new(position, button_size),
); );
} }
// 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 += Point2DI32::new(button_size.x() + PADDING, 0); position += Point2DI::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);
@ -258,10 +258,10 @@ where
if !self.rotate_panel_visible { if !self.rotate_panel_visible {
debug_ui_presenter.ui_presenter.draw_tooltip(device, debug_ui_presenter.ui_presenter.draw_tooltip(device,
"Rotate", "Rotate",
RectI32::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 += Point2DI32::new(BUTTON_WIDTH + PADDING, 0); position += Point2DI::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: Point2DI32, position: Point2DI,
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 =
RectI32::new(position, Point2DI32::new(zoom_segmented_control_width, BUTTON_HEIGHT)); RectI::new(position, Point2DI::new(zoom_segmented_control_width, BUTTON_HEIGHT));
debug_ui_presenter.ui_presenter.draw_tooltip(device, "Zoom", zoom_segmented_control_rect); debug_ui_presenter.ui_presenter.draw_tooltip(device, "Zoom", zoom_segmented_control_rect);
let zoom_textures = &[ let zoom_textures = &[
@ -306,17 +306,17 @@ 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 = Point2DI32::new(PADDING, PADDING); let window_origin = Point2DI::new(PADDING, PADDING);
let window_size = Point2DI32::new(PADDING * 2 + message_size, TOOLTIP_HEIGHT); let window_size = Point2DI::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,
RectI32::new(window_origin, window_size), RectI::new(window_origin, window_size),
WINDOW_COLOR, WINDOW_COLOR,
); );
debug_ui_presenter.ui_presenter.draw_text( debug_ui_presenter.ui_presenter.draw_text(
device, device,
&model.message, &model.message,
window_origin + Point2DI32::new(PADDING, PADDING + FONT_ASCENT), window_origin + Point2DI::new(PADDING, PADDING + FONT_ASCENT),
false, false,
); );
} }
@ -333,9 +333,9 @@ where
let effects_panel_y = bottom - (BUTTON_HEIGHT + PADDING + EFFECTS_PANEL_HEIGHT); let effects_panel_y = bottom - (BUTTON_HEIGHT + PADDING + EFFECTS_PANEL_HEIGHT);
debug_ui_presenter.ui_presenter.draw_solid_rounded_rect( debug_ui_presenter.ui_presenter.draw_solid_rounded_rect(
device, device,
RectI32::new( RectI::new(
Point2DI32::new(PADDING, effects_panel_y), Point2DI::new(PADDING, effects_panel_y),
Point2DI32::new(EFFECTS_PANEL_WIDTH, EFFECTS_PANEL_HEIGHT), Point2DI::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 = Point2DI32::new(panel_x, panel_y); let panel_position = Point2DI::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,
RectI32::new( RectI::new(
panel_position, panel_position,
Point2DI32::new(SCREENSHOT_PANEL_WIDTH, SCREENSHOT_PANEL_HEIGHT), Point2DI::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 = Point2DI32::new(panel_x, panel_y); let panel_position = Point2DI::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,
RectI32::new( RectI::new(
panel_position, panel_position,
Point2DI32::new(BACKGROUND_PANEL_WIDTH, BACKGROUND_PANEL_HEIGHT), Point2DI::new(BACKGROUND_PANEL_WIDTH, BACKGROUND_PANEL_HEIGHT),
), ),
WINDOW_COLOR, WINDOW_COLOR,
); );
@ -472,18 +472,18 @@ 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 = Point2DI32::new(rotate_panel_x, rotate_panel_y); let rotate_panel_origin = Point2DI::new(rotate_panel_x, rotate_panel_y);
let rotate_panel_size = Point2DI32::new(ROTATE_PANEL_WIDTH, ROTATE_PANEL_HEIGHT); let rotate_panel_size = Point2DI::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,
RectI32::new(rotate_panel_origin, rotate_panel_size), RectI::new(rotate_panel_origin, rotate_panel_size),
WINDOW_COLOR, WINDOW_COLOR,
); );
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 = RectI32::new( let widget_rect = RectI::new(
Point2DI32::new(widget_x, widget_y), Point2DI::new(widget_x, widget_y),
Point2DI32::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT), Point2DI::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT),
); );
if let Some(position) = debug_ui_presenter if let Some(position) = debug_ui_presenter
.ui_presenter .ui_presenter
@ -496,18 +496,18 @@ 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 = RectI32::new( let slider_track_rect = RectI::new(
Point2DI32::new(widget_x, slider_track_y), Point2DI::new(widget_x, slider_track_y),
Point2DI32::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT), Point2DI::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT),
); );
debug_ui_presenter debug_ui_presenter
.ui_presenter .ui_presenter
.draw_rect_outline(device, slider_track_rect, TEXT_COLOR); .draw_rect_outline(device, slider_track_rect, TEXT_COLOR);
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 = RectI32::new( let slider_knob_rect = RectI::new(
Point2DI32::new(slider_knob_x, widget_y), Point2DI::new(slider_knob_x, widget_y),
Point2DI32::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT), Point2DI::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,15 +518,15 @@ 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: Point2DI32, panel_position: Point2DI,
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 = Point2DI32::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); let widget_size = Point2DI::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT);
let widget_origin = panel_position + Point2DI32::new(0, widget_size.y() * index); let widget_origin = panel_position + Point2DI::new(0, widget_size.y() * index);
let widget_rect = RectI32::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) {
// FIXME(pcwalton): This is not sufficient for Android, where we will need to take in // FIXME(pcwalton): This is not sufficient for Android, where we will need to take in
@ -543,15 +543,15 @@ where
device: &D, device: &D,
debug_ui_presenter: &mut DebugUIPresenter<D>, debug_ui_presenter: &mut DebugUIPresenter<D>,
color: BackgroundColor, color: BackgroundColor,
panel_position: Point2DI32, panel_position: Point2DI,
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 = Point2DI32::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); let widget_size = Point2DI::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT);
let widget_origin = panel_position + Point2DI32::new(0, widget_size.y() * index); let widget_origin = panel_position + Point2DI::new(0, widget_size.y() * index);
let widget_rect = RectI32::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;
if self.draw_menu_item(device, debug_ui_presenter, text, widget_rect, selected) { if self.draw_menu_item(device, debug_ui_presenter, text, widget_rect, selected) {
@ -564,7 +564,7 @@ where
device: &D, device: &D,
debug_ui_presenter: &mut DebugUIPresenter<D>, debug_ui_presenter: &mut DebugUIPresenter<D>,
text: &str, text: &str,
widget_rect: RectI32, widget_rect: RectI,
selected: bool) selected: bool)
-> bool { -> bool {
if selected { if selected {
@ -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() + Point2DI32::new(text_x, text_y); let text_position = widget_rect.origin() + Point2DI::new(text_x, text_y);
debug_ui_presenter.ui_presenter.draw_text(device, text, text_position, selected); debug_ui_presenter.ui_presenter.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, Point2DI32::new(text_x, text_y), false); .draw_text(device, text, Point2DI::new(text_x, text_y), false);
let switch_width = debug_ui_presenter.ui_presenter.measure_segmented_control(2); let switch_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 = Point2DI32::new(switch_x, switch_y); let switch_position = Point2DI::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,9 +11,9 @@
//! 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::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::rect::RectI;
use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF32}; use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF};
use pathfinder_gl::GLVersion; use pathfinder_gl::GLVersion;
use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::resources::ResourceLoader;
use rayon::ThreadPoolBuilder; use rayon::ThreadPoolBuilder;
@ -25,7 +25,7 @@ pub trait Window {
0 0
} }
fn viewport(&self, view: View) -> RectI32; fn viewport(&self, view: View) -> RectI;
fn make_current(&mut self, view: View); fn make_current(&mut self, view: View);
fn present(&mut self); fn present(&mut self);
fn resource_loader(&self) -> &dyn ResourceLoader; fn resource_loader(&self) -> &dyn ResourceLoader;
@ -42,10 +42,10 @@ pub enum Event {
WindowResized(WindowSize), WindowResized(WindowSize),
KeyDown(Keycode), KeyDown(Keycode),
KeyUp(Keycode), KeyUp(Keycode),
MouseDown(Point2DI32), MouseDown(Point2DI),
MouseMoved(Point2DI32), MouseMoved(Point2DI),
MouseDragged(Point2DI32), MouseDragged(Point2DI),
Zoom(f32, Point2DI32), Zoom(f32, Point2DI),
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: Point2DI32, pub logical_size: Point2DI,
pub backing_scale_factor: f32, pub backing_scale_factor: f32,
} }
impl WindowSize { impl WindowSize {
#[inline] #[inline]
pub fn device_size(&self) -> Point2DI32 { pub fn device_size(&self) -> Point2DI {
self.logical_size self.logical_size
.to_f32() .to_f32()
.scale(self.backing_scale_factor) .scale(self.backing_scale_factor)
@ -93,7 +93,7 @@ pub struct OcularTransform {
pub perspective: Perspective, pub perspective: Perspective,
// The view transform which converts from world coordinates to camera coordinates // The view transform which converts from world coordinates to camera coordinates
pub modelview_to_eye: Transform3DF32, pub modelview_to_eye: Transform3DF,
} }
#[derive(Clone)] #[derive(Clone)]

View File

@ -13,8 +13,8 @@
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::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
use pathfinder_geometry::basic::rect::RectI32; 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};
use sdl2::event::{Event as SDLEvent, WindowEvent}; use sdl2::event::{Event as SDLEvent, WindowEvent};
@ -83,7 +83,7 @@ impl Window for WindowImpl {
GLVersion::GL3 GLVersion::GL3
} }
fn viewport(&self, view: View) -> RectI32 { fn viewport(&self, view: View) -> RectI {
let (width, height) = self.window.drawable_size(); let (width, height) = self.window.drawable_size();
let mut width = width as i32; let mut width = width as i32;
let height = height as i32; let height = height as i32;
@ -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);
} }
RectI32::new(Point2DI32::new(x_offset, 0), Point2DI32::new(width, height)) RectI::new(Point2DI::new(x_offset, 0), Point2DI::new(width, height))
} }
fn make_current(&mut self, _view: View) { 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: Point2DI32::new(logical_width as i32, logical_height as i32), logical_size: Point2DI::new(logical_width as i32, logical_height as i32),
backing_scale_factor: drawable_width as f32 / logical_width as f32, 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(Point2DI32::new(x, y))), SDLEvent::MouseButtonDown { x, y, .. } => Some(Event::MouseDown(Point2DI::new(x, y))),
SDLEvent::MouseMotion { SDLEvent::MouseMotion {
x, y, mousestate, .. x, y, mousestate, ..
} => { } => {
let position = Point2DI32::new(x, y); let position = Point2DI::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 = Point2DI32::new(mouse_state.x(), mouse_state.y()); let center = Point2DI::new(mouse_state.x(), mouse_state.y());
Some(Event::Zoom(d_dist, center)) Some(Event::Zoom(d_dist, center))
} }
_ => None, _ => None,

View File

@ -9,8 +9,8 @@
// except according to those terms. // except according to those terms.
use pathfinder_canvas::{CanvasRenderingContext2D, Path2D}; use pathfinder_canvas::{CanvasRenderingContext2D, Path2D};
use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; use pathfinder_geometry::basic::point::{Point2DF, Point2DI};
use pathfinder_geometry::basic::rect::RectF32; use pathfinder_geometry::basic::rect::RectF;
use pathfinder_geometry::color::ColorF; use pathfinder_geometry::color::ColorF;
use pathfinder_geometry::stroke::LineJoin; use pathfinder_geometry::stroke::LineJoin;
use pathfinder_gl::{GLDevice, GLVersion}; use pathfinder_gl::{GLDevice, GLVersion};
@ -35,7 +35,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 = Point2DI32::new(640, 480); let window_size = Point2DI::new(640, 480);
let window = video.window("Minimal example", window_size.x() as u32, window_size.y() as u32) let window = video.window("Minimal example", window_size.x() as u32, window_size.y() as u32)
.opengl() .opengl()
.build() .build()
@ -61,16 +61,16 @@ fn main() {
canvas.set_line_width(10.0); canvas.set_line_width(10.0);
// Draw walls. // Draw walls.
canvas.stroke_rect(RectF32::new(Point2DF32::new(75.0, 140.0), Point2DF32::new(150.0, 110.0))); canvas.stroke_rect(RectF::new(Point2DF::new(75.0, 140.0), Point2DF::new(150.0, 110.0)));
// Draw door. // Draw door.
canvas.fill_rect(RectF32::new(Point2DF32::new(130.0, 190.0), Point2DF32::new(40.0, 60.0))); canvas.fill_rect(RectF::new(Point2DF::new(130.0, 190.0), Point2DF::new(40.0, 60.0)));
// Draw roof. // Draw roof.
let mut path = Path2D::new(); let mut path = Path2D::new();
path.move_to(Point2DF32::new(50.0, 140.0)); path.move_to(Point2DF::new(50.0, 140.0));
path.line_to(Point2DF32::new(150.0, 60.0)); path.line_to(Point2DF::new(150.0, 60.0));
path.line_to(Point2DF32::new(250.0, 140.0)); path.line_to(Point2DF::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::{CanvasRenderingContext2D, FillStyle, Path2D}; use pathfinder_canvas::{CanvasRenderingContext2D, FillStyle, Path2D};
use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; use pathfinder_geometry::basic::point::{Point2DF, Point2DI};
use pathfinder_geometry::color::{ColorF, ColorU}; use pathfinder_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 = Point2DI32::new(1067, 800); let window_size = Point2DI::new(1067, 800);
let window = video.window("Moire example", window_size.x() as u32, window_size.y() as u32) 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 = Point2DI32::new(drawable_width as i32, drawable_height as i32); let drawable_size = Point2DI::new(drawable_width as i32, drawable_height as i32);
// Create the GL context, and make it current. // Create the GL context, and make it current.
let gl_context = window.gl_create_context().unwrap(); let gl_context = window.gl_create_context().unwrap();
@ -87,14 +87,14 @@ struct MoireRenderer {
renderer: Renderer<GLDevice>, renderer: Renderer<GLDevice>,
scene: SceneProxy, scene: SceneProxy,
frame: i32, frame: i32,
window_size: Point2DI32, window_size: Point2DI,
drawable_size: Point2DI32, drawable_size: Point2DI,
device_pixel_ratio: f32, device_pixel_ratio: f32,
colors: ColorGradient, colors: ColorGradient,
} }
impl MoireRenderer { impl MoireRenderer {
fn new(renderer: Renderer<GLDevice>, window_size: Point2DI32, drawable_size: Point2DI32) fn new(renderer: Renderer<GLDevice>, window_size: Point2DI, drawable_size: Point2DI)
-> MoireRenderer { -> MoireRenderer {
MoireRenderer { MoireRenderer {
renderer, renderer,
@ -117,9 +117,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 + Point2DF32::new(sin_time, cos_time).scale(OUTER_RADIUS); let outer_center = window_center + Point2DF::new(sin_time, cos_time).scale(OUTER_RADIUS);
let inner_center = window_center + let inner_center = window_center +
Point2DF32::new(1.0, sin_time).scale(cos_time * INNER_RADIUS); Point2DF::new(1.0, sin_time).scale(cos_time * INNER_RADIUS);
// Clear to background color. // Clear to background color.
self.renderer.device.clear(&ClearParams { self.renderer.device.clear(&ClearParams {
@ -144,7 +144,7 @@ impl MoireRenderer {
self.frame += 1; self.frame += 1;
} }
fn draw_circles(&self, canvas: &mut CanvasRenderingContext2D, center: Point2DF32) { fn draw_circles(&self, canvas: &mut CanvasRenderingContext2D, center: Point2DF) {
let center = center.scale(self.device_pixel_ratio); 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;

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
use pathfinder_canvas::CanvasRenderingContext2D; use pathfinder_canvas::CanvasRenderingContext2D;
use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; use pathfinder_geometry::basic::point::{Point2DF, Point2DI};
use pathfinder_geometry::color::ColorF; use pathfinder_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 = Point2DI32::new(640, 480); let window_size = Point2DI::new(640, 480);
let window = video.window("Text example", window_size.x() as u32, window_size.y() as u32) let window = video.window("Text example", window_size.x() as u32, window_size.y() as u32)
.opengl() .opengl()
.build() .build()
@ -57,8 +57,8 @@ 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!", Point2DF32::new(32.0, 48.0)); canvas.fill_text("Hello Pathfinder!", Point2DF::new(32.0, 48.0));
canvas.stroke_text("Goodbye Pathfinder!", Point2DF32::new(32.0, 96.0)); canvas.stroke_text("Goodbye Pathfinder!", Point2DF::new(32.0, 96.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::Point2DF32; use crate::basic::point::Point2DF;
use crate::basic::transform2d::Matrix2x2F32; 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 LineSegmentF32(pub F32x4); pub struct LineSegmentF(pub F32x4);
impl LineSegmentF32 { impl LineSegmentF {
#[inline] #[inline]
pub fn new(from: Point2DF32, to: Point2DF32) -> LineSegmentF32 { pub fn new(from: Point2DF, to: Point2DF) -> LineSegmentF {
LineSegmentF32(from.0.concat_xy_xy(to.0)) LineSegmentF(from.0.concat_xy_xy(to.0))
} }
#[inline] #[inline]
pub fn from(&self) -> Point2DF32 { pub fn from(&self) -> Point2DF {
Point2DF32(self.0) Point2DF(self.0)
} }
#[inline] #[inline]
pub fn to(&self) -> Point2DF32 { pub fn to(&self) -> Point2DF {
Point2DF32(self.0.zwxy()) Point2DF(self.0.zwxy())
} }
#[inline] #[inline]
pub fn set_from(&mut self, point: &Point2DF32) { pub fn set_from(&mut self, point: &Point2DF) {
self.0 = point.0.concat_xy_zw(self.0) self.0 = point.0.concat_xy_zw(self.0)
} }
#[inline] #[inline]
pub fn set_to(&mut self, point: &Point2DF32) { pub fn set_to(&mut self, point: &Point2DF) {
self.0 = self.0.concat_xy_xy(point.0) self.0 = self.0.concat_xy_xy(point.0)
} }
@ -88,30 +88,30 @@ impl LineSegmentF32 {
} }
#[inline] #[inline]
pub fn translate(&self, offset: Point2DF32) -> LineSegmentF32 { pub fn translate(&self, offset: Point2DF) -> LineSegmentF {
LineSegmentF32(self.0 + offset.0.xyxy()) LineSegmentF(self.0 + offset.0.xyxy())
} }
#[inline] #[inline]
pub fn scale(&self, factor: f32) -> LineSegmentF32 { pub fn scale(&self, factor: f32) -> LineSegmentF {
LineSegmentF32(self.0 * F32x4::splat(factor)) LineSegmentF(self.0 * F32x4::splat(factor))
} }
#[inline] #[inline]
pub fn split(&self, t: f32) -> (LineSegmentF32, LineSegmentF32) { pub fn split(&self, t: f32) -> (LineSegmentF, LineSegmentF) {
debug_assert!(t >= 0.0 && t <= 1.0); 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);
( (
LineSegmentF32(from_from.concat_xy_xy(mid_mid)), LineSegmentF(from_from.concat_xy_xy(mid_mid)),
LineSegmentF32(mid_mid.concat_xy_xy(to_to)), LineSegmentF(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) -> (LineSegmentF32, LineSegmentF32) { pub fn split_at_x(&self, x: f32) -> (LineSegmentF, LineSegmentF) {
let (min_part, max_part) = self.split(self.solve_t_for_x(x)); 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)
@ -122,7 +122,7 @@ impl LineSegmentF32 {
// 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) -> (LineSegmentF32, LineSegmentF32) { pub fn split_at_y(&self, y: f32) -> (LineSegmentF, LineSegmentF) {
let (min_part, max_part) = self.split(self.solve_t_for_y(y)); 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
@ -155,12 +155,12 @@ impl LineSegmentF32 {
} }
#[inline] #[inline]
pub fn reversed(&self) -> LineSegmentF32 { pub fn reversed(&self) -> LineSegmentF {
LineSegmentF32(self.0.zwxy()) LineSegmentF(self.0.zwxy())
} }
#[inline] #[inline]
pub fn upper_point(&self) -> Point2DF32 { pub fn upper_point(&self) -> Point2DF {
if self.from_y() < self.to_y() { if self.from_y() < self.to_y() {
self.from() self.from()
} else { } else {
@ -200,7 +200,7 @@ impl LineSegmentF32 {
// 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) -> LineSegmentF32 { pub fn orient(&self, y_winding: i32) -> LineSegmentF {
if y_winding >= 0 { if y_winding >= 0 {
*self *self
} else { } else {
@ -227,14 +227,14 @@ impl LineSegmentF32 {
} }
#[inline] #[inline]
pub fn vector(&self) -> Point2DF32 { pub fn vector(&self) -> Point2DF {
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: &LineSegmentF32) -> Option<f32> { pub fn intersection_t(&self, other: &LineSegmentF) -> Option<f32> {
let p0p1 = self.vector(); let p0p1 = self.vector();
let matrix = Matrix2x2F32(other.vector().0.concat_xy_xy((-p0p1).0)); let matrix = Matrix2x2F(other.vector().0.concat_xy_xy((-p0p1).0));
if f32::abs(matrix.det()) < EPSILON { if f32::abs(matrix.det()) < EPSILON {
return None; return None;
} }
@ -244,12 +244,12 @@ impl LineSegmentF32 {
} }
#[inline] #[inline]
pub fn sample(&self, t: f32) -> Point2DF32 { pub fn sample(&self, t: f32) -> Point2DF {
self.from() + self.vector().scale(t) self.from() + self.vector().scale(t)
} }
#[inline] #[inline]
pub fn offset(&self, distance: f32) -> LineSegmentF32 { pub fn offset(&self, distance: f32) -> LineSegmentF {
if self.is_zero_length() { if self.is_zero_length() {
*self *self
} else { } else {
@ -258,7 +258,7 @@ impl LineSegmentF32 {
.vector() .vector()
.yx() .yx()
.normalize() .normalize()
.scale_xy(Point2DF32::new(-distance, distance)) .scale_xy(Point2DF::new(-distance, distance))
} }
} }
@ -268,19 +268,19 @@ impl LineSegmentF32 {
} }
} }
impl Add<Point2DF32> for LineSegmentF32 { impl Add<Point2DF> for LineSegmentF {
type Output = LineSegmentF32; type Output = LineSegmentF;
#[inline] #[inline]
fn add(self, point: Point2DF32) -> LineSegmentF32 { fn add(self, point: Point2DF) -> LineSegmentF {
LineSegmentF32(self.0 + point.0.xyxy()) LineSegmentF(self.0 + point.0.xyxy())
} }
} }
impl Sub<Point2DF32> for LineSegmentF32 { impl Sub<Point2DF> for LineSegmentF {
type Output = LineSegmentF32; type Output = LineSegmentF;
#[inline] #[inline]
fn sub(self, point: Point2DF32) -> LineSegmentF32 { fn sub(self, point: Point2DF) -> LineSegmentF {
LineSegmentF32(self.0 - point.0.xyxy()) LineSegmentF(self.0 - point.0.xyxy())
} }
} }

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

View File

@ -10,50 +10,50 @@
//! 2D axis-aligned rectangles, optimized with SIMD. //! 2D axis-aligned rectangles, optimized with SIMD.
use crate::basic::point::{Point2DF32, Point2DI32}; use crate::basic::point::{Point2DF, Point2DI};
use pathfinder_simd::default::{F32x4, I32x4}; use pathfinder_simd::default::{F32x4, I32x4};
#[derive(Clone, Copy, Debug, PartialEq, Default)] #[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct RectF32(pub F32x4); pub struct RectF(pub F32x4);
impl RectF32 { impl RectF {
#[inline] #[inline]
pub fn new(origin: Point2DF32, size: Point2DF32) -> RectF32 { pub fn new(origin: Point2DF, size: Point2DF) -> RectF {
RectF32(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: Point2DF32, lower_right: Point2DF32) -> RectF32 { pub fn from_points(origin: Point2DF, lower_right: Point2DF) -> RectF {
RectF32(origin.0.concat_xy_xy(lower_right.0)) RectF(origin.0.concat_xy_xy(lower_right.0))
} }
#[inline] #[inline]
pub fn origin(&self) -> Point2DF32 { pub fn origin(&self) -> Point2DF {
Point2DF32(self.0) Point2DF(self.0)
} }
#[inline] #[inline]
pub fn size(&self) -> Point2DF32 { pub fn size(&self) -> Point2DF {
Point2DF32(self.0.zwxy() - self.0.xyxy()) Point2DF(self.0.zwxy() - self.0.xyxy())
} }
#[inline] #[inline]
pub fn upper_right(&self) -> Point2DF32 { pub fn upper_right(&self) -> Point2DF {
Point2DF32(self.0.zyxw()) Point2DF(self.0.zyxw())
} }
#[inline] #[inline]
pub fn lower_left(&self) -> Point2DF32 { pub fn lower_left(&self) -> Point2DF {
Point2DF32(self.0.xwzy()) Point2DF(self.0.xwzy())
} }
#[inline] #[inline]
pub fn lower_right(&self) -> Point2DF32 { pub fn lower_right(&self) -> Point2DF {
Point2DF32(self.0.zwxy()) Point2DF(self.0.zwxy())
} }
#[inline] #[inline]
pub fn contains_point(&self, point: Point2DF32) -> bool { pub fn contains_point(&self, point: Point2DF) -> bool {
// self.origin <= point && point <= self.lower_right // self.origin <= point && point <= self.lower_right
self.0 self.0
.concat_xy_xy(point.0) .concat_xy_xy(point.0)
@ -62,7 +62,7 @@ impl RectF32 {
} }
#[inline] #[inline]
pub fn contains_rect(&self, other: RectF32) -> bool { pub fn contains_rect(&self, other: RectF) -> bool {
// self.origin <= other.origin && other.lower_right <= self.lower_right // self.origin <= other.origin && other.lower_right <= self.lower_right
self.0 self.0
.concat_xy_zw(other.0) .concat_xy_zw(other.0)
@ -76,20 +76,20 @@ impl RectF32 {
} }
#[inline] #[inline]
pub fn union_point(&self, point: Point2DF32) -> RectF32 { pub fn union_point(&self, point: Point2DF) -> RectF {
RectF32::from_points(self.origin().min(point), self.lower_right().max(point)) RectF::from_points(self.origin().min(point), self.lower_right().max(point))
} }
#[inline] #[inline]
pub fn union_rect(&self, other: RectF32) -> RectF32 { pub fn union_rect(&self, other: RectF) -> RectF {
RectF32::from_points( RectF::from_points(
self.origin().min(other.origin()), self.origin().min(other.origin()),
self.lower_right().max(other.lower_right()), self.lower_right().max(other.lower_right()),
) )
} }
#[inline] #[inline]
pub fn intersects(&self, other: RectF32) -> bool { pub fn intersects(&self, other: RectF) -> bool {
// self.origin < other.lower_right && other.origin < self.lower_right // self.origin < other.lower_right && other.origin < self.lower_right
self.0 self.0
.concat_xy_xy(other.0) .concat_xy_xy(other.0)
@ -98,11 +98,11 @@ impl RectF32 {
} }
#[inline] #[inline]
pub fn intersection(&self, other: RectF32) -> Option<RectF32> { pub fn intersection(&self, other: RectF) -> Option<RectF> {
if !self.intersects(other) { if !self.intersects(other) {
None None
} else { } else {
Some(RectF32::from_points( Some(RectF::from_points(
self.origin().max(other.origin()), self.origin().max(other.origin()),
self.lower_right().min(other.lower_right()), self.lower_right().min(other.lower_right()),
)) ))
@ -130,63 +130,63 @@ impl RectF32 {
} }
#[inline] #[inline]
pub fn scale_xy(self, factors: Point2DF32) -> RectF32 { pub fn scale_xy(self, factors: Point2DF) -> RectF {
RectF32(self.0 * factors.0.concat_xy_xy(factors.0)) RectF(self.0 * factors.0.concat_xy_xy(factors.0))
} }
#[inline] #[inline]
pub fn round_out(self) -> RectF32 { pub fn round_out(self) -> RectF {
RectF32::from_points(self.origin().floor(), self.lower_right().ceil()) RectF::from_points(self.origin().floor(), self.lower_right().ceil())
} }
#[inline] #[inline]
pub fn dilate(self, amount: Point2DF32) -> RectF32 { pub fn dilate(self, amount: Point2DF) -> RectF {
RectF32::from_points(self.origin() - amount, self.lower_right() + amount) RectF::from_points(self.origin() - amount, self.lower_right() + amount)
} }
#[inline] #[inline]
pub fn to_i32(&self) -> RectI32 { pub fn to_i32(&self) -> RectI {
RectI32(self.0.to_i32x4()) RectI(self.0.to_i32x4())
} }
} }
#[derive(Clone, Copy, Debug, PartialEq, Default)] #[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct RectI32(pub I32x4); pub struct RectI(pub I32x4);
impl RectI32 { impl RectI {
#[inline] #[inline]
pub fn new(origin: Point2DI32, size: Point2DI32) -> RectI32 { pub fn new(origin: Point2DI, size: Point2DI) -> RectI {
RectI32(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: Point2DI32, lower_right: Point2DI32) -> RectI32 { pub fn from_points(origin: Point2DI, lower_right: Point2DI) -> RectI {
RectI32(origin.0.concat_xy_xy(lower_right.0)) RectI(origin.0.concat_xy_xy(lower_right.0))
} }
#[inline] #[inline]
pub fn origin(&self) -> Point2DI32 { pub fn origin(&self) -> Point2DI {
Point2DI32(self.0) Point2DI(self.0)
} }
#[inline] #[inline]
pub fn size(&self) -> Point2DI32 { pub fn size(&self) -> Point2DI {
Point2DI32(self.0.zwxy() - self.0.xyxy()) Point2DI(self.0.zwxy() - self.0.xyxy())
} }
#[inline] #[inline]
pub fn upper_right(&self) -> Point2DI32 { pub fn upper_right(&self) -> Point2DI {
Point2DI32(self.0.zyxw()) Point2DI(self.0.zyxw())
} }
#[inline] #[inline]
pub fn lower_left(&self) -> Point2DI32 { pub fn lower_left(&self) -> Point2DI {
Point2DI32(self.0.xwzy()) Point2DI(self.0.xwzy())
} }
#[inline] #[inline]
pub fn lower_right(&self) -> Point2DI32 { pub fn lower_right(&self) -> Point2DI {
Point2DI32(self.0.zwxy()) Point2DI(self.0.zwxy())
} }
#[inline] #[inline]
@ -210,9 +210,9 @@ impl RectI32 {
} }
#[inline] #[inline]
pub fn contains_point(&self, point: Point2DI32) -> bool { pub fn contains_point(&self, point: Point2DI) -> bool {
// self.origin <= point && point <= self.lower_right - 1 // self.origin <= point && point <= self.lower_right - 1
let lower_right = self.lower_right() - Point2DI32::splat(1); let lower_right = self.lower_right() - Point2DI::splat(1);
self.0 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))
@ -220,7 +220,7 @@ impl RectI32 {
} }
#[inline] #[inline]
pub fn to_f32(&self) -> RectF32 { pub fn to_f32(&self) -> RectF {
RectF32(self.0.to_f32x4()) RectF(self.0.to_f32x4())
} }
} }

View File

@ -10,10 +10,10 @@
//! 2D affine transforms. //! 2D affine transforms.
use crate::basic::line_segment::LineSegmentF32; use crate::basic::line_segment::LineSegmentF;
use crate::basic::point::Point2DF32; use crate::basic::point::Point2DF;
use crate::basic::rect::RectF32; use crate::basic::rect::RectF;
use crate::basic::transform3d::Transform3DF32; use crate::basic::transform3d::Transform3DF;
use crate::segment::Segment; use crate::segment::Segment;
use crate::unit_vector::UnitVector; use crate::unit_vector::UnitVector;
use pathfinder_simd::default::F32x4; use pathfinder_simd::default::F32x4;
@ -21,60 +21,60 @@ use std::ops::Sub;
/// A 2x2 matrix, optimized with SIMD, in column-major order. /// A 2x2 matrix, optimized with SIMD, in column-major order.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub struct Matrix2x2F32(pub F32x4); pub struct Matrix2x2F(pub F32x4);
impl Default for Matrix2x2F32 { impl Default for Matrix2x2F {
#[inline] #[inline]
fn default() -> Matrix2x2F32 { fn default() -> Matrix2x2F {
Self::from_scale(Point2DF32::splat(1.0)) Self::from_scale(Point2DF::splat(1.0))
} }
} }
impl Matrix2x2F32 { impl Matrix2x2F {
#[inline] #[inline]
pub fn from_scale(scale: Point2DF32) -> Matrix2x2F32 { pub fn from_scale(scale: Point2DF) -> Matrix2x2F {
Matrix2x2F32(F32x4::new(scale.x(), 0.0, 0.0, scale.y())) Matrix2x2F(F32x4::new(scale.x(), 0.0, 0.0, scale.y()))
} }
#[inline] #[inline]
pub fn from_rotation(theta: f32) -> Matrix2x2F32 { pub fn from_rotation(theta: f32) -> Matrix2x2F {
Matrix2x2F32::from_rotation_vector(UnitVector::from_angle(theta)) Matrix2x2F::from_rotation_vector(UnitVector::from_angle(theta))
} }
#[inline] #[inline]
pub fn from_rotation_vector(vector: UnitVector) -> Matrix2x2F32 { pub fn from_rotation_vector(vector: UnitVector) -> Matrix2x2F {
Matrix2x2F32((vector.0).0.xyyx() * F32x4::new(1.0, 1.0, -1.0, 1.0)) Matrix2x2F((vector.0).0.xyyx() * F32x4::new(1.0, 1.0, -1.0, 1.0))
} }
#[inline] #[inline]
pub fn row_major(m11: f32, m12: f32, m21: f32, m22: f32) -> Matrix2x2F32 { pub fn row_major(m11: f32, m12: f32, m21: f32, m22: f32) -> Matrix2x2F {
Matrix2x2F32(F32x4::new(m11, m21, m12, m22)) Matrix2x2F(F32x4::new(m11, m21, m12, m22))
} }
#[inline] #[inline]
pub fn post_mul(&self, other: &Matrix2x2F32) -> Matrix2x2F32 { pub fn post_mul(&self, other: &Matrix2x2F) -> Matrix2x2F {
Matrix2x2F32(self.0.xyxy() * other.0.xxzz() + self.0.zwzw() * other.0.yyww()) Matrix2x2F(self.0.xyxy() * other.0.xxzz() + self.0.zwzw() * other.0.yyww())
} }
#[inline] #[inline]
pub fn pre_mul(&self, other: &Matrix2x2F32) -> Matrix2x2F32 { pub fn pre_mul(&self, other: &Matrix2x2F) -> Matrix2x2F {
other.post_mul(self) other.post_mul(self)
} }
#[inline] #[inline]
pub fn entrywise_mul(&self, other: &Matrix2x2F32) -> Matrix2x2F32 { pub fn entrywise_mul(&self, other: &Matrix2x2F) -> Matrix2x2F {
Matrix2x2F32(self.0 * other.0) Matrix2x2F(self.0 * other.0)
} }
#[inline] #[inline]
pub fn adjugate(&self) -> Matrix2x2F32 { pub fn adjugate(&self) -> Matrix2x2F {
Matrix2x2F32(self.0.wyzx() * F32x4::new(1.0, -1.0, -1.0, 1.0)) Matrix2x2F(self.0.wyzx() * F32x4::new(1.0, -1.0, -1.0, 1.0))
} }
#[inline] #[inline]
pub fn transform_point(&self, point: Point2DF32) -> Point2DF32 { pub fn transform_point(&self, point: Point2DF) -> Point2DF {
let halves = self.0 * point.0.xxyy(); let halves = self.0 * point.0.xxyy();
Point2DF32(halves + halves.zwzw()) Point2DF(halves + halves.zwzw())
} }
#[inline] #[inline]
@ -83,8 +83,8 @@ impl Matrix2x2F32 {
} }
#[inline] #[inline]
pub fn inverse(&self) -> Matrix2x2F32 { pub fn inverse(&self) -> Matrix2x2F {
Matrix2x2F32(F32x4::splat(1.0 / self.det()) * self.adjugate().0) Matrix2x2F(F32x4::splat(1.0 / self.det()) * self.adjugate().0)
} }
#[inline] #[inline]
@ -105,116 +105,116 @@ impl Matrix2x2F32 {
} }
} }
impl Sub<Matrix2x2F32> for Matrix2x2F32 { impl Sub<Matrix2x2F> for Matrix2x2F {
type Output = Matrix2x2F32; type Output = Matrix2x2F;
#[inline] #[inline]
fn sub(self, other: Matrix2x2F32) -> Matrix2x2F32 { fn sub(self, other: Matrix2x2F) -> Matrix2x2F {
Matrix2x2F32(self.0 - other.0) Matrix2x2F(self.0 - other.0)
} }
} }
/// An affine transform, optimized with SIMD. /// An affine transform, optimized with SIMD.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub struct Transform2DF32 { pub struct Transform2DF {
// Row-major order. // Row-major order.
matrix: Matrix2x2F32, matrix: Matrix2x2F,
vector: Point2DF32, vector: Point2DF,
} }
impl Default for Transform2DF32 { impl Default for Transform2DF {
#[inline] #[inline]
fn default() -> Transform2DF32 { fn default() -> Transform2DF {
Self::from_scale(Point2DF32::splat(1.0)) Self::from_scale(Point2DF::splat(1.0))
} }
} }
impl Transform2DF32 { impl Transform2DF {
#[inline] #[inline]
pub fn from_scale(scale: Point2DF32) -> Transform2DF32 { pub fn from_scale(scale: Point2DF) -> Transform2DF {
Transform2DF32 { Transform2DF {
matrix: Matrix2x2F32::from_scale(scale), matrix: Matrix2x2F::from_scale(scale),
vector: Point2DF32::default(), vector: Point2DF::default(),
} }
} }
#[inline] #[inline]
pub fn from_rotation(theta: f32) -> Transform2DF32 { pub fn from_rotation(theta: f32) -> Transform2DF {
Transform2DF32 { Transform2DF {
matrix: Matrix2x2F32::from_rotation(theta), matrix: Matrix2x2F::from_rotation(theta),
vector: Point2DF32::default(), vector: Point2DF::default(),
} }
} }
#[inline] #[inline]
pub fn from_rotation_vector(vector: UnitVector) -> Transform2DF32 { pub fn from_rotation_vector(vector: UnitVector) -> Transform2DF {
Transform2DF32 { Transform2DF {
matrix: Matrix2x2F32::from_rotation_vector(vector), matrix: Matrix2x2F::from_rotation_vector(vector),
vector: Point2DF32::default(), vector: Point2DF::default(),
} }
} }
#[inline] #[inline]
pub fn from_translation(vector: Point2DF32) -> Transform2DF32 { pub fn from_translation(vector: Point2DF) -> Transform2DF {
Transform2DF32 { matrix: Matrix2x2F32::default(), vector } Transform2DF { matrix: Matrix2x2F::default(), vector }
} }
#[inline] #[inline]
pub fn from_scale_rotation_translation( pub fn from_scale_rotation_translation(
scale: Point2DF32, scale: Point2DF,
theta: f32, theta: f32,
translation: Point2DF32, translation: Point2DF,
) -> Transform2DF32 { ) -> Transform2DF {
let rotation = Transform2DF32::from_rotation(theta); let rotation = Transform2DF::from_rotation(theta);
let translation = Transform2DF32::from_translation(translation); let translation = Transform2DF::from_translation(translation);
Transform2DF32::from_scale(scale).post_mul(&rotation).post_mul(&translation) Transform2DF::from_scale(scale).post_mul(&rotation).post_mul(&translation)
} }
#[inline] #[inline]
pub fn row_major(m11: f32, m12: f32, m21: f32, m22: f32, m31: f32, m32: f32) -> Transform2DF32 { pub fn row_major(m11: f32, m12: f32, m21: f32, m22: f32, m31: f32, m32: f32) -> Transform2DF {
Transform2DF32 { Transform2DF {
matrix: Matrix2x2F32::row_major(m11, m12, m21, m22), matrix: Matrix2x2F::row_major(m11, m12, m21, m22),
vector: Point2DF32::new(m31, m32), vector: Point2DF::new(m31, m32),
} }
} }
#[inline] #[inline]
pub fn transform_point(&self, point: Point2DF32) -> Point2DF32 { pub fn transform_point(&self, point: Point2DF) -> Point2DF {
self.matrix.transform_point(point) + self.vector self.matrix.transform_point(point) + self.vector
} }
#[inline] #[inline]
pub fn transform_line_segment(&self, line_segment: &LineSegmentF32) -> LineSegmentF32 { pub fn transform_line_segment(&self, line_segment: &LineSegmentF) -> LineSegmentF {
LineSegmentF32::new(self.transform_point(line_segment.from()), LineSegmentF::new(self.transform_point(line_segment.from()),
self.transform_point(line_segment.to())) self.transform_point(line_segment.to()))
} }
#[inline] #[inline]
pub fn transform_rect(&self, rect: &RectF32) -> RectF32 { pub fn transform_rect(&self, rect: &RectF) -> RectF {
let upper_left = self.transform_point(rect.origin()); let upper_left = self.transform_point(rect.origin());
let upper_right = self.transform_point(rect.upper_right()); let upper_right = self.transform_point(rect.upper_right());
let lower_left = self.transform_point(rect.lower_left()); let lower_left = self.transform_point(rect.lower_left());
let lower_right = self.transform_point(rect.lower_right()); let lower_right = self.transform_point(rect.lower_right());
let min_point = upper_left.min(upper_right).min(lower_left).min(lower_right); let min_point = upper_left.min(upper_right).min(lower_left).min(lower_right);
let max_point = upper_left.max(upper_right).max(lower_left).max(lower_right); let max_point = upper_left.max(upper_right).max(lower_left).max(lower_right);
RectF32::from_points(min_point, max_point) RectF::from_points(min_point, max_point)
} }
#[inline] #[inline]
pub fn post_mul(&self, other: &Transform2DF32) -> Transform2DF32 { pub fn post_mul(&self, other: &Transform2DF) -> Transform2DF {
let matrix = self.matrix.post_mul(&other.matrix); let matrix = self.matrix.post_mul(&other.matrix);
let vector = other.transform_point(self.vector); let vector = other.transform_point(self.vector);
Transform2DF32 { matrix, vector } Transform2DF { matrix, vector }
} }
#[inline] #[inline]
pub fn pre_mul(&self, other: &Transform2DF32) -> Transform2DF32 { pub fn pre_mul(&self, other: &Transform2DF) -> Transform2DF {
other.post_mul(self) other.post_mul(self)
} }
// TODO(pcwalton): Optimize better with SIMD. // TODO(pcwalton): Optimize better with SIMD.
#[inline] #[inline]
pub fn to_3d(&self) -> Transform3DF32 { pub fn to_3d(&self) -> Transform3DF {
Transform3DF32::row_major( Transform3DF::row_major(
self.matrix.0[0], self.matrix.0[0],
self.matrix.0[1], self.matrix.0[1],
0.0, 0.0,
@ -236,7 +236,7 @@ impl Transform2DF32 {
#[inline] #[inline]
pub fn is_identity(&self) -> bool { pub fn is_identity(&self) -> bool {
*self == Transform2DF32::default() *self == Transform2DF::default()
} }
#[inline] #[inline]
@ -257,25 +257,25 @@ impl Transform2DF32 {
} }
#[inline] #[inline]
pub fn post_translate(&self, vector: Point2DF32) -> Transform2DF32 { pub fn post_translate(&self, vector: Point2DF) -> Transform2DF {
self.post_mul(&Transform2DF32::from_translation(vector)) self.post_mul(&Transform2DF::from_translation(vector))
} }
#[inline] #[inline]
pub fn post_rotate(&self, theta: f32) -> Transform2DF32 { pub fn post_rotate(&self, theta: f32) -> Transform2DF {
self.post_mul(&Transform2DF32::from_rotation(theta)) self.post_mul(&Transform2DF::from_rotation(theta))
} }
#[inline] #[inline]
pub fn post_scale(&self, scale: Point2DF32) -> Transform2DF32 { pub fn post_scale(&self, scale: Point2DF) -> Transform2DF {
self.post_mul(&Transform2DF32::from_scale(scale)) self.post_mul(&Transform2DF::from_scale(scale))
} }
/// Returns the translation part of this matrix. /// Returns the translation part of this matrix.
/// ///
/// 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) -> Point2DF32 { pub fn translation(&self) -> Point2DF {
self.vector self.vector
} }
@ -292,20 +292,20 @@ impl Transform2DF32 {
/// 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 {
Point2DF32(self.matrix.0.zwxy()).length() Point2DF(self.matrix.0.zwxy()).length()
} }
} }
/// Transforms a path with a SIMD 2D transform. /// Transforms a path with a SIMD 2D transform.
pub struct Transform2DF32PathIter<I> pub struct Transform2DFPathIter<I>
where where
I: Iterator<Item = Segment>, I: Iterator<Item = Segment>,
{ {
iter: I, iter: I,
transform: Transform2DF32, transform: Transform2DF,
} }
impl<I> Iterator for Transform2DF32PathIter<I> impl<I> Iterator for Transform2DFPathIter<I>
where where
I: Iterator<Item = Segment>, I: Iterator<Item = Segment>,
{ {
@ -337,13 +337,13 @@ where
} }
} }
impl<I> Transform2DF32PathIter<I> impl<I> Transform2DFPathIter<I>
where where
I: Iterator<Item = Segment>, I: Iterator<Item = Segment>,
{ {
#[inline] #[inline]
pub fn new(iter: I, transform: &Transform2DF32) -> Transform2DF32PathIter<I> { pub fn new(iter: I, transform: &Transform2DF) -> Transform2DFPathIter<I> {
Transform2DF32PathIter { Transform2DFPathIter {
iter, iter,
transform: *transform, transform: *transform,
} }

View File

@ -10,9 +10,9 @@
//! 3D transforms that can be applied to paths. //! 3D transforms that can be applied to paths.
use crate::basic::point::{Point2DF32, Point2DI32, Point3DF32}; use crate::basic::point::{Point2DF, Point2DI, Point3DF};
use crate::basic::rect::RectF32; use crate::basic::rect::RectF;
use crate::basic::transform2d::Matrix2x2F32; use crate::basic::transform2d::Matrix2x2F;
use crate::segment::Segment; use crate::segment::Segment;
use pathfinder_simd::default::F32x4; use pathfinder_simd::default::F32x4;
use std::ops::{Add, Neg}; use std::ops::{Add, Neg};
@ -22,17 +22,17 @@ use std::ops::{Add, Neg};
/// In column-major order. /// In column-major order.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
#[repr(C)] #[repr(C)]
pub struct Transform3DF32 { pub struct Transform3DF {
pub c0: F32x4, pub c0: F32x4,
pub c1: F32x4, pub c1: F32x4,
pub c2: F32x4, pub c2: F32x4,
pub c3: F32x4, pub c3: F32x4,
} }
impl Default for Transform3DF32 { impl Default for Transform3DF {
#[inline] #[inline]
fn default() -> Transform3DF32 { fn default() -> Transform3DF {
Transform3DF32 { Transform3DF {
c0: F32x4::new(1.0, 0.0, 0.0, 0.0), c0: F32x4::new(1.0, 0.0, 0.0, 0.0),
c1: F32x4::new(0.0, 1.0, 0.0, 0.0), c1: F32x4::new(0.0, 1.0, 0.0, 0.0),
c2: F32x4::new(0.0, 0.0, 1.0, 0.0), c2: F32x4::new(0.0, 0.0, 1.0, 0.0),
@ -41,7 +41,7 @@ impl Default for Transform3DF32 {
} }
} }
impl Transform3DF32 { impl Transform3DF {
#[inline] #[inline]
pub fn row_major( pub fn row_major(
m00: f32, m00: f32,
@ -60,8 +60,8 @@ impl Transform3DF32 {
m31: f32, m31: f32,
m32: f32, m32: f32,
m33: f32, m33: f32,
) -> Transform3DF32 { ) -> Transform3DF {
Transform3DF32 { Transform3DF {
c0: F32x4::new(m00, m10, m20, m30), c0: F32x4::new(m00, m10, m20, m30),
c1: F32x4::new(m01, m11, m21, m31), c1: F32x4::new(m01, m11, m21, m31),
c2: F32x4::new(m02, m12, m22, m32), c2: F32x4::new(m02, m12, m22, m32),
@ -70,26 +70,26 @@ impl Transform3DF32 {
} }
#[inline] #[inline]
pub fn from_scale(x: f32, y: f32, z: f32) -> Transform3DF32 { pub fn from_scale(x: f32, y: f32, z: f32) -> Transform3DF {
Transform3DF32::row_major( Transform3DF::row_major(
x, 0.0, 0.0, 0.0, 0.0, y, 0.0, 0.0, 0.0, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, x, 0.0, 0.0, 0.0, 0.0, y, 0.0, 0.0, 0.0, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0,
) )
} }
#[inline] #[inline]
pub fn from_uniform_scale(factor: f32) -> Transform3DF32 { pub fn from_uniform_scale(factor: f32) -> Transform3DF {
Transform3DF32::from_scale(factor, factor, factor) Transform3DF::from_scale(factor, factor, factor)
} }
#[inline] #[inline]
pub fn from_translation(x: f32, y: f32, z: f32) -> Transform3DF32 { pub fn from_translation(x: f32, y: f32, z: f32) -> Transform3DF {
Transform3DF32::row_major( Transform3DF::row_major(
1.0, 0.0, 0.0, x, 0.0, 1.0, 0.0, y, 0.0, 0.0, 1.0, z, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, x, 0.0, 1.0, 0.0, y, 0.0, 0.0, 1.0, z, 0.0, 0.0, 0.0, 1.0,
) )
} }
// TODO(pcwalton): Optimize. // TODO(pcwalton): Optimize.
pub fn from_rotation(yaw: f32, pitch: f32, roll: f32) -> Transform3DF32 { pub fn from_rotation(yaw: f32, pitch: f32, roll: f32) -> Transform3DF {
let (cos_b, sin_b) = (yaw.cos(), yaw.sin()); let (cos_b, sin_b) = (yaw.cos(), yaw.sin());
let (cos_c, sin_c) = (pitch.cos(), pitch.sin()); let (cos_c, sin_c) = (pitch.cos(), pitch.sin());
let (cos_a, sin_a) = (roll.cos(), roll.sin()); let (cos_a, sin_a) = (roll.cos(), roll.sin());
@ -102,7 +102,7 @@ impl Transform3DF32 {
let m20 = -sin_b; let m20 = -sin_b;
let m21 = cos_b * sin_c; let m21 = cos_b * sin_c;
let m22 = cos_b * cos_c; let m22 = cos_b * cos_c;
Transform3DF32::row_major( Transform3DF::row_major(
m00, m01, m02, 0.0, m10, m11, m12, 0.0, m20, m21, m22, 0.0, 0.0, 0.0, 0.0, 1.0, m00, m01, m02, 0.0, m10, m11, m12, 0.0, m20, m21, m22, 0.0, 0.0, 0.0, 0.0, 1.0,
) )
} }
@ -111,7 +111,7 @@ impl Transform3DF32 {
/// ///
/// The quaternion is expected to be packed into a SIMD type (x, y, z, w) corresponding to /// The quaternion is expected to be packed into a SIMD type (x, y, z, w) corresponding to
/// x + yi + zj + wk. /// x + yi + zj + wk.
pub fn from_rotation_quaternion(q: F32x4) -> Transform3DF32 { pub fn from_rotation_quaternion(q: F32x4) -> Transform3DF {
// TODO(pcwalton): Optimize better with more shuffles. // TODO(pcwalton): Optimize better with more shuffles.
let (mut sq, mut w, mut xy_xz_yz) = (q * q, q.wwww() * q, q.xxyy() * q.yzzy()); let (mut sq, mut w, mut xy_xz_yz) = (q * q, q.wwww() * q, q.xxyy() * q.yzzy());
sq += sq; sq += sq;
@ -120,7 +120,7 @@ impl Transform3DF32 {
let diag = F32x4::splat(1.0) - (sq.yxxy() + sq.zzyy()); let diag = F32x4::splat(1.0) - (sq.yxxy() + sq.zzyy());
let (wx2, wy2, wz2) = (w.x(), w.y(), w.z()); let (wx2, wy2, wz2) = (w.x(), w.y(), w.z());
let (xy2, xz2, yz2) = (xy_xz_yz.x(), xy_xz_yz.y(), xy_xz_yz.z()); let (xy2, xz2, yz2) = (xy_xz_yz.x(), xy_xz_yz.y(), xy_xz_yz.z());
Transform3DF32::row_major( Transform3DF::row_major(
diag.x(), diag.x(),
xy2 - wz2, xy2 - wz2,
xz2 + wy2, xz2 + wy2,
@ -149,14 +149,14 @@ impl Transform3DF32 {
top: f32, top: f32,
near_val: f32, near_val: f32,
far_val: f32, far_val: f32,
) -> Transform3DF32 { ) -> Transform3DF {
let x_inv = 1.0 / (right - left); let x_inv = 1.0 / (right - left);
let y_inv = 1.0 / (top - bottom); let y_inv = 1.0 / (top - bottom);
let z_inv = 1.0 / (far_val - near_val); let z_inv = 1.0 / (far_val - near_val);
let tx = -(right + left) * x_inv; let tx = -(right + left) * x_inv;
let ty = -(top + bottom) * y_inv; let ty = -(top + bottom) * y_inv;
let tz = -(far_val + near_val) * z_inv; let tz = -(far_val + near_val) * z_inv;
Transform3DF32::row_major( Transform3DF::row_major(
2.0 * x_inv, 2.0 * x_inv,
0.0, 0.0,
0.0, 0.0,
@ -178,7 +178,7 @@ impl Transform3DF32 {
/// Just like `gluPerspective()`. /// Just like `gluPerspective()`.
#[inline] #[inline]
pub fn from_perspective(fov_y: f32, aspect: f32, z_near: f32, z_far: f32) -> Transform3DF32 { pub fn from_perspective(fov_y: f32, aspect: f32, z_near: f32, z_far: f32) -> Transform3DF {
let f = 1.0 / (fov_y * 0.5).tan(); let f = 1.0 / (fov_y * 0.5).tan();
let z_denom = 1.0 / (z_near - z_far); let z_denom = 1.0 / (z_near - z_far);
let m00 = f / aspect; let m00 = f / aspect;
@ -186,7 +186,7 @@ impl Transform3DF32 {
let m22 = (z_far + z_near) * z_denom; let m22 = (z_far + z_near) * z_denom;
let m23 = 2.0 * z_far * z_near * z_denom; let m23 = 2.0 * z_far * z_near * z_denom;
let m32 = -1.0; let m32 = -1.0;
Transform3DF32::row_major( Transform3DF::row_major(
m00, 0.0, 0.0, 0.0, 0.0, m11, 0.0, 0.0, 0.0, 0.0, m22, m23, 0.0, 0.0, m32, 0.0, m00, 0.0, 0.0, 0.0, 0.0, m11, 0.0, 0.0, 0.0, 0.0, m22, m23, 0.0, 0.0, m32, 0.0,
) )
} }
@ -197,12 +197,12 @@ impl Transform3DF32 {
// +- -+ // +- -+
#[inline] #[inline]
pub fn from_submatrices( pub fn from_submatrices(
a: Matrix2x2F32, a: Matrix2x2F,
b: Matrix2x2F32, b: Matrix2x2F,
c: Matrix2x2F32, c: Matrix2x2F,
d: Matrix2x2F32, d: Matrix2x2F,
) -> Transform3DF32 { ) -> Transform3DF {
Transform3DF32 { Transform3DF {
c0: a.0.concat_xy_xy(c.0), c0: a.0.concat_xy_xy(c.0),
c1: a.0.concat_zw_zw(c.0), c1: a.0.concat_zw_zw(c.0),
c2: b.0.concat_xy_xy(d.0), c2: b.0.concat_xy_xy(d.0),
@ -215,15 +215,15 @@ impl Transform3DF32 {
// //
// https://stackoverflow.com/a/18508113 // https://stackoverflow.com/a/18508113
#[inline] #[inline]
pub fn pre_mul(&self, other: &Transform3DF32) -> Transform3DF32 { pub fn pre_mul(&self, other: &Transform3DF) -> Transform3DF {
return Transform3DF32 { return Transform3DF {
c0: mul_col(self.c0, other), c0: mul_col(self.c0, other),
c1: mul_col(self.c1, other), c1: mul_col(self.c1, other),
c2: mul_col(self.c2, other), c2: mul_col(self.c2, other),
c3: mul_col(self.c3, other), c3: mul_col(self.c3, other),
}; };
fn mul_col(a_col: F32x4, b: &Transform3DF32) -> F32x4 { fn mul_col(a_col: F32x4, b: &Transform3DF) -> F32x4 {
let (a0, a1) = (F32x4::splat(a_col[0]), F32x4::splat(a_col[1])); let (a0, a1) = (F32x4::splat(a_col[0]), F32x4::splat(a_col[1]));
let (a2, a3) = (F32x4::splat(a_col[2]), F32x4::splat(a_col[3])); let (a2, a3) = (F32x4::splat(a_col[2]), F32x4::splat(a_col[3]));
a0 * b.c0 + a1 * b.c1 + a2 * b.c2 + a3 * b.c3 a0 * b.c0 + a1 * b.c1 + a2 * b.c2 + a3 * b.c3
@ -231,44 +231,44 @@ impl Transform3DF32 {
} }
#[inline] #[inline]
pub fn post_mul(&self, other: &Transform3DF32) -> Transform3DF32 { pub fn post_mul(&self, other: &Transform3DF) -> Transform3DF {
other.pre_mul(self) other.pre_mul(self)
} }
#[inline] #[inline]
pub fn transform_point(&self, point: Point3DF32) -> Point3DF32 { pub fn transform_point(&self, point: Point3DF) -> Point3DF {
let term0 = self.c0 * F32x4::splat(point.x()); let 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());
Point3DF32(term0 + term1 + term2 + term3) Point3DF(term0 + term1 + term2 + term3)
} }
#[inline] #[inline]
pub fn upper_left(&self) -> Matrix2x2F32 { pub fn upper_left(&self) -> Matrix2x2F {
Matrix2x2F32(self.c0.concat_xy_xy(self.c1)) Matrix2x2F(self.c0.concat_xy_xy(self.c1))
} }
#[inline] #[inline]
pub fn upper_right(&self) -> Matrix2x2F32 { pub fn upper_right(&self) -> Matrix2x2F {
Matrix2x2F32(self.c2.concat_xy_xy(self.c3)) Matrix2x2F(self.c2.concat_xy_xy(self.c3))
} }
#[inline] #[inline]
pub fn lower_left(&self) -> Matrix2x2F32 { pub fn lower_left(&self) -> Matrix2x2F {
Matrix2x2F32(self.c0.concat_zw_zw(self.c1)) Matrix2x2F(self.c0.concat_zw_zw(self.c1))
} }
#[inline] #[inline]
pub fn lower_right(&self) -> Matrix2x2F32 { pub fn lower_right(&self) -> Matrix2x2F {
Matrix2x2F32(self.c2.concat_zw_zw(self.c3)) Matrix2x2F(self.c2.concat_zw_zw(self.c3))
} }
// https://en.wikipedia.org/wiki/Invertible_matrix#Blockwise_inversion // https://en.wikipedia.org/wiki/Invertible_matrix#Blockwise_inversion
// //
// If A is the upper left submatrix of this matrix, this method assumes that A and the Schur // If A is the upper left submatrix of this matrix, this method assumes that A and the Schur
// complement of A are invertible. // complement of A are invertible.
pub fn inverse(&self) -> Transform3DF32 { pub fn inverse(&self) -> Transform3DF {
// Extract submatrices. // Extract submatrices.
let (a, b) = (self.upper_left(), self.upper_right()); let (a, b) = (self.upper_left(), self.upper_right());
let (c, d) = (self.lower_left(), self.lower_right()); let (c, d) = (self.lower_left(), self.lower_right());
@ -284,10 +284,10 @@ impl Transform3DF32 {
let (c_new, d_new) = ((-y).post_mul(&x), y); let (c_new, d_new) = ((-y).post_mul(&x), y);
// Construct inverse. // Construct inverse.
Transform3DF32::from_submatrices(a_new, b_new, c_new, d_new) Transform3DF::from_submatrices(a_new, b_new, c_new, d_new)
} }
pub fn approx_eq(&self, other: &Transform3DF32, epsilon: f32) -> bool { pub fn approx_eq(&self, other: &Transform3DF, epsilon: f32) -> bool {
self.c0.approx_eq(other.c0, epsilon) self.c0.approx_eq(other.c0, epsilon)
&& self.c1.approx_eq(other.c1, epsilon) && self.c1.approx_eq(other.c1, epsilon)
&& self.c2.approx_eq(other.c2, epsilon) && self.c2.approx_eq(other.c2, epsilon)
@ -300,31 +300,31 @@ impl Transform3DF32 {
} }
} }
impl Add<Matrix2x2F32> for Matrix2x2F32 { impl Add<Matrix2x2F> for Matrix2x2F {
type Output = Matrix2x2F32; type Output = Matrix2x2F;
#[inline] #[inline]
fn add(self, other: Matrix2x2F32) -> Matrix2x2F32 { fn add(self, other: Matrix2x2F) -> Matrix2x2F {
Matrix2x2F32(self.0 + other.0) Matrix2x2F(self.0 + other.0)
} }
} }
impl Neg for Matrix2x2F32 { impl Neg for Matrix2x2F {
type Output = Matrix2x2F32; type Output = Matrix2x2F;
#[inline] #[inline]
fn neg(self) -> Matrix2x2F32 { fn neg(self) -> Matrix2x2F {
Matrix2x2F32(-self.0) Matrix2x2F(-self.0)
} }
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Perspective { pub struct Perspective {
pub transform: Transform3DF32, pub transform: Transform3DF,
pub window_size: Point2DI32, pub window_size: Point2DI,
} }
impl Perspective { impl Perspective {
#[inline] #[inline]
pub fn new(transform: &Transform3DF32, window_size: Point2DI32) -> Perspective { pub fn new(transform: &Transform3DF, window_size: Point2DI) -> Perspective {
Perspective { Perspective {
transform: *transform, transform: *transform,
window_size, window_size,
@ -332,30 +332,30 @@ impl Perspective {
} }
#[inline] #[inline]
pub fn transform_point_2d(&self, point: &Point2DF32) -> Point2DF32 { pub fn transform_point_2d(&self, point: &Point2DF) -> Point2DF {
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()
* Point2DF32::new(1.0, -1.0); * Point2DF::new(1.0, -1.0);
(point + Point2DF32::splat(1.0)) * self.window_size.to_f32().scale(0.5) (point + Point2DF::splat(1.0)) * self.window_size.to_f32().scale(0.5)
} }
// TODO(pcwalton): SIMD? // TODO(pcwalton): SIMD?
#[inline] #[inline]
pub fn transform_rect(&self, rect: RectF32) -> RectF32 { pub fn transform_rect(&self, rect: RectF) -> RectF {
let upper_left = self.transform_point_2d(&rect.origin()); let upper_left = self.transform_point_2d(&rect.origin());
let upper_right = self.transform_point_2d(&rect.upper_right()); let upper_right = self.transform_point_2d(&rect.upper_right());
let lower_left = self.transform_point_2d(&rect.lower_left()); let lower_left = self.transform_point_2d(&rect.lower_left());
let lower_right = self.transform_point_2d(&rect.lower_right()); let lower_right = self.transform_point_2d(&rect.lower_right());
let min_point = upper_left.min(upper_right).min(lower_left).min(lower_right); let min_point = upper_left.min(upper_right).min(lower_left).min(lower_right);
let max_point = upper_left.max(upper_right).max(lower_left).max(lower_right); let max_point = upper_left.max(upper_right).max(lower_left).max(lower_right);
RectF32::from_points(min_point, max_point) RectF::from_points(min_point, max_point)
} }
#[inline] #[inline]
pub fn post_mul(&self, other: &Transform3DF32) -> Perspective { pub fn post_mul(&self, other: &Transform3DF) -> Perspective {
Perspective { Perspective {
transform: self.transform.post_mul(other), transform: self.transform.post_mul(other),
window_size: self.window_size, window_size: self.window_size,
@ -420,18 +420,18 @@ where
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::basic::point::Point3DF32; use crate::basic::point::Point3DF;
use crate::basic::transform3d::Transform3DF32; use crate::basic::transform3d::Transform3DF;
#[test] #[test]
fn test_post_mul() { fn test_post_mul() {
let a = Transform3DF32::row_major( let a = Transform3DF::row_major(
3.0, 1.0, 4.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0, 8.0, 9.0, 7.0, 9.0, 3.0, 2.0, 3.0, 1.0, 4.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0, 8.0, 9.0, 7.0, 9.0, 3.0, 2.0,
); );
let b = Transform3DF32::row_major( let b = Transform3DF::row_major(
3.0, 8.0, 4.0, 6.0, 2.0, 6.0, 4.0, 3.0, 3.0, 8.0, 3.0, 2.0, 7.0, 9.0, 5.0, 0.0, 3.0, 8.0, 4.0, 6.0, 2.0, 6.0, 4.0, 3.0, 3.0, 8.0, 3.0, 2.0, 7.0, 9.0, 5.0, 0.0,
); );
let c = Transform3DF32::row_major( let c = Transform3DF::row_major(
58.0, 107.0, 53.0, 29.0, 84.0, 177.0, 87.0, 72.0, 106.0, 199.0, 101.0, 49.0, 62.0, 58.0, 107.0, 53.0, 29.0, 84.0, 177.0, 87.0, 72.0, 106.0, 199.0, 101.0, 49.0, 62.0,
152.0, 83.0, 75.0, 152.0, 83.0, 75.0,
); );
@ -440,13 +440,13 @@ mod test {
#[test] #[test]
fn test_pre_mul() { fn test_pre_mul() {
let a = Transform3DF32::row_major( let a = Transform3DF::row_major(
3.0, 1.0, 4.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0, 8.0, 9.0, 7.0, 9.0, 3.0, 2.0, 3.0, 1.0, 4.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0, 8.0, 9.0, 7.0, 9.0, 3.0, 2.0,
); );
let b = Transform3DF32::row_major( let b = Transform3DF::row_major(
3.0, 8.0, 4.0, 6.0, 2.0, 6.0, 4.0, 3.0, 3.0, 8.0, 3.0, 2.0, 7.0, 9.0, 5.0, 0.0, 3.0, 8.0, 4.0, 6.0, 2.0, 6.0, 4.0, 3.0, 3.0, 8.0, 3.0, 2.0, 7.0, 9.0, 5.0, 0.0,
); );
let c = Transform3DF32::row_major( let c = Transform3DF::row_major(
135.0, 93.0, 110.0, 103.0, 93.0, 61.0, 85.0, 82.0, 104.0, 52.0, 90.0, 86.0, 117.0, 135.0, 93.0, 110.0, 103.0, 93.0, 61.0, 85.0, 82.0, 104.0, 52.0, 90.0, 86.0, 117.0,
50.0, 122.0, 125.0, 50.0, 122.0, 125.0,
); );
@ -455,26 +455,26 @@ mod test {
#[test] #[test]
fn test_transform_point() { fn test_transform_point() {
let a = Transform3DF32::row_major( let a = Transform3DF::row_major(
3.0, 1.0, 4.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0, 8.0, 9.0, 7.0, 9.0, 3.0, 2.0, 3.0, 1.0, 4.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0, 8.0, 9.0, 7.0, 9.0, 3.0, 2.0,
); );
let p = Point3DF32::new(3.0, 8.0, 4.0, 6.0); let p = Point3DF::new(3.0, 8.0, 4.0, 6.0);
let q = Point3DF32::new(63.0, 97.0, 135.0, 117.0); let q = Point3DF::new(63.0, 97.0, 135.0, 117.0);
assert_eq!(a.transform_point(p), q); assert_eq!(a.transform_point(p), q);
} }
#[test] #[test]
fn test_inverse() { fn test_inverse() {
// Random matrix. // Random matrix.
let m = Transform3DF32::row_major( let m = Transform3DF::row_major(
0.86277982, 0.15986552, 0.90739898, 0.60066808, 0.17386167, 0.016353, 0.8535783, 0.86277982, 0.15986552, 0.90739898, 0.60066808, 0.17386167, 0.016353, 0.8535783,
0.12969608, 0.0946466, 0.43248631, 0.63480505, 0.08154603, 0.50305436, 0.48359687, 0.12969608, 0.0946466, 0.43248631, 0.63480505, 0.08154603, 0.50305436, 0.48359687,
0.51057162, 0.24812012, 0.51057162, 0.24812012,
); );
let p0 = Point3DF32::new(0.95536648, 0.80633691, 0.16357357, 0.5477598); let p0 = Point3DF::new(0.95536648, 0.80633691, 0.16357357, 0.5477598);
let p1 = m.transform_point(p0); let p1 = m.transform_point(p0);
let m_inv = m.inverse(); let m_inv = m.inverse();
let m_inv_exp = Transform3DF32::row_major( let m_inv_exp = Transform3DF::row_major(
-2.47290136, -2.47290136,
3.48865688, 3.48865688,
-6.12298336, -6.12298336,

View File

@ -8,9 +8,9 @@
// 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::LineSegmentF32; use crate::basic::line_segment::LineSegmentF;
use crate::basic::point::{Point2DF32, Point3DF32}; use crate::basic::point::{Point2DF, Point3DF};
use crate::basic::rect::RectF32; use crate::basic::rect::RectF;
use crate::outline::{Contour, PointFlags}; use crate::outline::{Contour, PointFlags};
use crate::segment::{CubicSegment, Segment}; use crate::segment::{CubicSegment, Segment};
use crate::util::lerp; use crate::util::lerp;
@ -20,17 +20,17 @@ use std::fmt::Debug;
use std::mem; use std::mem;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
struct Edge(LineSegmentF32); struct Edge(LineSegmentF);
impl TEdge for Edge { impl TEdge for Edge {
#[inline] #[inline]
fn point_is_inside(&self, point: &Point2DF32) -> bool { fn point_is_inside(&self, point: &Point2DF) -> bool {
let area = (self.0.to() - self.0.from()).det(*point - self.0.from()); 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: &LineSegmentF32) -> ArrayVec<[f32; 3]> { fn intersect_line_segment(&self, segment: &LineSegmentF) -> 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: &Point2DF32) -> bool { fn point_is_inside(&self, point: &Point2DF) -> 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: &LineSegmentF32) -> ArrayVec<[f32; 3]> { fn intersect_line_segment(&self, segment: &LineSegmentF) -> 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: &Point2DF32) -> bool; fn point_is_inside(&self, point: &Point2DF) -> bool;
fn intersect_line_segment(&self, segment: &LineSegmentF32) -> ArrayVec<[f32; 3]>; fn intersect_line_segment(&self, segment: &LineSegmentF) -> 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<[Point2DF32; 4]>, clip_polygon: SmallVec<[Point2DF; 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: &[Point2DF32], contour: Contour) -> ContourPolygonClipper { pub(crate) fn new(clip_polygon: &[Point2DF], 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(LineSegmentF32::new(prev, next))); self.clip_against(Edge(LineSegmentF::new(prev, next)));
prev = next; prev = next;
} }
@ -343,7 +343,7 @@ enum EdgeRelativeLocation {
// Fast axis-aligned box 2D clipping // Fast axis-aligned box 2D clipping
pub(crate) struct ContourRectClipper { pub(crate) struct ContourRectClipper {
clip_rect: RectF32, clip_rect: RectF,
contour: Contour, contour: Contour,
} }
@ -358,7 +358,7 @@ impl ContourClipper for ContourRectClipper {
impl ContourRectClipper { impl ContourRectClipper {
#[inline] #[inline]
pub(crate) fn new(clip_rect: RectF32, contour: Contour) -> ContourRectClipper { pub(crate) fn new(clip_rect: RectF, contour: Contour) -> ContourRectClipper {
ContourRectClipper { clip_rect, contour } ContourRectClipper { clip_rect, contour }
} }
@ -379,16 +379,16 @@ impl ContourRectClipper {
// 3D quad clipping // 3D quad clipping
pub struct PolygonClipper3D { pub struct PolygonClipper3D {
subject: Vec<Point3DF32>, subject: Vec<Point3DF>,
} }
impl PolygonClipper3D { impl PolygonClipper3D {
#[inline] #[inline]
pub fn new(subject: Vec<Point3DF32>) -> PolygonClipper3D { pub fn new(subject: Vec<Point3DF>) -> PolygonClipper3D {
PolygonClipper3D { subject } PolygonClipper3D { subject }
} }
pub fn clip(mut self) -> Vec<Point3DF32> { pub fn clip(mut self) -> Vec<Point3DF> {
// 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: Point3DF32) -> bool { fn point_is_inside(self, point: Point3DF) -> 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: Point3DF32, next: Point3DF32) -> Point3DF32 { fn line_intersection(self, prev: Point3DF, next: Point3DF) -> Point3DF {
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: RectF32, polygon_points: &[Point2DF32]) -> bool { pub(crate) fn rect_is_outside_polygon(rect: RectF, polygon_points: &[Point2DF]) -> 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: RectF32, polygon_points: &[Point2DF3
} }
// 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: RectF32, polygon_points: &[Point2DF32]) -> bool { pub(crate) fn rect_is_inside_polygon(rect: RectF, polygon_points: &[Point2DF]) -> 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::Point2DF32; use crate::basic::point::Point2DF;
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: Point2DF32, amount: Point2DF,
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: Point2DF32, amount: Point2DF,
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 => Point2DF32::new(1.0, -1.0), Orientation::Ccw => Point2DF::new(1.0, -1.0),
Orientation::Cw => Point2DF32::new(-1.0, 1.0), Orientation::Cw => Point2DF::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 {
Point2DF32::default() Point2DF::default()
} else { } else {
bisector.scale_xy(scale).scale(1.0 / bisector_length) bisector.scale_xy(scale).scale(1.0 / bisector_length)
}; };

View File

@ -10,10 +10,10 @@
//! A compressed in-memory representation of paths. //! A compressed in-memory representation of paths.
use crate::basic::line_segment::LineSegmentF32; use crate::basic::line_segment::LineSegmentF;
use crate::basic::point::Point2DF32; use crate::basic::point::Point2DF;
use crate::basic::rect::RectF32; use crate::basic::rect::RectF;
use crate::basic::transform2d::Transform2DF32; use crate::basic::transform2d::Transform2DF;
use crate::basic::transform3d::Perspective; use crate::basic::transform3d::Perspective;
use crate::clip::{self, ContourPolygonClipper, ContourRectClipper}; use crate::clip::{self, ContourPolygonClipper, ContourRectClipper};
use crate::dilation::ContourDilator; use crate::dilation::ContourDilator;
@ -27,14 +27,14 @@ use std::mem;
#[derive(Clone)] #[derive(Clone)]
pub struct Outline { pub struct Outline {
pub(crate) contours: Vec<Contour>, pub(crate) contours: Vec<Contour>,
pub(crate) bounds: RectF32, pub(crate) bounds: RectF,
} }
#[derive(Clone)] #[derive(Clone)]
pub struct Contour { pub struct Contour {
pub(crate) points: Vec<Point2DF32>, pub(crate) points: Vec<Point2DF>,
pub(crate) flags: Vec<PointFlags>, pub(crate) flags: Vec<PointFlags>,
pub(crate) bounds: RectF32, pub(crate) bounds: RectF,
pub(crate) closed: bool, pub(crate) closed: bool,
} }
@ -50,7 +50,7 @@ impl Outline {
pub fn new() -> Outline { pub fn new() -> Outline {
Outline { Outline {
contours: vec![], contours: vec![],
bounds: RectF32::default(), bounds: RectF::default(),
} }
} }
@ -104,7 +104,7 @@ impl Outline {
} }
#[inline] #[inline]
pub fn bounds(&self) -> RectF32 { pub fn bounds(&self) -> RectF {
self.bounds self.bounds
} }
@ -127,7 +127,7 @@ impl Outline {
self.contours.push(contour); self.contours.push(contour);
} }
pub fn transform(&mut self, transform: &Transform2DF32) { pub fn transform(&mut self, transform: &Transform2DF) {
if transform.is_identity() { if transform.is_identity() {
return; return;
} }
@ -137,7 +137,7 @@ impl Outline {
contour.transform(transform); contour.transform(transform);
contour.update_bounds(&mut new_bounds); contour.update_bounds(&mut new_bounds);
} }
self.bounds = new_bounds.unwrap_or_else(|| RectF32::default()); self.bounds = new_bounds.unwrap_or_else(|| RectF::default());
} }
pub fn apply_perspective(&mut self, perspective: &Perspective) { pub fn apply_perspective(&mut self, perspective: &Perspective) {
@ -146,10 +146,10 @@ impl Outline {
contour.apply_perspective(perspective); contour.apply_perspective(perspective);
contour.update_bounds(&mut new_bounds); contour.update_bounds(&mut new_bounds);
} }
self.bounds = new_bounds.unwrap_or_else(|| RectF32::default()); self.bounds = new_bounds.unwrap_or_else(|| RectF::default());
} }
pub fn dilate(&mut self, amount: Point2DF32) { pub fn dilate(&mut self, amount: Point2DF) {
let orientation = Orientation::from_outline(self); let orientation = Orientation::from_outline(self);
self.contours self.contours
.iter_mut() .iter_mut()
@ -157,25 +157,25 @@ impl Outline {
self.bounds = self.bounds.dilate(amount); self.bounds = self.bounds.dilate(amount);
} }
pub fn prepare_for_tiling(&mut self, view_box: RectF32) { pub fn prepare_for_tiling(&mut self, view_box: RectF) {
self.contours self.contours
.iter_mut() .iter_mut()
.for_each(|contour| contour.prepare_for_tiling(view_box)); .for_each(|contour| contour.prepare_for_tiling(view_box));
self.bounds = self self.bounds = self
.bounds .bounds
.intersection(view_box) .intersection(view_box)
.unwrap_or_else(|| RectF32::default()); .unwrap_or_else(|| RectF::default());
} }
pub fn is_outside_polygon(&self, clip_polygon: &[Point2DF32]) -> bool { pub fn is_outside_polygon(&self, clip_polygon: &[Point2DF]) -> bool {
clip::rect_is_outside_polygon(self.bounds, clip_polygon) clip::rect_is_outside_polygon(self.bounds, clip_polygon)
} }
fn is_inside_polygon(&self, clip_polygon: &[Point2DF32]) -> bool { fn is_inside_polygon(&self, clip_polygon: &[Point2DF]) -> bool {
clip::rect_is_inside_polygon(self.bounds, clip_polygon) clip::rect_is_inside_polygon(self.bounds, clip_polygon)
} }
pub fn clip_against_polygon(&mut self, clip_polygon: &[Point2DF32]) { pub fn clip_against_polygon(&mut self, clip_polygon: &[Point2DF]) {
// Quick check. // Quick check.
if self.is_inside_polygon(clip_polygon) { if self.is_inside_polygon(clip_polygon) {
return; return;
@ -186,7 +186,7 @@ impl Outline {
} }
} }
pub fn clip_against_rect(&mut self, clip_rect: RectF32) { pub fn clip_against_rect(&mut self, clip_rect: RectF) {
if clip_rect.contains_rect(self.bounds) { if clip_rect.contains_rect(self.bounds) {
return; return;
} }
@ -215,7 +215,7 @@ impl Contour {
Contour { Contour {
points: vec![], points: vec![],
flags: vec![], flags: vec![],
bounds: RectF32::default(), bounds: RectF::default(),
closed: false, closed: false,
} }
} }
@ -229,7 +229,7 @@ impl Contour {
Contour { Contour {
points: Vec::with_capacity(length), points: Vec::with_capacity(length),
flags: Vec::with_capacity(length), flags: Vec::with_capacity(length),
bounds: RectF32::default(), bounds: RectF::default(),
closed: false, closed: false,
}, },
) )
@ -254,7 +254,7 @@ impl Contour {
} }
#[inline] #[inline]
pub fn bounds(&self) -> RectF32 { pub fn bounds(&self) -> RectF {
self.bounds self.bounds
} }
@ -264,33 +264,33 @@ impl Contour {
} }
#[inline] #[inline]
pub fn position_of(&self, index: u32) -> Point2DF32 { pub fn position_of(&self, index: u32) -> Point2DF {
self.points[index as usize] self.points[index as usize]
} }
#[inline] #[inline]
pub(crate) fn position_of_last(&self, index: u32) -> Point2DF32 { pub(crate) fn position_of_last(&self, index: u32) -> Point2DF {
self.points[self.points.len() - index as usize] self.points[self.points.len() - index as usize]
} }
#[inline] #[inline]
pub(crate) fn last_position(&self) -> Option<Point2DF32> { pub(crate) fn last_position(&self) -> Option<Point2DF> {
self.points.last().cloned() self.points.last().cloned()
} }
#[inline] #[inline]
pub fn push_endpoint(&mut self, point: Point2DF32) { pub fn push_endpoint(&mut self, point: Point2DF) {
self.push_point(point, PointFlags::empty(), true); self.push_point(point, PointFlags::empty(), true);
} }
#[inline] #[inline]
pub fn push_quadratic(&mut self, ctrl: Point2DF32, point: Point2DF32) { pub fn push_quadratic(&mut self, ctrl: Point2DF, point: Point2DF) {
self.push_point(ctrl, PointFlags::CONTROL_POINT_0, true); self.push_point(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: Point2DF32, ctrl1: Point2DF32, point: Point2DF32) { pub fn push_cubic(&mut self, ctrl0: Point2DF, ctrl1: Point2DF, point: Point2DF) {
self.push_point(ctrl0, PointFlags::CONTROL_POINT_0, true); self.push_point(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);
@ -304,7 +304,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: Point2DF32, point: Point2DF,
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());
@ -368,22 +368,22 @@ impl Contour {
self.push_point(segment.baseline.to(), PointFlags::empty(), update_bounds); self.push_point(segment.baseline.to(), PointFlags::empty(), update_bounds);
} }
pub fn push_arc(&mut self, center: Point2DF32, radius: f32, start_angle: f32, end_angle: f32) { pub fn push_arc(&mut self, center: Point2DF, radius: f32, start_angle: f32, end_angle: f32) {
let start = Point2DF32::new(f32::cos(start_angle), f32::sin(start_angle)).scale(radius); let start = Point2DF::new(f32::cos(start_angle), f32::sin(start_angle)).scale(radius);
let end = Point2DF32::new(f32::cos(end_angle), f32::sin(end_angle)).scale(radius); let end = Point2DF::new(f32::cos(end_angle), f32::sin(end_angle)).scale(radius);
let chord = LineSegmentF32::new(start, end).translate(center); let chord = LineSegmentF::new(start, end).translate(center);
let full_circle = end_angle - start_angle >= PI * 2.0; let full_circle = end_angle - start_angle >= PI * 2.0;
self.push_arc_from_chord_full(center, chord, full_circle); self.push_arc_from_chord_full(center, chord, full_circle);
} }
#[inline] #[inline]
pub fn push_arc_from_chord(&mut self, center: Point2DF32, chord: LineSegmentF32) { pub fn push_arc_from_chord(&mut self, center: Point2DF, chord: LineSegmentF) {
self.push_arc_from_chord_full(center, chord, false); self.push_arc_from_chord_full(center, chord, false);
} }
fn push_arc_from_chord_full(&mut self, fn push_arc_from_chord_full(&mut self,
center: Point2DF32, center: Point2DF,
mut chord: LineSegmentF32, mut chord: LineSegmentF,
full_circle: bool) { full_circle: bool) {
chord = chord.translate(-center); chord = chord.translate(-center);
let radius = chord.from().length(); let radius = chord.from().length();
@ -393,8 +393,8 @@ impl Contour {
debug_assert!(f32::abs(vector.0.length() - 1.0) < EPSILON); debug_assert!(f32::abs(vector.0.length() - 1.0) < EPSILON);
debug_assert!(f32::abs(end_vector.0.length() - 1.0) < EPSILON); debug_assert!(f32::abs(end_vector.0.length() - 1.0) < EPSILON);
let scale = Transform2DF32::from_scale(Point2DF32::splat(radius)); let scale = Transform2DF::from_scale(Point2DF::splat(radius));
let translation = Transform2DF32::from_translation(center); let translation = Transform2DF::from_translation(center);
let mut first_segment = true; let mut first_segment = true;
loop { loop {
@ -402,12 +402,12 @@ impl Contour {
let last = !(full_circle && first_segment) && let last = !(full_circle && first_segment) &&
sweep_vector.0.x() >= -EPSILON && sweep_vector.0.y() >= -EPSILON; sweep_vector.0.x() >= -EPSILON && sweep_vector.0.y() >= -EPSILON;
if !last { if !last {
sweep_vector = UnitVector(Point2DF32::new(0.0, 1.0)); sweep_vector = UnitVector(Point2DF::new(0.0, 1.0));
} }
let mut segment = Segment::arc_from_cos(sweep_vector.0.x()); let mut segment = Segment::arc_from_cos(sweep_vector.0.x());
let rotation = let rotation =
Transform2DF32::from_rotation_vector(sweep_vector.halve_angle().rotate_by(vector)); Transform2DF::from_rotation_vector(sweep_vector.halve_angle().rotate_by(vector));
segment = segment.transform(&scale.post_mul(&rotation).post_mul(&translation)); segment = segment.transform(&scale.post_mul(&rotation).post_mul(&translation));
if first_segment { if first_segment {
@ -458,9 +458,9 @@ impl Contour {
} }
#[inline] #[inline]
pub fn hull_segment_after(&self, prev_point_index: u32) -> LineSegmentF32 { pub fn hull_segment_after(&self, prev_point_index: u32) -> LineSegmentF {
let next_point_index = self.next_point_index_of(prev_point_index); let next_point_index = self.next_point_index_of(prev_point_index);
LineSegmentF32::new( LineSegmentF::new(
self.points[prev_point_index as usize], self.points[prev_point_index as usize],
self.points[next_point_index as usize], self.points[next_point_index as usize],
) )
@ -526,7 +526,7 @@ impl Contour {
} }
} }
pub fn transform(&mut self, transform: &Transform2DF32) { pub fn transform(&mut self, transform: &Transform2DF) {
if transform.is_identity() { if transform.is_identity() {
return; return;
} }
@ -544,12 +544,12 @@ impl Contour {
} }
} }
pub fn dilate(&mut self, amount: Point2DF32, orientation: Orientation) { pub fn dilate(&mut self, amount: Point2DF, orientation: Orientation) {
ContourDilator::new(self, amount, orientation).dilate(); ContourDilator::new(self, amount, orientation).dilate();
self.bounds = self.bounds.dilate(amount); self.bounds = self.bounds.dilate(amount);
} }
fn prepare_for_tiling(&mut self, view_box: RectF32) { fn prepare_for_tiling(&mut self, view_box: RectF) {
// Snap points to the view box bounds. This mops up floating point error from the clipping // Snap points to the view box bounds. This mops up floating point error from the clipping
// process. // process.
let (mut last_endpoint_index, mut contour_is_monotonic) = (None, true); let (mut last_endpoint_index, mut contour_is_monotonic) = (None, true);
@ -576,7 +576,7 @@ impl Contour {
self.bounds = self self.bounds = self
.bounds .bounds
.intersection(view_box) .intersection(view_box)
.unwrap_or_else(|| RectF32::default()); .unwrap_or_else(|| RectF::default());
} }
fn make_monotonic(&mut self) { fn make_monotonic(&mut self) {
@ -598,7 +598,7 @@ impl Contour {
} else { } else {
point_index point_index
}; };
let baseline = LineSegmentF32::new( let baseline = LineSegmentF::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],
); );
@ -614,7 +614,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 = LineSegmentF32::new(*ctrl_position_0, *ctrl_position_1); let ctrl = LineSegmentF::new(*ctrl_position_0, *ctrl_position_1);
handle_cubic(self, Segment::cubic(&baseline, &ctrl)); handle_cubic(self, Segment::cubic(&baseline, &ctrl));
} }
@ -694,7 +694,7 @@ impl Contour {
// Use this function to keep bounds up to date when mutating paths. See `Outline::transform()` // Use this function to keep bounds up to date when mutating paths. See `Outline::transform()`
// for an example of use. // for an example of use.
pub(crate) fn update_bounds(&self, bounds: &mut Option<RectF32>) { pub(crate) fn update_bounds(&self, bounds: &mut Option<RectF>) {
*bounds = Some(match *bounds { *bounds = Some(match *bounds {
None => self.bounds, None => self.bounds,
Some(bounds) => bounds.union_rect(self.bounds), Some(bounds) => bounds.union_rect(self.bounds),
@ -800,21 +800,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(&LineSegmentF32::new(point0, point1))); return Some(Segment::line(&LineSegmentF::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(&LineSegmentF32::new(point0, point1))); return Some(Segment::line(&LineSegmentF::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(&LineSegmentF32::new(point0, point2), point1)); return Some(Segment::quadratic(&LineSegmentF::new(point0, point2), point1));
} }
let point3_index = self.index; let point3_index = self.index;
@ -822,16 +822,16 @@ 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(
&LineSegmentF32::new(point0, point3), &LineSegmentF::new(point0, point3),
&LineSegmentF32::new(point1, point2), &LineSegmentF::new(point1, point2),
)); ));
} }
} }
#[inline] #[inline]
pub(crate) fn union_rect(bounds: &mut RectF32, new_point: Point2DF32, first: bool) { pub(crate) fn union_rect(bounds: &mut RectF, new_point: Point2DF, first: bool) {
if first { if first {
*bounds = RectF32::from_points(new_point, new_point); *bounds = RectF::from_points(new_point, new_point);
} else { } else {
*bounds = bounds.union_point(new_point) *bounds = bounds.union_point(new_point)
} }

View File

@ -10,9 +10,9 @@
//! Line or curve segments, optimized with SIMD. //! Line or curve segments, optimized with SIMD.
use crate::basic::line_segment::LineSegmentF32; use crate::basic::line_segment::LineSegmentF;
use crate::basic::point::Point2DF32; use crate::basic::point::Point2DF;
use crate::basic::transform2d::Transform2DF32; 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;
use std::f32::consts::SQRT_2; use std::f32::consts::SQRT_2;
@ -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: LineSegmentF32, pub baseline: LineSegmentF,
pub ctrl: LineSegmentF32, pub ctrl: LineSegmentF,
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: LineSegmentF32::default(), baseline: LineSegmentF::default(),
ctrl: LineSegmentF32::default(), ctrl: LineSegmentF::default(),
kind: SegmentKind::None, kind: SegmentKind::None,
flags: SegmentFlags::empty(), flags: SegmentFlags::empty(),
} }
} }
#[inline] #[inline]
pub fn line(line: &LineSegmentF32) -> Segment { pub fn line(line: &LineSegmentF) -> Segment {
Segment { Segment {
baseline: *line, baseline: *line,
ctrl: LineSegmentF32::default(), ctrl: LineSegmentF::default(),
kind: SegmentKind::Line, kind: SegmentKind::Line,
flags: SegmentFlags::empty(), flags: SegmentFlags::empty(),
} }
} }
#[inline] #[inline]
pub fn quadratic(baseline: &LineSegmentF32, ctrl: Point2DF32) -> Segment { pub fn quadratic(baseline: &LineSegmentF, ctrl: Point2DF) -> Segment {
Segment { Segment {
baseline: *baseline, baseline: *baseline,
ctrl: LineSegmentF32::new(ctrl, Point2DF32::default()), ctrl: LineSegmentF::new(ctrl, Point2DF::default()),
kind: SegmentKind::Quadratic, kind: SegmentKind::Quadratic,
flags: SegmentFlags::empty(), flags: SegmentFlags::empty(),
} }
} }
#[inline] #[inline]
pub fn cubic(baseline: &LineSegmentF32, ctrl: &LineSegmentF32) -> Segment { pub fn cubic(baseline: &LineSegmentF, ctrl: &LineSegmentF) -> Segment {
Segment { Segment {
baseline: *baseline, baseline: *baseline,
ctrl: *ctrl, ctrl: *ctrl,
@ -85,17 +85,17 @@ impl Segment {
// //
// https://pdfs.semanticscholar.org/1639/0db1a470bd13fe428e0896671a9a5745070a.pdf // https://pdfs.semanticscholar.org/1639/0db1a470bd13fe428e0896671a9a5745070a.pdf
let term = F32x4::new(cos_sweep_angle, -cos_sweep_angle, 0.0, 0.0); let term = F32x4::new(cos_sweep_angle, -cos_sweep_angle, 0.0, 0.0);
let p0 = Point2DF32((F32x4::splat(0.5) * (F32x4::splat(1.0) + term)).sqrt()); let p0 = Point2DF((F32x4::splat(0.5) * (F32x4::splat(1.0) + term)).sqrt());
let p3 = p0.scale_xy(Point2DF32::new(1.0, -1.0)); let p3 = p0.scale_xy(Point2DF::new(1.0, -1.0));
let p1 = p0 - p3.yx().scale(K); let p1 = p0 - p3.yx().scale(K);
let p2 = p3 + p0.yx().scale(K); let p2 = p3 + p0.yx().scale(K);
return Segment::cubic(&LineSegmentF32::new(p3, p0), &LineSegmentF32::new(p2, p1)); return Segment::cubic(&LineSegmentF::new(p3, p0), &LineSegmentF::new(p2, p1));
const K: f32 = 4.0 / 3.0 * (SQRT_2 - 1.0); const K: f32 = 4.0 / 3.0 * (SQRT_2 - 1.0);
} }
#[inline] #[inline]
pub fn as_line_segment(&self) -> LineSegmentF32 { pub fn as_line_segment(&self) -> LineSegmentF {
debug_assert!(self.is_line()); debug_assert!(self.is_line());
self.baseline self.baseline
} }
@ -137,7 +137,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 =
LineSegmentF32::new(self.baseline.from() + p1_2, p1_2 + self.baseline.to()) LineSegmentF::new(self.baseline.from() + p1_2, p1_2 + self.baseline.to())
.scale(1.0 / 3.0); .scale(1.0 / 3.0);
new_segment.kind = SegmentKind::Cubic; new_segment.kind = SegmentKind::Cubic;
new_segment new_segment
@ -196,7 +196,7 @@ impl Segment {
} }
#[inline] #[inline]
pub fn sample(self, t: f32) -> Point2DF32 { pub fn sample(self, t: f32) -> Point2DF {
// 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)
@ -206,7 +206,7 @@ impl Segment {
} }
#[inline] #[inline]
pub fn transform(self, transform: &Transform2DF32) -> Segment { pub fn transform(self, transform: &Transform2DF) -> Segment {
Segment { Segment {
baseline: transform.transform_line_segment(&self.baseline), baseline: transform.transform_line_segment(&self.baseline),
ctrl: transform.transform_line_segment(&self.ctrl), ctrl: transform.transform_line_segment(&self.ctrl),
@ -253,16 +253,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 = LineSegmentF32::new(*from, *from); baseline0 = LineSegmentF::new(*from, *from);
ctrl0 = LineSegmentF32::new(*from, *from); ctrl0 = LineSegmentF::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 = LineSegmentF32::new(*to, *to); baseline1 = LineSegmentF::new(*to, *to);
ctrl1 = LineSegmentF32::new(*to, *to); ctrl1 = LineSegmentF::new(*to, *to);
} else { } else {
let tttt = F32x4::splat(t); let tttt = F32x4::splat(t);
@ -281,10 +281,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 = LineSegmentF32(p0p3.concat_xy_xy(p0123)); baseline0 = LineSegmentF(p0p3.concat_xy_xy(p0123));
ctrl0 = LineSegmentF32(p01p12.concat_xy_xy(p012p123)); ctrl0 = LineSegmentF(p01p12.concat_xy_xy(p012p123));
baseline1 = LineSegmentF32(p0123.concat_xy_zw(p0p3)); baseline1 = LineSegmentF(p0123.concat_xy_zw(p0p3));
ctrl1 = LineSegmentF32(p012p123.concat_zw_zw(p12p23)); ctrl1 = LineSegmentF(p012p123.concat_zw_zw(p12p23));
} }
( (
@ -315,7 +315,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) -> Point2DF32 { pub fn sample(self, t: f32) -> Point2DF {
self.split(t).0.baseline.to() self.split(t).0.baseline.to()
} }

View File

@ -10,9 +10,9 @@
//! Utilities for converting path strokes to fills. //! Utilities for converting path strokes to fills.
use crate::basic::line_segment::LineSegmentF32; use crate::basic::line_segment::LineSegmentF;
use crate::basic::point::Point2DF32; use crate::basic::point::Point2DF;
use crate::basic::rect::RectF32; use crate::basic::rect::RectF;
use crate::outline::{Contour, Outline}; use crate::outline::{Contour, Outline};
use crate::segment::Segment; use crate::segment::Segment;
use std::f32; use std::f32;
@ -84,7 +84,7 @@ impl<'a> OutlineStrokeToFill<'a> {
new_contours.iter().for_each(|contour| contour.update_bounds(&mut new_bounds)); new_contours.iter().for_each(|contour| contour.update_bounds(&mut new_bounds));
self.output.contours = new_contours; self.output.contours = new_contours;
self.output.bounds = new_bounds.unwrap_or_else(|| RectF32::default()); self.output.bounds = new_bounds.unwrap_or_else(|| RectF::default());
} }
#[inline] #[inline]
@ -99,7 +99,7 @@ impl<'a> OutlineStrokeToFill<'a> {
// Add join if necessary. // Add join if necessary.
if closed && stroker.output.needs_join(self.style.line_join) { if closed && stroker.output.needs_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 = LineSegmentF32::new(p1, p0); let final_segment = LineSegmentF::new(p1, p0);
let join_point = stroker.input.position_of(0); let join_point = stroker.input.position_of(0);
stroker.output.add_join(self.style.line_join, join_point, &final_segment); stroker.output.add_join(self.style.line_join, join_point, &final_segment);
} }
@ -123,7 +123,7 @@ impl<'a> OutlineStrokeToFill<'a> {
let offset = gradient.scale(width * 0.5); let offset = gradient.scale(width * 0.5);
let p2 = p1 + offset; let p2 = p1 + offset;
let p3 = p2 + gradient.yx().scale_xy(Point2DF32::new(-width, width)); let p3 = p2 + gradient.yx().scale_xy(Point2DF::new(-width, width));
let p4 = p3 - offset; let p4 = p3 - offset;
contour.push_endpoint(p2); contour.push_endpoint(p2);
@ -131,8 +131,8 @@ impl<'a> OutlineStrokeToFill<'a> {
contour.push_endpoint(p4); contour.push_endpoint(p4);
} }
LineCap::Round => { LineCap::Round => {
let offset = gradient.yx().scale_xy(Point2DF32::new(-width, width)); let offset = gradient.yx().scale_xy(Point2DF::new(-width, width));
let chord = LineSegmentF32::new(p1, p1 + offset); let chord = LineSegmentF::new(p1, p1 + offset);
contour.push_arc_from_chord(p1 + offset.scale(0.5), chord); contour.push_arc_from_chord(p1 + offset.scale(0.5), chord);
} }
} }
@ -179,7 +179,7 @@ impl<'a> ContourStrokeToFill<'a> {
trait Offset { trait Offset {
fn offset(&self, distance: f32, join: LineJoin, contour: &mut Contour); fn offset(&self, distance: f32, join: LineJoin, contour: &mut Contour);
fn add_to_contour(&self, join: LineJoin, join_point: Point2DF32, contour: &mut Contour); fn add_to_contour(&self, join: LineJoin, join_point: Point2DF, contour: &mut Contour);
fn offset_once(&self, distance: f32) -> Self; fn 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;
} }
@ -207,7 +207,7 @@ impl Offset for Segment {
after.offset(distance, join, contour); after.offset(distance, join, contour);
} }
fn add_to_contour(&self, join: LineJoin, join_point: Point2DF32, contour: &mut Contour) { fn add_to_contour(&self, join: LineJoin, join_point: Point2DF, contour: &mut Contour) {
// Add join if necessary. // Add join if necessary.
if contour.needs_join(join) { if contour.needs_join(join) {
let p3 = self.baseline.from(); let p3 = self.baseline.from();
@ -219,7 +219,7 @@ impl Offset for Segment {
self.ctrl.from() self.ctrl.from()
}; };
contour.add_join(join, join_point, &LineSegmentF32::new(p4, p3)); contour.add_join(join, join_point, &LineSegmentF::new(p4, p3));
} }
// Push segment. // Push segment.
@ -232,51 +232,51 @@ impl Offset for Segment {
} }
if self.is_quadratic() { if self.is_quadratic() {
let mut segment_0 = LineSegmentF32::new(self.baseline.from(), self.ctrl.from()); let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.from());
let mut segment_1 = LineSegmentF32::new(self.ctrl.from(), self.baseline.to()); let mut segment_1 = LineSegmentF::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 = LineSegmentF32::new(segment_0.from(), segment_1.to()); let baseline = LineSegmentF::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 = LineSegmentF32::new(self.baseline.from(), self.ctrl.to()); let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.to());
let mut segment_1 = LineSegmentF32::new(self.ctrl.to(), self.baseline.to()); let mut segment_1 = LineSegmentF::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 = LineSegmentF32::new(segment_0.from(), segment_1.to()); let baseline = LineSegmentF::new(segment_0.from(), segment_1.to());
let ctrl = LineSegmentF32::new(segment_0.from(), ctrl); let ctrl = LineSegmentF::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 = LineSegmentF32::new(self.baseline.from(), self.ctrl.from()); let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.from());
let mut segment_1 = LineSegmentF32::new(self.ctrl.from(), self.baseline.to()); let mut segment_1 = LineSegmentF::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 = LineSegmentF32::new(segment_0.from(), segment_1.to()); let baseline = LineSegmentF::new(segment_0.from(), segment_1.to());
let ctrl = LineSegmentF32::new(ctrl, segment_1.to()); let ctrl = LineSegmentF::new(ctrl, segment_1.to());
return Segment::cubic(&baseline, &ctrl); return Segment::cubic(&baseline, &ctrl);
} }
let mut segment_0 = LineSegmentF32::new(self.baseline.from(), self.ctrl.from()); let mut segment_0 = LineSegmentF::new(self.baseline.from(), self.ctrl.from());
let mut segment_1 = LineSegmentF32::new(self.ctrl.from(), self.ctrl.to()); let mut segment_1 = LineSegmentF::new(self.ctrl.from(), self.ctrl.to());
let mut segment_2 = LineSegmentF32::new(self.ctrl.to(), self.baseline.to()); let mut segment_2 = LineSegmentF::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);
@ -290,8 +290,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 = LineSegmentF32::new(segment_0.from(), segment_2.to()); let baseline = LineSegmentF::new(segment_0.from(), segment_2.to());
let ctrl = LineSegmentF32::new(ctrl_0, ctrl_1); let ctrl = LineSegmentF::new(ctrl_0, ctrl_1);
Segment::cubic(&baseline, &ctrl) Segment::cubic(&baseline, &ctrl)
} }
@ -330,9 +330,9 @@ impl Contour {
(join == LineJoin::Miter || join == LineJoin::Round) && self.len() >= 2 (join == LineJoin::Miter || join == LineJoin::Round) && self.len() >= 2
} }
fn add_join(&mut self, join: LineJoin, join_point: Point2DF32, next_tangent: &LineSegmentF32) { fn add_join(&mut self, join: LineJoin, join_point: Point2DF, next_tangent: &LineSegmentF) {
let (p0, p1) = (self.position_of_last(2), self.position_of_last(1)); let (p0, p1) = (self.position_of_last(2), self.position_of_last(1));
let prev_tangent = LineSegmentF32::new(p0, p1); let prev_tangent = LineSegmentF::new(p0, p1);
match join { match join {
LineJoin::Bevel => {} LineJoin::Bevel => {}
@ -342,7 +342,7 @@ impl Contour {
} }
} }
LineJoin::Round => { LineJoin::Round => {
self.push_arc_from_chord(join_point, LineSegmentF32::new(prev_tangent.to(), self.push_arc_from_chord(join_point, LineSegmentF::new(prev_tangent.to(),
next_tangent.to())); next_tangent.to()));
} }
} }

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::Point2DF32; use crate::basic::point::Point2DF;
use pathfinder_simd::default::F32x4; use pathfinder_simd::default::F32x4;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct UnitVector(pub Point2DF32); pub struct UnitVector(pub Point2DF);
impl UnitVector { impl UnitVector {
#[inline] #[inline]
pub fn from_angle(theta: f32) -> UnitVector { pub fn from_angle(theta: f32) -> UnitVector {
UnitVector(Point2DF32::new(theta.cos(), theta.sin())) UnitVector(Point2DF::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(Point2DF32::new(products[0] - products[1], products[2] + products[3])) UnitVector(Point2DF::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(Point2DF32::new(products[0] + products[1], products[2] - products[3])) UnitVector(Point2DF::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(Point2DF32((F32x4::splat(0.5) * (F32x4::splat(1.0) + term)).sqrt())) UnitVector(Point2DF((F32x4::splat(0.5) * (F32x4::splat(1.0) + term)).sqrt()))
} }
} }

View File

@ -14,8 +14,8 @@
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::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
use pathfinder_geometry::basic::rect::RectI32; 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};
use pathfinder_gpu::{DepthFunc, Device, Primitive, RenderState, ShaderKind, StencilFunc}; use pathfinder_gpu::{DepthFunc, Device, Primitive, RenderState, ShaderKind, StencilFunc};
@ -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: Point2DI32) -> GLTexture { fn create_texture(&self, format: TextureFormat, size: Point2DI) -> 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: Point2DI32, data: &[u8]) -> GLTexture { fn create_texture_from_data(&self, size: Point2DI, data: &[u8]) -> GLTexture {
assert!(data.len() >= size.x() as usize * size.y() as usize); 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) -> Point2DI32 { fn texture_size(&self, texture: &Self::Texture) -> Point2DI {
texture.size texture.size
} }
fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI32, data: &[u8]) { fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI, data: &[u8]) {
assert!(data.len() >= size.x() as usize * size.y() as usize * 4); 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: Point2DI32) -> Vec<u8> { fn read_pixels_from_default_framebuffer(&self, size: Point2DI) -> 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();
@ -622,7 +622,7 @@ impl Device for GLDevice {
} }
#[inline] #[inline]
fn bind_default_framebuffer(&self, viewport: RectI32) { fn bind_default_framebuffer(&self, viewport: RectI) {
unsafe { unsafe {
gl::BindFramebuffer(gl::FRAMEBUFFER, self.default_framebuffer); ck(); gl::BindFramebuffer(gl::FRAMEBUFFER, self.default_framebuffer); ck();
gl::Viewport(viewport.origin().x(), gl::Viewport(viewport.origin().x(),
@ -799,7 +799,7 @@ impl Drop for GLShader {
pub struct GLTexture { pub struct GLTexture {
gl_texture: GLuint, gl_texture: GLuint,
pub size: Point2DI32, pub size: Point2DI,
} }
pub struct GLTimerQuery { pub struct GLTimerQuery {

View File

@ -12,9 +12,9 @@
use crate::resources::ResourceLoader; use crate::resources::ResourceLoader;
use image::ImageFormat; use image::ImageFormat;
use pathfinder_geometry::basic::point::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::rect::RectI;
use pathfinder_geometry::basic::transform3d::Transform3DF32; use pathfinder_geometry::basic::transform3d::Transform3DF;
use pathfinder_geometry::color::ColorF; use pathfinder_geometry::color::ColorF;
use pathfinder_simd::default::F32x4; use pathfinder_simd::default::F32x4;
use std::time::Duration; use std::time::Duration;
@ -41,8 +41,8 @@ pub trait Device {
type VertexArray; type VertexArray;
type VertexAttr; type VertexAttr;
fn create_texture(&self, format: TextureFormat, size: Point2DI32) -> Self::Texture; fn create_texture(&self, format: TextureFormat, size: Point2DI) -> Self::Texture;
fn create_texture_from_data(&self, size: Point2DI32, data: &[u8]) -> Self::Texture; fn create_texture_from_data(&self, size: Point2DI, 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) -> Point2DI32; fn texture_size(&self, texture: &Self::Texture) -> Point2DI;
fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI32, data: &[u8]); fn upload_to_texture(&self, texture: &Self::Texture, size: Point2DI, data: &[u8]);
fn read_pixels_from_default_framebuffer(&self, size: Point2DI32) -> Vec<u8>; fn read_pixels_from_default_framebuffer(&self, size: Point2DI) -> 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);
@ -94,7 +94,7 @@ pub trait Device {
// TODO(pcwalton): Go bindless... // TODO(pcwalton): Go bindless...
fn bind_vertex_array(&self, vertex_array: &Self::VertexArray); fn bind_vertex_array(&self, vertex_array: &Self::VertexArray);
fn bind_buffer(&self, buffer: &Self::Buffer, target: BufferTarget); fn bind_buffer(&self, buffer: &Self::Buffer, target: BufferTarget);
fn bind_default_framebuffer(&self, viewport: RectI32); fn bind_default_framebuffer(&self, viewport: RectI);
fn bind_framebuffer(&self, framebuffer: &Self::Framebuffer); fn bind_framebuffer(&self, framebuffer: &Self::Framebuffer);
fn bind_texture(&self, texture: &Self::Texture, unit: u32); fn bind_texture(&self, texture: &Self::Texture, unit: u32);
@ -103,7 +103,7 @@ pub trait Device {
let image = image::load_from_memory_with_format(&data, ImageFormat::PNG) let image = image::load_from_memory_with_format(&data, ImageFormat::PNG)
.unwrap() .unwrap()
.to_luma(); .to_luma();
let size = Point2DI32::new(image.width() as i32, image.height() as i32); let size = Point2DI::new(image.width() as i32, image.height() as i32);
self.create_texture_from_data(size, &image) self.create_texture_from_data(size, &image)
} }
@ -202,7 +202,7 @@ pub enum Primitive {
#[derive(Clone, Copy, Default)] #[derive(Clone, Copy, Default)]
pub struct ClearParams { pub struct ClearParams {
pub color: Option<ColorF>, pub color: Option<ColorF>,
pub rect: Option<RectI32>, pub rect: Option<RectI>,
pub depth: Option<f32>, pub depth: Option<f32>,
pub stencil: Option<u8>, pub stencil: Option<u8>,
} }
@ -297,7 +297,7 @@ impl Default for StencilFunc {
impl UniformData { impl UniformData {
#[inline] #[inline]
pub fn from_transform_3d(transform: &Transform3DF32) -> UniformData { pub fn from_transform_3d(transform: &Transform3DF) -> UniformData {
UniformData::Mat4([transform.c0, transform.c1, transform.c2, transform.c3]) UniformData::Mat4([transform.c0, transform.c1, transform.c2, transform.c3])
} }
} }

View File

@ -17,9 +17,9 @@ 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::{LineSegmentF32, LineSegmentU4, LineSegmentU8}; use pathfinder_geometry::basic::line_segment::{LineSegmentF, LineSegmentU4, LineSegmentU8};
use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; use pathfinder_geometry::basic::point::{Point2DF, Point2DI};
use pathfinder_geometry::basic::rect::{RectF32, RectI32}; 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};
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
@ -75,7 +75,7 @@ impl<'a> SceneBuilder<'a> {
fn build_path( fn build_path(
&self, &self,
path_index: usize, path_index: usize,
view_box: RectF32, view_box: RectF,
built_options: &PreparedRenderOptions, built_options: &PreparedRenderOptions,
scene: &Scene, scene: &Scene,
) -> Vec<AlphaTileBatchPrimitive> { ) -> Vec<AlphaTileBatchPrimitive> {
@ -141,7 +141,7 @@ pub struct TileStats {
// Utilities for built objects // Utilities for built objects
impl BuiltObject { impl BuiltObject {
pub(crate) fn new(bounds: RectF32) -> BuiltObject { pub(crate) fn new(bounds: RectF) -> BuiltObject {
let tile_rect = tiles::round_rect_out_to_tile_bounds(bounds); let tile_rect = tiles::round_rect_out_to_tile_bounds(bounds);
let tiles = DenseTileMap::new(tile_rect); let tiles = DenseTileMap::new(tile_rect);
BuiltObject { BuiltObject {
@ -153,15 +153,15 @@ impl BuiltObject {
} }
#[inline] #[inline]
pub(crate) fn tile_rect(&self) -> RectI32 { pub(crate) fn tile_rect(&self) -> RectI {
self.tiles.rect self.tiles.rect
} }
fn add_fill( fn add_fill(
&mut self, &mut self,
builder: &SceneBuilder, builder: &SceneBuilder,
segment: &LineSegmentF32, segment: &LineSegmentF,
tile_coords: Point2DI32, tile_coords: Point2DI,
) { ) {
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: Point2DI32, tile_coords: Point2DI,
) -> 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: Point2DI32, tile_coords: Point2DI,
) { ) {
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 = Point2DF32::new(left, tile_origin_y); let left = Point2DF::new(left, tile_origin_y);
let right = Point2DF32::new(right, tile_origin_y); let right = Point2DF::new(right, tile_origin_y);
let segment = if winding < 0 { let segment = if winding < 0 {
LineSegmentF32::new(left, right) LineSegmentF::new(left, right)
} else { } else {
LineSegmentF32::new(right, left) LineSegmentF::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: LineSegmentF32, mut segment: LineSegmentF,
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 = Point2DF32::new(x, segment.solve_y_for_x(x)); let point = Point2DF::new(x, segment.solve_y_for_x(x));
if !winding { if !winding {
fill_to = point; fill_to = point;
segment = LineSegmentF32::new(point, segment.to()); segment = LineSegmentF::new(point, segment.to());
} else { } else {
fill_from = point; fill_from = point;
segment = LineSegmentF32::new(segment.from(), point); segment = LineSegmentF::new(segment.from(), point);
} }
} }
let fill_segment = LineSegmentF32::new(fill_from, fill_to); let fill_segment = LineSegmentF::new(fill_from, fill_to);
let fill_tile_coords = Point2DI32::new(subsegment_tile_x, tile_y); let fill_tile_coords = Point2DI::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: Point2DI32) -> Option<u32> { pub(crate) fn tile_coords_to_local_index(&self, coords: Point2DI) -> 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) -> Point2DI32 { pub(crate) fn local_tile_index_to_coords(&self, tile_index: u32) -> Point2DI {
self.tiles.index_to_coords(tile_index as usize) self.tiles.index_to_coords(tile_index as usize)
} }
} }

View File

@ -24,7 +24,7 @@ use crate::gpu::renderer::Renderer;
use crate::gpu_data::RenderCommand; use crate::gpu_data::RenderCommand;
use crate::options::{RenderCommandListener, RenderOptions}; use crate::options::{RenderCommandListener, RenderOptions};
use crate::scene::Scene; use crate::scene::Scene;
use pathfinder_geometry::basic::rect::RectF32; use pathfinder_geometry::basic::rect::RectF;
use pathfinder_gpu::Device; use pathfinder_gpu::Device;
use std::sync::mpsc::{self, Receiver, Sender}; use std::sync::mpsc::{self, Receiver, Sender};
use std::thread; use std::thread;
@ -53,7 +53,7 @@ impl SceneProxy {
} }
#[inline] #[inline]
pub fn set_view_box(&self, new_view_box: RectF32) { pub fn set_view_box(&self, new_view_box: RectF) {
self.sender.send(MainToWorkerMsg::SetViewBox(new_view_box)).unwrap(); self.sender.send(MainToWorkerMsg::SetViewBox(new_view_box)).unwrap();
} }
@ -117,7 +117,7 @@ fn scene_thread<E>(mut scene: Scene,
enum MainToWorkerMsg { enum MainToWorkerMsg {
ReplaceScene(Scene), ReplaceScene(Scene),
SetViewBox(RectF32), SetViewBox(RectF),
Build(RenderOptions, Box<dyn RenderCommandListener>), Build(RenderOptions, Box<dyn RenderCommandListener>),
GetSVG(Sender<Vec<u8>>), GetSVG(Sender<Vec<u8>>),
} }

View File

@ -16,8 +16,8 @@
//! 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::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::rect::RectI;
use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::resources::ResourceLoader;
use pathfinder_gpu::Device; use pathfinder_gpu::Device;
use pathfinder_ui::{FONT_ASCENT, LINE_HEIGHT, PADDING, UIPresenter, WINDOW_COLOR}; use pathfinder_ui::{FONT_ASCENT, LINE_HEIGHT, PADDING, UIPresenter, WINDOW_COLOR};
@ -50,7 +50,7 @@ where
pub fn new( pub fn new(
device: &D, device: &D,
resources: &dyn ResourceLoader, resources: &dyn ResourceLoader,
framebuffer_size: Point2DI32, framebuffer_size: Point2DI,
) -> DebugUIPresenter<D> { ) -> DebugUIPresenter<D> {
let ui_presenter = UIPresenter::new(device, resources, framebuffer_size); let ui_presenter = UIPresenter::new(device, resources, framebuffer_size);
DebugUIPresenter { DebugUIPresenter {
@ -84,17 +84,17 @@ where
fn draw_stats_window(&self, device: &D, mean_cpu_sample: &CPUSample) { fn draw_stats_window(&self, device: &D, mean_cpu_sample: &CPUSample) {
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 = RectI32::new( let window_rect = RectI::new(
Point2DI32::new( Point2DI::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,
), ),
Point2DI32::new(STATS_WINDOW_WIDTH, STATS_WINDOW_HEIGHT), Point2DI::new(STATS_WINDOW_WIDTH, STATS_WINDOW_HEIGHT),
); );
self.ui_presenter.draw_solid_rounded_rect(device, window_rect, WINDOW_COLOR); self.ui_presenter.draw_solid_rounded_rect(device, window_rect, WINDOW_COLOR);
let origin = window_rect.origin() + Point2DI32::new(PADDING, PADDING + FONT_ASCENT); let origin = window_rect.origin() + Point2DI::new(PADDING, PADDING + FONT_ASCENT);
self.ui_presenter.draw_text( 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 + Point2DI32::new(0, LINE_HEIGHT * 1), origin + Point2DI::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 + Point2DI32::new(0, LINE_HEIGHT * 2), origin + Point2DI::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 + Point2DI32::new(0, LINE_HEIGHT * 3), origin + Point2DI::new(0, LINE_HEIGHT * 3),
false, false,
); );
} }
@ -124,17 +124,17 @@ where
fn draw_performance_window(&self, device: &D, mean_cpu_sample: &CPUSample) { fn draw_performance_window(&self, device: &D, mean_cpu_sample: &CPUSample) {
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 = RectI32::new( let window_rect = RectI::new(
Point2DI32::new( Point2DI::new(
framebuffer_size.x() - PADDING - PERFORMANCE_WINDOW_WIDTH, framebuffer_size.x() - PADDING - PERFORMANCE_WINDOW_WIDTH,
bottom - PERFORMANCE_WINDOW_HEIGHT, bottom - PERFORMANCE_WINDOW_HEIGHT,
), ),
Point2DI32::new(PERFORMANCE_WINDOW_WIDTH, PERFORMANCE_WINDOW_HEIGHT), Point2DI::new(PERFORMANCE_WINDOW_WIDTH, PERFORMANCE_WINDOW_HEIGHT),
); );
self.ui_presenter.draw_solid_rounded_rect(device, window_rect, WINDOW_COLOR); self.ui_presenter.draw_solid_rounded_rect(device, window_rect, WINDOW_COLOR);
let origin = window_rect.origin() + Point2DI32::new(PADDING, PADDING + FONT_ASCENT); let origin = window_rect.origin() + Point2DI::new(PADDING, PADDING + FONT_ASCENT);
self.ui_presenter.draw_text( 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 + Point2DI32::new(0, LINE_HEIGHT * 1), origin + Point2DI::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 + Point2DI32::new(0, LINE_HEIGHT * 2), origin + Point2DI::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 + Point2DI32::new(0, LINE_HEIGHT * 3), origin + Point2DI::new(0, LINE_HEIGHT * 3),
false, false,
); );
} }

View File

@ -13,9 +13,9 @@ 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::{Point2DI32, Point3DF32}; use pathfinder_geometry::basic::point::{Point2DI, Point3DF};
use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::rect::RectI;
use pathfinder_geometry::basic::transform3d::Transform3DF32; use pathfinder_geometry::basic::transform3d::Transform3DF;
use pathfinder_geometry::color::ColorF; use pathfinder_geometry::color::ColorF;
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};
@ -182,7 +182,7 @@ where
); );
let mask_framebuffer_size = let mask_framebuffer_size =
Point2DI32::new(MASK_FRAMEBUFFER_WIDTH, MASK_FRAMEBUFFER_HEIGHT); Point2DI::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: Point2DI32) { pub fn set_main_framebuffer_size(&mut self, new_framebuffer_size: Point2DI) {
self.debug_ui_presenter.ui_presenter.set_framebuffer_size(new_framebuffer_size); self.debug_ui_presenter.ui_presenter.set_framebuffer_size(new_framebuffer_size);
} }
@ -715,7 +715,7 @@ where
} }
} }
fn draw_stencil(&self, quad_positions: &[Point3DF32]) { fn draw_stencil(&self, quad_positions: &[Point3DF]) {
self.device.allocate_buffer( self.device.allocate_buffer(
&self.stencil_vertex_array.vertex_buffer, &self.stencil_vertex_array.vertex_buffer,
BufferData::Memory(quad_positions), BufferData::Memory(quad_positions),
@ -764,8 +764,8 @@ where
pub fn reproject_texture( pub fn reproject_texture(
&self, &self,
texture: &D::Texture, texture: &D::Texture,
old_transform: &Transform3DF32, old_transform: &Transform3DF,
new_transform: &Transform3DF32, new_transform: &Transform3DF,
) { ) {
self.bind_draw_framebuffer(); self.bind_draw_framebuffer();
@ -869,28 +869,28 @@ where
}) })
} }
fn draw_viewport(&self) -> RectI32 { fn draw_viewport(&self) -> RectI {
let main_viewport = self.main_viewport(); let main_viewport = self.main_viewport();
match self.render_mode { match self.render_mode {
RenderMode::Monochrome { RenderMode::Monochrome {
defringing_kernel: Some(..), defringing_kernel: Some(..),
.. ..
} => { } => {
let scale = Point2DI32::new(3, 1); let scale = Point2DI::new(3, 1);
RectI32::new(Point2DI32::default(), main_viewport.size().scale_xy(scale)) RectI::new(Point2DI::default(), main_viewport.size().scale_xy(scale))
} }
_ => main_viewport, _ => main_viewport,
} }
} }
fn main_viewport(&self) -> RectI32 { fn main_viewport(&self) -> RectI {
match self.dest_framebuffer { match self.dest_framebuffer {
DestFramebuffer::Default { viewport, .. } => viewport, DestFramebuffer::Default { viewport, .. } => viewport,
DestFramebuffer::Other(ref framebuffer) => { DestFramebuffer::Other(ref framebuffer) => {
let size = self let size = self
.device .device
.texture_size(self.device.framebuffer_texture(framebuffer)); .texture_size(self.device.framebuffer_texture(framebuffer));
RectI32::new(Point2DI32::default(), size) RectI::new(Point2DI::default(), size)
} }
} }
} }
@ -1554,8 +1554,8 @@ where
D: Device, D: Device,
{ {
Default { Default {
viewport: RectI32, viewport: RectI,
window_size: Point2DI32, window_size: Point2DI,
}, },
Other(D::Framebuffer), Other(D::Framebuffer),
} }
@ -1565,12 +1565,12 @@ where
D: Device, D: Device,
{ {
#[inline] #[inline]
pub fn full_window(window_size: Point2DI32) -> DestFramebuffer<D> { pub fn full_window(window_size: Point2DI) -> DestFramebuffer<D> {
let viewport = RectI32::new(Point2DI32::default(), window_size); let viewport = RectI::new(Point2DI::default(), window_size);
DestFramebuffer::Default { viewport, window_size } DestFramebuffer::Default { viewport, window_size }
} }
fn window_size(&self, device: &D) -> Point2DI32 { fn window_size(&self, device: &D) -> Point2DI {
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,14 +13,14 @@
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::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
use pathfinder_geometry::basic::rect::RectF32; 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;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct BuiltObject { pub(crate) struct BuiltObject {
pub bounds: RectF32, pub bounds: RectF,
pub fills: Vec<FillBatchPrimitive>, pub fills: Vec<FillBatchPrimitive>,
pub alpha_tiles: Vec<AlphaTileBatchPrimitive>, pub alpha_tiles: Vec<AlphaTileBatchPrimitive>,
pub tiles: DenseTileMap<TileObjectPrimitive>, pub tiles: DenseTileMap<TileObjectPrimitive>,
@ -38,7 +38,7 @@ pub enum RenderCommand {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct PaintData { pub struct PaintData {
pub size: Point2DI32, pub size: Point2DI,
pub texels: Vec<u8>, pub texels: Vec<u8>,
} }

View File

@ -11,9 +11,9 @@
//! 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::{Point2DF32, Point3DF32}; use pathfinder_geometry::basic::point::{Point2DF, Point3DF};
use pathfinder_geometry::basic::rect::RectF32; use pathfinder_geometry::basic::rect::RectF;
use pathfinder_geometry::basic::transform2d::Transform2DF32; use pathfinder_geometry::basic::transform2d::Transform2DF;
use pathfinder_geometry::basic::transform3d::Perspective; use pathfinder_geometry::basic::transform3d::Perspective;
use pathfinder_geometry::clip::PolygonClipper3D; use pathfinder_geometry::clip::PolygonClipper3D;
@ -34,12 +34,12 @@ where
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct RenderOptions { pub struct RenderOptions {
pub transform: RenderTransform, pub transform: RenderTransform,
pub dilation: Point2DF32, pub dilation: Point2DF,
pub subpixel_aa_enabled: bool, pub subpixel_aa_enabled: bool,
} }
impl RenderOptions { impl RenderOptions {
pub(crate) fn prepare(self, bounds: RectF32) -> PreparedRenderOptions { pub(crate) fn prepare(self, bounds: RectF) -> PreparedRenderOptions {
PreparedRenderOptions { PreparedRenderOptions {
transform: self.transform.prepare(bounds), transform: self.transform.prepare(bounds),
dilation: self.dilation, dilation: self.dilation,
@ -50,19 +50,19 @@ impl RenderOptions {
#[derive(Clone)] #[derive(Clone)]
pub enum RenderTransform { pub enum RenderTransform {
Transform2D(Transform2DF32), Transform2D(Transform2DF),
Perspective(Perspective), Perspective(Perspective),
} }
impl Default for RenderTransform { impl Default for RenderTransform {
#[inline] #[inline]
fn default() -> RenderTransform { fn default() -> RenderTransform {
RenderTransform::Transform2D(Transform2DF32::default()) RenderTransform::Transform2D(Transform2DF::default())
} }
} }
impl RenderTransform { impl RenderTransform {
fn prepare(&self, bounds: RectF32) -> PreparedRenderTransform { fn prepare(&self, bounds: RectF) -> PreparedRenderTransform {
let perspective = match self { let perspective = match self {
RenderTransform::Transform2D(ref transform) => { RenderTransform::Transform2D(ref transform) => {
if transform.is_identity() { if transform.is_identity() {
@ -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: Point2DF32, pub(crate) dilation: Point2DF,
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,
_ => [Point3DF32::default(); 4], _ => [Point3DF::default(); 4],
} }
} }
} }
pub(crate) type BoundingQuad = [Point3DF32; 4]; pub(crate) type BoundingQuad = [Point3DF; 4];
pub(crate) enum PreparedRenderTransform { pub(crate) enum PreparedRenderTransform {
None, None,
Transform2D(Transform2DF32), Transform2D(Transform2DF),
Perspective { Perspective {
perspective: Perspective, perspective: Perspective,
clip_polygon: Vec<Point2DF32>, clip_polygon: Vec<Point2DF>,
quad: [Point3DF32; 4], quad: [Point3DF; 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::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
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 = Point2DI32::new(PAINT_TEXTURE_WIDTH, PAINT_TEXTURE_HEIGHT); let size = Point2DI::new(PAINT_TEXTURE_WIDTH, PAINT_TEXTURE_HEIGHT);
let mut texels = vec![0; size.x() as usize * size.y() as usize * 4]; 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) -> Point2DI32 { pub(crate) fn paint_id_to_tex_coords(paint_id: PaintId) -> Point2DI {
let tex_coords = Point2DI32::new(paint_id.0 as i32 % PAINT_TEXTURE_WIDTH, let tex_coords = Point2DI::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) + Point2DI32::new(128, 128) tex_coords.scale(256) + Point2DI::new(128, 128)
} }

View File

@ -16,9 +16,9 @@ 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::Point2DF32; use pathfinder_geometry::basic::point::Point2DF;
use pathfinder_geometry::basic::rect::RectF32; use pathfinder_geometry::basic::rect::RectF;
use pathfinder_geometry::basic::transform2d::Transform2DF32; use pathfinder_geometry::basic::transform2d::Transform2DF;
use pathfinder_geometry::color::ColorU; use pathfinder_geometry::color::ColorU;
use pathfinder_geometry::outline::Outline; use pathfinder_geometry::outline::Outline;
use std::io::{self, Write}; use std::io::{self, Write};
@ -28,8 +28,8 @@ pub struct Scene {
pub(crate) paths: Vec<PathObject>, pub(crate) paths: Vec<PathObject>,
pub(crate) paints: Vec<Paint>, pub(crate) paints: Vec<Paint>,
paint_cache: HashMap<Paint, PaintId>, paint_cache: HashMap<Paint, PaintId>,
bounds: RectF32, bounds: RectF,
view_box: RectF32, view_box: RectF,
} }
impl Scene { impl Scene {
@ -39,8 +39,8 @@ impl Scene {
paths: vec![], paths: vec![],
paints: vec![], paints: vec![],
paint_cache: HashMap::new(), paint_cache: HashMap::new(),
bounds: RectF32::default(), bounds: RectF::default(),
view_box: RectF32::default(), view_box: RectF::default(),
} }
} }
@ -67,22 +67,22 @@ impl Scene {
} }
#[inline] #[inline]
pub fn bounds(&self) -> RectF32 { pub fn bounds(&self) -> RectF {
self.bounds self.bounds
} }
#[inline] #[inline]
pub fn set_bounds(&mut self, new_bounds: RectF32) { pub fn set_bounds(&mut self, new_bounds: RectF) {
self.bounds = new_bounds; self.bounds = new_bounds;
} }
#[inline] #[inline]
pub fn view_box(&self) -> RectF32 { pub fn view_box(&self) -> RectF {
self.view_box self.view_box
} }
#[inline] #[inline]
pub fn set_view_box(&mut self, new_view_box: RectF32) { pub fn set_view_box(&mut self, new_view_box: RectF) {
self.view_box = new_view_box; self.view_box = new_view_box;
} }
@ -116,12 +116,12 @@ impl Scene {
if options.transform.is_2d() || options.subpixel_aa_enabled { if options.transform.is_2d() || options.subpixel_aa_enabled {
let mut transform = match options.transform { let mut transform = match options.transform {
PreparedRenderTransform::Transform2D(transform) => transform, PreparedRenderTransform::Transform2D(transform) => transform,
PreparedRenderTransform::None => Transform2DF32::default(), PreparedRenderTransform::None => Transform2DF::default(),
PreparedRenderTransform::Perspective { .. } => unreachable!(), PreparedRenderTransform::Perspective { .. } => unreachable!(),
}; };
if options.subpixel_aa_enabled { if options.subpixel_aa_enabled {
transform = transform transform = transform
.post_mul(&Transform2DF32::from_scale(Point2DF32::new(3.0, 1.0))) .post_mul(&Transform2DF::from_scale(Point2DF::new(3.0, 1.0)))
} }
outline.transform(&transform); outline.transform(&transform);
} }
@ -156,9 +156,9 @@ impl Scene {
} }
#[inline] #[inline]
pub(crate) fn effective_view_box(&self, render_options: &PreparedRenderOptions) -> RectF32 { pub(crate) fn effective_view_box(&self, render_options: &PreparedRenderOptions) -> RectF {
if render_options.subpixel_aa_enabled { if render_options.subpixel_aa_enabled {
self.view_box.scale_xy(Point2DF32::new(3.0, 1.0)) self.view_box.scale_xy(Point2DF::new(3.0, 1.0))
} else { } else {
self.view_box self.view_box
} }

View File

@ -8,18 +8,18 @@
// 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::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::rect::RectI;
#[derive(Debug)] #[derive(Debug)]
pub struct DenseTileMap<T> { pub struct DenseTileMap<T> {
pub data: Vec<T>, pub data: Vec<T>,
pub rect: RectI32, pub rect: RectI,
} }
impl<T> DenseTileMap<T> { impl<T> DenseTileMap<T> {
#[inline] #[inline]
pub fn new(rect: RectI32) -> DenseTileMap<T> pub fn new(rect: RectI) -> DenseTileMap<T>
where where
T: Copy + Clone + Default, T: Copy + Clone + Default,
{ {
@ -31,7 +31,7 @@ impl<T> DenseTileMap<T> {
} }
#[inline] #[inline]
pub fn from_builder<F>(build: F, rect: RectI32) -> DenseTileMap<T> pub fn from_builder<F>(build: F, rect: RectI) -> DenseTileMap<T>
where where
F: FnMut(usize) -> T, F: FnMut(usize) -> T,
{ {
@ -43,7 +43,7 @@ impl<T> DenseTileMap<T> {
} }
#[inline] #[inline]
pub fn coords_to_index(&self, coords: Point2DI32) -> Option<usize> { pub fn coords_to_index(&self, coords: Point2DI) -> 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: Point2DI32) -> usize { pub fn coords_to_index_unchecked(&self, coords: Point2DI) -> usize {
(coords.y() - self.rect.min_y()) as usize * self.rect.size().x() as usize (coords.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) -> Point2DI32 { pub fn index_to_coords(&self, index: usize) -> Point2DI {
let (width, index) = (self.rect.size().x(), index as i32); let (width, index) = (self.rect.size().x(), index as i32);
self.rect.origin() + Point2DI32::new(index % width, index / width) self.rect.origin() + Point2DI::new(index % width, index / width)
} }
} }

View File

@ -12,9 +12,9 @@ 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::LineSegmentF32; use pathfinder_geometry::basic::line_segment::LineSegmentF;
use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; use pathfinder_geometry::basic::point::{Point2DF, Point2DI};
use pathfinder_geometry::basic::rect::{RectF32, RectI32}; 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;
use std::cmp::Ordering; use std::cmp::Ordering;
@ -44,7 +44,7 @@ impl<'a> Tiler<'a> {
pub(crate) fn new( pub(crate) fn new(
builder: &'a SceneBuilder<'a>, builder: &'a SceneBuilder<'a>,
outline: &'a Outline, outline: &'a Outline,
view_box: RectF32, view_box: RectF,
object_index: u16, object_index: u16,
paint_id: PaintId, paint_id: PaintId,
object_is_opaque: bool, object_is_opaque: bool,
@ -52,7 +52,7 @@ impl<'a> Tiler<'a> {
let bounds = outline let bounds = outline
.bounds() .bounds()
.intersection(view_box) .intersection(view_box)
.unwrap_or(RectF32::default()); .unwrap_or(RectF::default());
let built_object = BuiltObject::new(bounds); let built_object = BuiltObject::new(bounds);
Tiler { Tiler {
@ -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 = Point2DI32::new(current_tile_x, tile_y); let current_tile_coords = Point2DI::new(current_tile_x, tile_y);
self.built_object.add_active_fill( self.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 = Point2DI32::new(current_tile_x, tile_y); let current_tile_coords = Point2DI::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 = Point2DI32::new(current_tile_x, tile_y); let current_tile_coords = Point2DI::new(current_tile_x, tile_y);
self.built_object.add_active_fill( self.built_object.add_active_fill(
self.builder, self.builder,
current_x, current_x,
@ -354,8 +354,8 @@ impl<'a> Tiler<'a> {
} }
} }
pub fn round_rect_out_to_tile_bounds(rect: RectF32) -> RectI32 { pub fn round_rect_out_to_tile_bounds(rect: RectF) -> RectI {
rect.scale_xy(Point2DF32::new( rect.scale_xy(Point2DF::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: Point2DF32, crossing: Point2DF,
} }
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: &Point2DF32) -> ActiveEdge { fn from_segment_and_crossing(segment: &Segment, crossing: &Point2DF) -> 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 =
LineSegmentF32::new(self.crossing, segment.baseline.upper_point()).orient(winding); LineSegmentF::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: &LineSegmentF32, line_segment: &LineSegmentF,
builder: &SceneBuilder, builder: &SceneBuilder,
built_object: &mut BuiltObject, built_object: &mut BuiltObject,
tile_y: i32, tile_y: i32,
) -> Option<LineSegmentF32> { ) -> Option<LineSegmentF> {
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: Point2DI32, fn new(tile_coords: Point2DI,
backdrop: i8, backdrop: i8,
object_index: u16, object_index: u16,
tile_index: u16, tile_index: u16,
origin_uv: Point2DI32) origin_uv: Point2DI)
-> 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) -> Point2DI32 { pub fn tile_coords(&self) -> Point2DI {
Point2DI32::new( Point2DI::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,8 +15,8 @@ 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::Point2DI32; use pathfinder_geometry::basic::point::Point2DI;
use pathfinder_geometry::basic::rect::RectF32; 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};
@ -25,20 +25,20 @@ pub struct ZBuffer {
} }
impl ZBuffer { impl ZBuffer {
pub fn new(view_box: RectF32) -> ZBuffer { pub fn new(view_box: RectF) -> ZBuffer {
let tile_rect = tiles::round_rect_out_to_tile_bounds(view_box); let tile_rect = tiles::round_rect_out_to_tile_bounds(view_box);
ZBuffer { ZBuffer {
buffer: DenseTileMap::from_builder(|_| AtomicUsize::new(0), tile_rect), buffer: DenseTileMap::from_builder(|_| AtomicUsize::new(0), tile_rect),
} }
} }
pub fn test(&self, coords: Point2DI32, object_index: u32) -> bool { pub fn test(&self, coords: Point2DI, object_index: u32) -> bool {
let tile_index = self.buffer.coords_to_index_unchecked(coords); let 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: Point2DI32, object_index: u16) { pub fn update(&self, coords: Point2DI, 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: Point2DI32, object_index: u16, origin_uv: Point2DI32) fn new(tile_coords: Point2DI, object_index: u16, origin_uv: Point2DI)
-> 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 `Point3DF32`! // FIXME(pcwalton): Move to `Point3DF`!
#[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,10 +13,10 @@
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
use pathfinder_geometry::basic::line_segment::LineSegmentF32; use pathfinder_geometry::basic::line_segment::LineSegmentF;
use pathfinder_geometry::basic::point::Point2DF32; use pathfinder_geometry::basic::point::Point2DF;
use pathfinder_geometry::basic::rect::RectF32; use pathfinder_geometry::basic::rect::RectF;
use pathfinder_geometry::basic::transform2d::{Transform2DF32, Transform2DF32PathIter}; use pathfinder_geometry::basic::transform2d::{Transform2DF, Transform2DFPathIter};
use pathfinder_geometry::color::ColorU; use pathfinder_geometry::color::ColorU;
use pathfinder_geometry::outline::Outline; use pathfinder_geometry::outline::Outline;
use pathfinder_geometry::segment::{Segment, SegmentFlags}; use pathfinder_geometry::segment::{Segment, SegmentFlags};
@ -61,7 +61,7 @@ bitflags! {
impl BuiltSVG { impl BuiltSVG {
// TODO(pcwalton): Allow a global transform to be set. // TODO(pcwalton): Allow a global transform to be set.
pub fn from_tree(tree: Tree) -> BuiltSVG { pub fn from_tree(tree: Tree) -> BuiltSVG {
let global_transform = Transform2DF32::default(); let global_transform = Transform2DF::default();
let mut built_svg = BuiltSVG { let mut built_svg = BuiltSVG {
scene: Scene::new(), scene: Scene::new(),
@ -86,7 +86,7 @@ impl BuiltSVG {
built_svg built_svg
} }
fn process_node(&mut self, node: &Node, transform: &Transform2DF32) { fn process_node(&mut self, node: &Node, transform: &Transform2DF) {
let node_transform = usvg_transform_to_transform_2d(&node.transform()); let node_transform = usvg_transform_to_transform_2d(&node.transform());
let transform = transform.pre_mul(&node_transform); let transform = transform.pre_mul(&node_transform);
@ -122,7 +122,7 @@ impl BuiltSVG {
)); ));
let path = UsvgPathToSegments::new(path.segments.iter().cloned()); let path = UsvgPathToSegments::new(path.segments.iter().cloned());
let path = Transform2DF32PathIter::new(path, &transform); let path = Transform2DFPathIter::new(path, &transform);
let outline = Outline::from_segments(path); let outline = Outline::from_segments(path);
let name = format!("Fill({})", node.id()); let name = format!("Fill({})", node.id());
@ -265,15 +265,15 @@ impl PaintExt for Paint {
} }
} }
fn usvg_rect_to_euclid_rect(rect: &UsvgRect) -> RectF32 { fn usvg_rect_to_euclid_rect(rect: &UsvgRect) -> RectF {
RectF32::new( RectF::new(
Point2DF32::new(rect.x as f32, rect.y as f32), Point2DF::new(rect.x as f32, rect.y as f32),
Point2DF32::new(rect.width as f32, rect.height as f32), Point2DF::new(rect.width as f32, rect.height as f32),
) )
} }
fn usvg_transform_to_transform_2d(transform: &UsvgTransform) -> Transform2DF32 { fn usvg_transform_to_transform_2d(transform: &UsvgTransform) -> Transform2DF {
Transform2DF32::row_major( Transform2DF::row_major(
transform.a as f32, transform.a as f32,
transform.b as f32, transform.b as f32,
transform.c as f32, transform.c as f32,
@ -288,8 +288,8 @@ where
I: Iterator<Item = UsvgPathSegment>, I: Iterator<Item = UsvgPathSegment>,
{ {
iter: I, iter: I,
first_subpath_point: Point2DF32, first_subpath_point: Point2DF,
last_subpath_point: Point2DF32, last_subpath_point: Point2DF,
just_moved: bool, just_moved: bool,
} }
@ -300,8 +300,8 @@ where
fn new(iter: I) -> UsvgPathToSegments<I> { fn new(iter: I) -> UsvgPathToSegments<I> {
UsvgPathToSegments { UsvgPathToSegments {
iter, iter,
first_subpath_point: Point2DF32::default(), first_subpath_point: Point2DF::default(),
last_subpath_point: Point2DF32::default(), last_subpath_point: Point2DF::default(),
just_moved: false, just_moved: false,
} }
} }
@ -316,15 +316,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 = Point2DF32::new(x as f32, y as f32); let to = Point2DF::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 = Point2DF32::new(x as f32, y as f32); let to = Point2DF::new(x as f32, y as f32);
let mut segment = Segment::line(&LineSegmentF32::new(self.last_subpath_point, to)); let mut segment = Segment::line(&LineSegmentF::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);
} }
@ -340,12 +340,12 @@ where
x, x,
y, y,
} => { } => {
let ctrl0 = Point2DF32::new(x1 as f32, y1 as f32); let ctrl0 = Point2DF::new(x1 as f32, y1 as f32);
let ctrl1 = Point2DF32::new(x2 as f32, y2 as f32); let ctrl1 = Point2DF::new(x2 as f32, y2 as f32);
let to = Point2DF32::new(x as f32, y as f32); let to = Point2DF::new(x as f32, y as f32);
let mut segment = Segment::cubic( let mut segment = Segment::cubic(
&LineSegmentF32::new(self.last_subpath_point, to), &LineSegmentF::new(self.last_subpath_point, to),
&LineSegmentF32::new(ctrl0, ctrl1), &LineSegmentF::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);
@ -355,7 +355,7 @@ where
Some(segment) Some(segment)
} }
UsvgPathSegment::ClosePath => { UsvgPathSegment::ClosePath => {
let mut segment = Segment::line(&LineSegmentF32::new( let mut segment = Segment::line(&LineSegmentF::new(
self.last_subpath_point, self.last_subpath_point,
self.first_subpath_point, self.first_subpath_point,
)); ));

View File

@ -13,8 +13,8 @@ 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::Point2DF32; use pathfinder_geometry::basic::point::Point2DF;
use pathfinder_geometry::basic::transform2d::Transform2DF32; 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};
use pathfinder_renderer::paint::PaintId; use pathfinder_renderer::paint::PaintId;
@ -27,7 +27,7 @@ pub trait SceneExt {
fn push_glyph<F>(&mut self, fn push_glyph<F>(&mut self,
font: &F, font: &F,
glyph_id: u32, glyph_id: u32,
transform: &Transform2DF32, transform: &Transform2DF,
render_mode: TextRenderMode, render_mode: TextRenderMode,
hinting_options: HintingOptions, hinting_options: HintingOptions,
paint_id: PaintId) paint_id: PaintId)
@ -37,7 +37,7 @@ pub trait SceneExt {
fn push_layout(&mut self, fn push_layout(&mut self,
layout: &Layout, layout: &Layout,
style: &TextStyle, style: &TextStyle,
transform: &Transform2DF32, transform: &Transform2DF,
render_mode: TextRenderMode, render_mode: TextRenderMode,
hinting_options: HintingOptions, hinting_options: HintingOptions,
paint_id: PaintId) paint_id: PaintId)
@ -47,7 +47,7 @@ pub trait SceneExt {
text: &str, text: &str,
style: &TextStyle, style: &TextStyle,
collection: &FontCollection, collection: &FontCollection,
transform: &Transform2DF32, transform: &Transform2DF,
render_mode: TextRenderMode, render_mode: TextRenderMode,
hinting_options: HintingOptions, hinting_options: HintingOptions,
paint_id: PaintId) paint_id: PaintId)
@ -59,7 +59,7 @@ impl SceneExt for Scene {
fn push_glyph<F>(&mut self, fn push_glyph<F>(&mut self,
font: &F, font: &F,
glyph_id: u32, glyph_id: u32,
transform: &Transform2DF32, transform: &Transform2DF,
render_mode: TextRenderMode, render_mode: TextRenderMode,
hinting_options: HintingOptions, hinting_options: HintingOptions,
paint_id: PaintId) paint_id: PaintId)
@ -82,19 +82,19 @@ impl SceneExt for Scene {
fn push_layout(&mut self, fn push_layout(&mut self,
layout: &Layout, layout: &Layout,
style: &TextStyle, style: &TextStyle,
transform: &Transform2DF32, transform: &Transform2DF,
render_mode: TextRenderMode, render_mode: TextRenderMode,
hinting_options: HintingOptions, hinting_options: HintingOptions,
paint_id: PaintId) paint_id: PaintId)
-> Result<(), GlyphLoadingError> { -> Result<(), GlyphLoadingError> {
for glyph in &layout.glyphs { for glyph in &layout.glyphs {
let offset = Point2DF32::new(glyph.offset.x, glyph.offset.y); let offset = Point2DF::new(glyph.offset.x, glyph.offset.y);
let font = &*glyph.font.font; 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 = Point2DF32::new(scale, -scale); let scale = Point2DF::new(scale, -scale);
let transform = let transform =
Transform2DF32::from_scale(scale).post_mul(transform).post_translate(offset); Transform2DF::from_scale(scale).post_mul(transform).post_translate(offset);
self.push_glyph(font, self.push_glyph(font,
glyph.glyph_id, glyph.glyph_id,
&transform, &transform,
@ -110,7 +110,7 @@ impl SceneExt for Scene {
text: &str, text: &str,
style: &TextStyle, style: &TextStyle,
collection: &FontCollection, collection: &FontCollection,
transform: &Transform2DF32, transform: &Transform2DF,
render_mode: TextRenderMode, render_mode: TextRenderMode,
hinting_options: HintingOptions, hinting_options: HintingOptions,
paint_id: PaintId) paint_id: PaintId)
@ -129,11 +129,11 @@ pub enum TextRenderMode {
struct OutlinePathBuilder { struct OutlinePathBuilder {
outline: Outline, outline: Outline,
current_contour: Contour, current_contour: Contour,
transform: Transform2DF32, transform: Transform2DF,
} }
impl OutlinePathBuilder { impl OutlinePathBuilder {
fn new(transform: &Transform2DF32) -> OutlinePathBuilder { fn new(transform: &Transform2DF) -> OutlinePathBuilder {
OutlinePathBuilder { OutlinePathBuilder {
outline: Outline::new(), outline: Outline::new(),
current_contour: Contour::new(), current_contour: Contour::new(),
@ -147,8 +147,8 @@ impl OutlinePathBuilder {
} }
} }
fn convert_point(&self, point: Point2D<f32>) -> Point2DF32 { fn convert_point(&self, point: Point2D<f32>) -> Point2DF {
self.transform.transform_point(Point2DF32::new(point.x, point.y)) self.transform.transform_point(Point2DF::new(point.x, point.y))
} }
} }

View File

@ -17,8 +17,8 @@
extern crate serde_derive; extern crate serde_derive;
use hashbrown::HashMap; use hashbrown::HashMap;
use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32}; use pathfinder_geometry::basic::point::{Point2DF, Point2DI};
use pathfinder_geometry::basic::rect::RectI32; 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;
use pathfinder_gpu::{BlendState, BufferData, BufferTarget, BufferUploadMode, Device, Primitive}; use pathfinder_gpu::{BlendState, BufferData, BufferTarget, BufferUploadMode, Device, Primitive};
@ -66,9 +66,9 @@ static OUTLINE_RECT_LINE_INDICES: [u32; 8] = [0, 1, 2, 3, 4, 5, 6, 7];
pub struct UIPresenter<D> where D: Device { pub struct UIPresenter<D> where D: Device {
pub event_queue: UIEventQueue, pub event_queue: UIEventQueue,
pub mouse_position: Point2DF32, pub mouse_position: Point2DF,
framebuffer_size: Point2DI32, framebuffer_size: Point2DI,
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: Point2DI32) pub fn new(device: &D, resources: &dyn ResourceLoader, framebuffer_size: Point2DI)
-> 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: Point2DF32::default(), mouse_position: Point2DF::default(),
framebuffer_size, framebuffer_size,
@ -114,24 +114,24 @@ impl<D> UIPresenter<D> where D: Device {
} }
} }
pub fn framebuffer_size(&self) -> Point2DI32 { pub fn framebuffer_size(&self) -> Point2DI {
self.framebuffer_size self.framebuffer_size
} }
pub fn set_framebuffer_size(&mut self, window_size: Point2DI32) { pub fn set_framebuffer_size(&mut self, window_size: Point2DI) {
self.framebuffer_size = window_size; self.framebuffer_size = window_size;
} }
pub fn draw_solid_rect(&self, device: &D, rect: RectI32, color: ColorU) { pub fn draw_solid_rect(&self, device: &D, rect: RectI, color: ColorU) {
self.draw_rect(device, rect, color, true); self.draw_rect(device, rect, color, true);
} }
pub fn draw_rect_outline(&self, device: &D, rect: RectI32, color: ColorU) { pub fn draw_rect_outline(&self, device: &D, rect: RectI, color: ColorU) {
self.draw_rect(device, rect, color, false); self.draw_rect(device, rect, color, false);
} }
fn draw_rect(&self, device: &D, rect: RectI32, color: ColorU, filled: bool) { fn draw_rect(&self, device: &D, rect: RectI, color: ColorU, filled: bool) {
let vertex_data = [ let vertex_data = [
DebugSolidVertex::new(rect.origin()), DebugSolidVertex::new(rect.origin()),
DebugSolidVertex::new(rect.upper_right()), DebugSolidVertex::new(rect.upper_right()),
@ -183,7 +183,7 @@ impl<D> UIPresenter<D> where D: Device {
}); });
} }
pub fn draw_text(&self, device: &D, string: &str, origin: Point2DI32, invert: bool) { pub fn draw_text(&self, device: &D, string: &str, origin: Point2DI, invert: bool) {
let mut next = origin; let 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 =
RectI32::new(Point2DI32::new(next.x() - info.origin_x, next.y() - info.origin_y), RectI::new(Point2DI::new(next.x() - info.origin_x, next.y() - info.origin_y),
Point2DI32::new(info.width as i32, info.height as i32)); Point2DI::new(info.width as i32, info.height as i32));
let tex_coord_rect = RectI32::new(Point2DI32::new(info.x, info.y), let tex_coord_rect = RectI::new(Point2DI::new(info.x, info.y),
Point2DI32::new(info.width, info.height)); Point2DI::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: Point2DI32, origin: Point2DI,
texture: &D::Texture, texture: &D::Texture,
color: ColorU) { color: ColorU) {
let position_rect = RectI32::new(origin, device.texture_size(&texture)); let position_rect = RectI::new(origin, device.texture_size(&texture));
let tex_coord_rect = RectI32::new(Point2DI32::default(), position_rect.size()); let tex_coord_rect = RectI::new(Point2DI::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()),
@ -255,16 +255,16 @@ impl<D> UIPresenter<D> where D: Device {
SEGMENT_SIZE * segment_count as i32 + (segment_count - 1) as i32 SEGMENT_SIZE * segment_count as i32 + (segment_count - 1) as i32
} }
pub fn draw_solid_rounded_rect(&self, device: &D, rect: RectI32, color: ColorU) { pub fn draw_solid_rounded_rect(&self, device: &D, rect: RectI, color: ColorU) {
let corner_texture = self.corner_texture(true); let corner_texture = self.corner_texture(true);
let corner_rects = CornerRects::new(device, rect, corner_texture); let corner_rects = CornerRects::new(device, rect, corner_texture);
self.draw_rounded_rect_corners(device, color, corner_texture, &corner_rects); self.draw_rounded_rect_corners(device, color, corner_texture, &corner_rects);
let solid_rect_mid = RectI32::from_points(corner_rects.upper_left.upper_right(), let solid_rect_mid = RectI::from_points(corner_rects.upper_left.upper_right(),
corner_rects.lower_right.lower_left()); corner_rects.lower_right.lower_left());
let solid_rect_left = RectI32::from_points(corner_rects.upper_left.lower_left(), let solid_rect_left = RectI::from_points(corner_rects.upper_left.lower_left(),
corner_rects.lower_left.upper_right()); corner_rects.lower_left.upper_right());
let solid_rect_right = RectI32::from_points(corner_rects.upper_right.lower_left(), let solid_rect_right = RectI::from_points(corner_rects.upper_right.lower_left(),
corner_rects.lower_right.upper_right()); corner_rects.lower_right.upper_right());
let vertex_data = vec![ let vertex_data = vec![
DebugSolidVertex::new(solid_rect_mid.origin()), DebugSolidVertex::new(solid_rect_mid.origin()),
@ -295,7 +295,7 @@ impl<D> UIPresenter<D> where D: Device {
true); true);
} }
pub fn draw_rounded_rect_outline(&self, device: &D, rect: RectI32, color: ColorU) { pub fn draw_rounded_rect_outline(&self, device: &D, rect: RectI, color: ColorU) {
let corner_texture = self.corner_texture(false); let corner_texture = self.corner_texture(false);
let corner_rects = CornerRects::new(device, rect, corner_texture); let corner_rects = CornerRects::new(device, rect, corner_texture);
self.draw_rounded_rect_corners(device, color, corner_texture, &corner_rects); self.draw_rounded_rect_corners(device, color, corner_texture, &corner_rects);
@ -316,7 +316,7 @@ impl<D> UIPresenter<D> where D: Device {
} }
// TODO(pcwalton): `LineSegmentI32`. // TODO(pcwalton): `LineSegmentI32`.
fn draw_line(&self, device: &D, from: Point2DI32, to: Point2DI32, color: ColorU) { fn draw_line(&self, device: &D, from: Point2DI, to: Point2DI, color: ColorU) {
let vertex_data = vec![DebugSolidVertex::new(from), DebugSolidVertex::new(to)]; 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 = RectI32::new(Point2DI32::default(), corner_size); let tex_coord_rect = RectI::new(Point2DI::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: Point2DI32, texture: &D::Texture) -> bool { pub fn draw_button(&mut self, device: &D, origin: Point2DI, texture: &D::Texture) -> bool {
let button_rect = RectI32::new(origin, Point2DI32::new(BUTTON_WIDTH, BUTTON_HEIGHT)); let button_rect = RectI::new(origin, Point2DI::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 + Point2DI32::new(PADDING, PADDING), origin + Point2DI::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: Point2DI32, mut origin: Point2DI,
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 + Point2DI32::new(0, BUTTON_TEXT_OFFSET); origin = origin + Point2DI::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 + Point2DI32::new(offset, 0), origin + Point2DI::new(offset, 0),
segment_index as u8 == value); segment_index as u8 == value);
origin += Point2DI32::new(SEGMENT_SIZE + 1, 0); origin += Point2DI::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: Point2DI32, mut origin: Point2DI,
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 = Point2DI32::new(SEGMENT_SIZE / 2 - texture_width / 2, PADDING); let offset = Point2DI::new(SEGMENT_SIZE / 2 - texture_width / 2, PADDING);
let color = if Some(segment_index as u8) == value { 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 += Point2DI32::new(SEGMENT_SIZE + 1, 0); origin += Point2DI::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: Point2DI32, origin: Point2DI,
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 = RectI32::new(origin, Point2DI32::new(widget_width, BUTTON_HEIGHT)); let widget_rect = RectI::new(origin, Point2DI::new(widget_width, BUTTON_HEIGHT));
let mut clicked_segment = None; 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 = Point2DI32::new(SEGMENT_SIZE, BUTTON_HEIGHT); let highlight_size = Point2DI::new(SEGMENT_SIZE, BUTTON_HEIGHT);
let x_offset = value as i32 * SEGMENT_SIZE + (value as i32 - 1); let x_offset = value as i32 * SEGMENT_SIZE + (value as i32 - 1);
self.draw_solid_rounded_rect(device, self.draw_solid_rounded_rect(device,
RectI32::new(origin + Point2DI32::new(x_offset, 0), RectI::new(origin + Point2DI::new(x_offset, 0),
highlight_size), highlight_size),
TEXT_COLOR); TEXT_COLOR);
} }
let mut segment_origin = origin + Point2DI32::new(SEGMENT_SIZE + 1, 0); let mut segment_origin = origin + Point2DI::new(SEGMENT_SIZE + 1, 0);
for next_segment_index in 1..segment_count { 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,29 +521,29 @@ impl<D> UIPresenter<D> where D: Device {
_ => { _ => {
self.draw_line(device, self.draw_line(device,
segment_origin, segment_origin,
segment_origin + Point2DI32::new(0, BUTTON_HEIGHT), segment_origin + Point2DI::new(0, BUTTON_HEIGHT),
TEXT_COLOR); TEXT_COLOR);
} }
} }
segment_origin = segment_origin + Point2DI32::new(SEGMENT_SIZE + 1, 0); segment_origin = segment_origin + Point2DI::new(SEGMENT_SIZE + 1, 0);
} }
clicked_segment clicked_segment
} }
pub fn draw_tooltip(&self, device: &D, string: &str, rect: RectI32) { pub fn draw_tooltip(&self, device: &D, string: &str, rect: RectI) {
if !rect.to_f32().contains_point(self.mouse_position) { if !rect.to_f32().contains_point(self.mouse_position) {
return; return;
} }
let text_size = self.measure_text(string); let text_size = self.measure_text(string);
let window_size = Point2DI32::new(text_size + PADDING * 2, TOOLTIP_HEIGHT); let window_size = Point2DI::new(text_size + PADDING * 2, TOOLTIP_HEIGHT);
let origin = rect.origin() - Point2DI32::new(0, window_size.y() + PADDING); let origin = rect.origin() - Point2DI::new(0, window_size.y() + PADDING);
self.draw_solid_rounded_rect(device, RectI32::new(origin, window_size), WINDOW_COLOR); self.draw_solid_rounded_rect(device, RectI::new(origin, window_size), WINDOW_COLOR);
self.draw_text(device, self.draw_text(device,
string, string,
origin + Point2DI32::new(PADDING, PADDING + FONT_ASCENT), origin + Point2DI::new(PADDING, PADDING + FONT_ASCENT),
false); false);
} }
} }
@ -668,7 +668,7 @@ struct DebugTextureVertex {
} }
impl DebugTextureVertex { impl DebugTextureVertex {
fn new(position: Point2DI32, tex_coord: Point2DI32) -> DebugTextureVertex { fn new(position: Point2DI, tex_coord: Point2DI) -> 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,26 +687,26 @@ struct DebugSolidVertex {
} }
impl DebugSolidVertex { impl DebugSolidVertex {
fn new(position: Point2DI32) -> DebugSolidVertex { fn new(position: Point2DI) -> DebugSolidVertex {
DebugSolidVertex { position_x: position.x() as i16, position_y: position.y() as i16 } DebugSolidVertex { position_x: position.x() as i16, position_y: position.y() as i16 }
} }
} }
struct CornerRects { struct CornerRects {
upper_left: RectI32, upper_left: RectI,
upper_right: RectI32, upper_right: RectI,
lower_left: RectI32, lower_left: RectI,
lower_right: RectI32, lower_right: RectI,
} }
impl CornerRects { impl CornerRects {
fn new<D>(device: &D, rect: RectI32, texture: &D::Texture) -> CornerRects where D: Device { fn new<D>(device: &D, rect: RectI, texture: &D::Texture) -> CornerRects where D: Device {
let size = device.texture_size(texture); let size = device.texture_size(texture);
CornerRects { CornerRects {
upper_left: RectI32::new(rect.origin(), size), upper_left: RectI::new(rect.origin(), size),
upper_right: RectI32::new(rect.upper_right() - Point2DI32::new(size.x(), 0), size), upper_right: RectI::new(rect.upper_right() - Point2DI::new(size.x(), 0), size),
lower_left: RectI32::new(rect.lower_left() - Point2DI32::new(0, size.y()), size), lower_left: RectI::new(rect.lower_left() - Point2DI::new(0, size.y()), size),
lower_right: RectI32::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: RectI32) -> Option<Point2DI32> { pub fn handle_mouse_down_in_rect(&mut self, rect: RectI) -> Option<Point2DI> {
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: RectI32) -> Option<Point2DI32> { pub fn handle_mouse_down_or_dragged_in_rect(&mut self, rect: RectI) -> Option<Point2DI> {
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: Point2DI32, pub absolute: Point2DI,
pub relative: Point2DI32, pub relative: Point2DI,
} }
#[derive(Deserialize)] #[derive(Deserialize)]