Remove `Point3DF32`

This commit is contained in:
Patrick Walton 2019-02-01 17:05:35 -08:00
parent 42bb7acddb
commit 6a286ab153
3 changed files with 6 additions and 61 deletions

View File

@ -119,55 +119,6 @@ impl Mul<Point2DF32> for Point2DF32 {
}
}
// 3D points.
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct Point3DF32(pub F32x4);
impl Point3DF32 {
#[inline]
pub fn new(x: f32, y: f32, z: f32) -> Point3DF32 {
Point3DF32(F32x4::new(x, y, z, 1.0))
}
#[inline]
pub fn from_euclid_2d(point: &Point2D<f32>) -> Point3DF32 {
Point3DF32::new(point.x, point.y, 0.0)
}
#[inline]
pub fn x(self) -> f32 {
self.0[0]
}
#[inline]
pub fn y(self) -> f32 {
self.0[1]
}
#[inline]
pub fn z(self) -> f32 {
self.0[2]
}
#[inline]
pub fn to_2d(self) -> Point2DF32 {
Point2DF32(self.0)
}
#[inline]
pub fn to_4d(self) -> Point4DF32 {
let mut point = Point4DF32(self.0);
point.set_w(1.0);
point
}
#[inline]
pub fn lerp(self, other: Point3DF32, t: f32) -> Point3DF32 {
Point3DF32(self.0 + (other.0 - self.0) * F32x4::splat(t))
}
}
// 3D homogeneous points.
#[derive(Clone, Copy, Debug, PartialEq, Default)]
@ -235,8 +186,8 @@ impl Point4DF32 {
}
#[inline]
pub fn perspective_divide(self) -> Point3DF32 {
Point3DF32(self.0 * F32x4::splat(1.0 / self.w()))
pub fn perspective_divide(self) -> Point4DF32 {
Point4DF32(self.0 * F32x4::splat(1.0 / self.w()))
}
#[inline]

View File

@ -10,7 +10,7 @@
//! 3D transforms that can be applied to paths.
use crate::point::{Point2DF32, Point3DF32, Point4DF32};
use crate::point::{Point2DF32, Point4DF32};
use crate::segment::Segment;
use crate::transform::Matrix2x2F32;
use euclid::{Point2D, Rect, Size2D};
@ -179,12 +179,6 @@ impl Transform3DF32 {
Point4DF32(term0 + term1 + term2 + term3)
}
#[inline]
pub fn transform_point_3d(&self, point: Point3DF32) -> Point3DF32 {
let point4d = self.transform_point(point.to_4d());
point4d.perspective_divide()
}
#[inline]
pub fn upper_left(&self) -> Matrix2x2F32 {
Matrix2x2F32(self.c0.concat_xy_xy(self.c1))

View File

@ -18,7 +18,7 @@ use euclid::Rect;
use hashbrown::HashMap;
use pathfinder_geometry::clip::PolygonClipper3D;
use pathfinder_geometry::outline::Outline;
use pathfinder_geometry::point::{Point2DF32, Point3DF32, Point4DF32};
use pathfinder_geometry::point::{Point2DF32, Point4DF32};
use pathfinder_geometry::transform3d::Perspective;
use pathfinder_geometry::transform::Transform2DF32;
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator};
@ -137,7 +137,7 @@ impl Scene {
let quad = self.clip_bounding_quad_with_perspective(perspective);
let inverse_transform = perspective.transform.inverse();
quad.into_iter()
.map(|point| inverse_transform.transform_point_3d(point).to_2d())
.map(|point| inverse_transform.transform_point(point).perspective_divide().to_2d())
.collect()
}
@ -168,7 +168,7 @@ impl Scene {
self.update_bounds();
}
fn clip_bounding_quad_with_perspective(&self, perspective: &Perspective) -> Vec<Point3DF32> {
fn clip_bounding_quad_with_perspective(&self, perspective: &Perspective) -> Vec<Point4DF32> {
let mut points = vec![
Point4DF32::from_euclid_2d(&self.bounds.origin),
Point4DF32::from_euclid_2d(&self.bounds.top_right()),