Remove the now-obsolete path legalizer

This commit is contained in:
Patrick Walton 2017-10-02 11:40:11 -07:00
parent 60ff71be84
commit 705274997d
3 changed files with 0 additions and 229 deletions

View File

@ -2,7 +2,6 @@
use env_logger;
use euclid::Point2D;
use legalizer::Legalizer;
use partitioner::Partitioner;
use std::mem;
use std::slice;
@ -55,87 +54,6 @@ pub struct EdgeIndices {
pub lower_curve_indices_len: u32,
}
#[no_mangle]
pub unsafe extern fn pf_legalizer_new() -> *mut Legalizer {
let mut legalizer = Box::new(Legalizer::new());
let legalizer_ptr: *mut Legalizer = &mut *legalizer;
mem::forget(legalizer);
legalizer_ptr
}
#[no_mangle]
pub unsafe extern fn pf_legalizer_destroy(legalizer: *mut Legalizer) {
drop(mem::transmute::<*mut Legalizer, Box<Legalizer>>(legalizer))
}
#[no_mangle]
pub unsafe extern fn pf_legalizer_endpoints(legalizer: *const Legalizer,
out_endpoint_count: *mut u32)
-> *const Endpoint {
let endpoints = (*legalizer).endpoints();
if !out_endpoint_count.is_null() {
*out_endpoint_count = endpoints.len() as u32
}
endpoints.as_ptr()
}
#[no_mangle]
pub unsafe extern fn pf_legalizer_control_points(legalizer: *const Legalizer,
out_control_points_count: *mut u32)
-> *const Point2DF32 {
let control_points = (*legalizer).control_points();
if !out_control_points_count.is_null() {
*out_control_points_count = control_points.len() as u32
}
// FIXME(pcwalton): This is unsafe! `Point2D<f32>` and `Point2DF32` may have different layouts!
control_points.as_ptr() as *const Point2DF32
}
#[no_mangle]
pub unsafe extern fn pf_legalizer_subpaths(legalizer: *const Legalizer,
out_subpaths_count: *mut u32)
-> *const Subpath {
let subpaths = (*legalizer).subpaths();
if !out_subpaths_count.is_null() {
*out_subpaths_count = subpaths.len() as u32
}
subpaths.as_ptr()
}
#[no_mangle]
pub unsafe extern fn pf_legalizer_move_to(legalizer: *mut Legalizer,
position: *const Point2DF32) {
(*legalizer).move_to(&(*position).to_point2d())
}
#[no_mangle]
pub unsafe extern fn pf_legalizer_close_path(legalizer: *mut Legalizer) {
(*legalizer).close_path()
}
#[no_mangle]
pub unsafe extern fn pf_legalizer_line_to(legalizer: *mut Legalizer,
endpoint: *const Point2DF32) {
(*legalizer).line_to(&(*endpoint).to_point2d())
}
#[no_mangle]
pub unsafe extern fn pf_legalizer_quadratic_curve_to(legalizer: *mut Legalizer,
control_point: *const Point2DF32,
endpoint: *const Point2DF32) {
(*legalizer).quadratic_curve_to(&(*control_point).to_point2d(), &(*endpoint).to_point2d())
}
#[no_mangle]
pub unsafe extern fn pf_legalizer_bezier_curve_to(legalizer: *mut Legalizer,
point1: *const Point2DF32,
point2: *const Point2DF32,
endpoint: *const Point2DF32) {
(*legalizer).bezier_curve_to(&(*point1).to_point2d(),
&(*point2).to_point2d(),
&(*endpoint).to_point2d())
}
#[no_mangle]
pub unsafe extern fn pf_partitioner_new() -> *mut Partitioner<'static> {
let mut partitioner = Box::new(Partitioner::new());

View File

@ -1,144 +0,0 @@
// partitionfinder/legalizer.rs
use euclid::Point2D;
use geometry::{QuadraticBezierInflectionPoints, SubdividedQuadraticBezier};
use std::u32;
use {Endpoint, Subpath};
pub struct Legalizer {
endpoints: Vec<Endpoint>,
control_points: Vec<Point2D<f32>>,
subpaths: Vec<Subpath>,
}
impl Legalizer {
#[inline]
pub fn new() -> Legalizer {
Legalizer {
endpoints: vec![],
control_points: vec![],
subpaths: vec![],
}
}
#[inline]
pub fn endpoints(&self) -> &[Endpoint] {
&self.endpoints
}
#[inline]
pub fn control_points(&self) -> &[Point2D<f32>] {
&self.control_points
}
#[inline]
pub fn subpaths(&self) -> &[Subpath] {
&self.subpaths
}
pub fn move_to(&mut self, position: &Point2D<f32>) {
self.subpaths.push(Subpath {
first_endpoint_index: self.endpoints.len() as u32,
last_endpoint_index: self.endpoints.len() as u32 + 1,
});
self.endpoints.push(Endpoint {
position: *position,
control_point_index: u32::MAX,
subpath_index: (self.subpaths.len() - 1) as u32,
})
}
#[inline]
pub fn close_path(&mut self) {
// All paths are implicitly closed.
}
pub fn line_to(&mut self, endpoint: &Point2D<f32>) {
self.subpaths
.last_mut()
.expect("`line_to()` called with no current subpath")
.last_endpoint_index += 1;
self.endpoints.push(Endpoint {
position: *endpoint,
control_point_index: u32::MAX,
subpath_index: (self.subpaths.len() - 1) as u32,
})
}
fn monotone_quadratic_curve_to(&mut self,
control_point: &Point2D<f32>,
endpoint: &Point2D<f32>) {
self.subpaths
.last_mut()
.expect("`quadratic_curve_to()` called with no current subpath")
.last_endpoint_index += 1;
self.endpoints.push(Endpoint {
position: *endpoint,
control_point_index: self.control_points.len() as u32,
subpath_index: (self.subpaths.len() - 1) as u32,
});
self.control_points.push(*control_point)
}
pub fn quadratic_curve_to(&mut self, control_point: &Point2D<f32>, endpoint: &Point2D<f32>) {
let last_endpoint_index =
self.subpaths
.last()
.expect("`quadratic_curve_to()` called with no current subpath")
.last_endpoint_index;
let point0 = self.endpoints[last_endpoint_index as usize - 1].position;
match QuadraticBezierInflectionPoints::calculate(&point0, control_point, endpoint) {
QuadraticBezierInflectionPoints {
xt: Some(xt),
yt: Some(yt),
} => {
let subdivision = SubdividedQuadraticBezier::new(f32::min(xt, yt),
&point0,
control_point,
endpoint);
self.monotone_quadratic_curve_to(&subdivision.ap1, &subdivision.ap2bp0);
self.quadratic_curve_to(&subdivision.bp1, &subdivision.bp2)
}
QuadraticBezierInflectionPoints {
xt: Some(t),
yt: None,
} |
QuadraticBezierInflectionPoints {
xt: None,
yt: Some(t),
} => {
let subdivision = SubdividedQuadraticBezier::new(t,
&point0,
control_point,
endpoint);
self.monotone_quadratic_curve_to(&subdivision.ap1, &subdivision.ap2bp0);
self.quadratic_curve_to(&subdivision.bp1, &subdivision.bp2)
}
QuadraticBezierInflectionPoints {
xt: None,
yt: None,
} => {
self.monotone_quadratic_curve_to(control_point, endpoint)
}
}
}
pub fn bezier_curve_to(&mut self,
point1: &Point2D<f32>,
point2: &Point2D<f32>,
endpoint: &Point2D<f32>) {
// https://stackoverflow.com/a/2029695
//
// FIXME(pcwalton): Reimplement subdivision!
let last_endpoint_index = self.subpaths
.last()
.expect("`bezier_curve_to()` called with no current subpath")
.last_endpoint_index;
let point0 = self.endpoints[last_endpoint_index as usize - 1].position;
let control_point = ((point1.to_vector() + point2.to_vector()) * 0.75 -
(point0.to_vector() + endpoint.to_vector()) * 0.25).to_point();
self.quadratic_curve_to(&control_point, endpoint)
}
}

View File

@ -15,11 +15,9 @@ extern crate alloc_jemalloc;
extern crate bit_vec;
extern crate env_logger;
extern crate euclid;
extern crate half;
#[macro_use]
extern crate log;
extern crate pathfinder_path_utils;
extern crate serde;
#[macro_use]
extern crate serde_derive;
@ -29,7 +27,6 @@ use std::u32;
pub mod capi;
pub mod geometry;
pub mod legalizer;
pub mod partitioner;
#[repr(C)]