Remove the duplicated de Casteljau subdivision code in
`partitioner::geometry`
This commit is contained in:
parent
705274997d
commit
8c6110a388
|
@ -1,68 +0,0 @@
|
||||||
// pathfinder/partitioner/src/geometry.rs
|
|
||||||
//
|
|
||||||
// Copyright © 2017 The Pathfinder Project Developers.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
use euclid::Point2D;
|
|
||||||
use euclid::approxeq::ApproxEq;
|
|
||||||
|
|
||||||
fn quadratic_bezier_axis_inflection_point(p0: f32, p1: f32, p2: f32) -> Option<f32> {
|
|
||||||
let t = (p0 - p1) / (p0 - 2.0 * p1 + p2);
|
|
||||||
if t > f32::approx_epsilon() && t < 1.0 - f32::approx_epsilon() {
|
|
||||||
Some(t)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct QuadraticBezierInflectionPoints {
|
|
||||||
pub xt: Option<f32>,
|
|
||||||
pub yt: Option<f32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl QuadraticBezierInflectionPoints {
|
|
||||||
pub fn calculate(p0: &Point2D<f32>, p1: &Point2D<f32>, p2: &Point2D<f32>)
|
|
||||||
-> QuadraticBezierInflectionPoints {
|
|
||||||
if ((*p1 - *p0).length() + (*p2 - *p1).length()).abs() < f32::approx_epsilon() {
|
|
||||||
QuadraticBezierInflectionPoints {
|
|
||||||
xt: None,
|
|
||||||
yt: None,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
QuadraticBezierInflectionPoints {
|
|
||||||
xt: quadratic_bezier_axis_inflection_point(p0.x, p1.x, p2.x),
|
|
||||||
yt: quadratic_bezier_axis_inflection_point(p0.y, p1.y, p2.y),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct SubdividedQuadraticBezier {
|
|
||||||
pub ap0: Point2D<f32>,
|
|
||||||
pub ap1: Point2D<f32>,
|
|
||||||
pub ap2bp0: Point2D<f32>,
|
|
||||||
pub bp1: Point2D<f32>,
|
|
||||||
pub bp2: Point2D<f32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SubdividedQuadraticBezier {
|
|
||||||
pub fn new(t: f32, p0: &Point2D<f32>, p1: &Point2D<f32>, p2: &Point2D<f32>)
|
|
||||||
-> SubdividedQuadraticBezier {
|
|
||||||
let (ap1, bp1) = (p0.lerp(*p1, t), p1.lerp(*p2, t));
|
|
||||||
let ap2bp0 = ap1.lerp(bp1, t);
|
|
||||||
SubdividedQuadraticBezier {
|
|
||||||
ap0: *p0,
|
|
||||||
ap1: ap1,
|
|
||||||
ap2bp0: ap2bp0,
|
|
||||||
bp1: bp1,
|
|
||||||
bp2: *p2,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -26,7 +26,6 @@ use pathfinder_path_utils::{Endpoint, Subpath};
|
||||||
use std::u32;
|
use std::u32;
|
||||||
|
|
||||||
pub mod capi;
|
pub mod capi;
|
||||||
pub mod geometry;
|
|
||||||
pub mod partitioner;
|
pub mod partitioner;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
use bit_vec::BitVec;
|
use bit_vec::BitVec;
|
||||||
use euclid::approxeq::ApproxEq;
|
use euclid::approxeq::ApproxEq;
|
||||||
use euclid::Point2D;
|
use euclid::Point2D;
|
||||||
use geometry::SubdividedQuadraticBezier;
|
|
||||||
use log::LogLevel;
|
use log::LogLevel;
|
||||||
use pathfinder_path_utils::PathBuffer;
|
use pathfinder_path_utils::PathBuffer;
|
||||||
use pathfinder_path_utils::curve::Curve;
|
use pathfinder_path_utils::curve::Curve;
|
||||||
|
@ -1064,33 +1063,34 @@ impl<'a> Partitioner<'a> {
|
||||||
_ => {
|
_ => {
|
||||||
let left_endpoint_position =
|
let left_endpoint_position =
|
||||||
self.b_vertex_positions[active_edge.left_vertex_index as usize];
|
self.b_vertex_positions[active_edge.left_vertex_index as usize];
|
||||||
|
let control_point_position =
|
||||||
|
self.b_vertex_positions[active_edge.control_point_vertex_index as usize];
|
||||||
let right_endpoint_position =
|
let right_endpoint_position =
|
||||||
self.endpoints[active_edge.right_endpoint_index as usize].position;
|
self.endpoints[active_edge.right_endpoint_index as usize].position;
|
||||||
let subdivided_quadratic_bezier = SubdividedQuadraticBezier::new(
|
let original_curve = Curve::new(&left_endpoint_position,
|
||||||
t,
|
&control_point_position,
|
||||||
&left_endpoint_position,
|
|
||||||
&self.b_vertex_positions[active_edge.control_point_vertex_index as usize],
|
|
||||||
&right_endpoint_position);
|
&right_endpoint_position);
|
||||||
|
let (left_curve, right_curve) = original_curve.subdivide(t);
|
||||||
|
|
||||||
left_curve_control_point_vertex_index = self.b_vertex_loop_blinn_data.len() as u32;
|
left_curve_control_point_vertex_index = self.b_vertex_loop_blinn_data.len() as u32;
|
||||||
active_edge.left_vertex_index = left_curve_control_point_vertex_index + 1;
|
active_edge.left_vertex_index = left_curve_control_point_vertex_index + 1;
|
||||||
active_edge.control_point_vertex_index = left_curve_control_point_vertex_index + 2;
|
active_edge.control_point_vertex_index = left_curve_control_point_vertex_index + 2;
|
||||||
|
|
||||||
self.b_vertex_positions.extend([
|
self.b_vertex_positions.extend([
|
||||||
subdivided_quadratic_bezier.ap1,
|
left_curve.control_point,
|
||||||
subdivided_quadratic_bezier.ap2bp0,
|
left_curve.endpoints[1],
|
||||||
subdivided_quadratic_bezier.bp1,
|
right_curve.control_point,
|
||||||
].into_iter());
|
].into_iter());
|
||||||
self.b_vertex_path_ids.extend(iter::repeat(self.path_id).take(3));
|
self.b_vertex_path_ids.extend(iter::repeat(self.path_id).take(3));
|
||||||
self.b_vertex_loop_blinn_data.extend([
|
self.b_vertex_loop_blinn_data.extend([
|
||||||
BVertexLoopBlinnData::control_point(&left_endpoint_position,
|
BVertexLoopBlinnData::control_point(&left_curve.endpoints[0],
|
||||||
&subdivided_quadratic_bezier.ap1,
|
&left_curve.control_point,
|
||||||
&subdivided_quadratic_bezier.ap2bp0,
|
&left_curve.endpoints[1],
|
||||||
bottom),
|
bottom),
|
||||||
BVertexLoopBlinnData::new(active_edge.endpoint_kind()),
|
BVertexLoopBlinnData::new(active_edge.endpoint_kind()),
|
||||||
BVertexLoopBlinnData::control_point(&subdivided_quadratic_bezier.ap2bp0,
|
BVertexLoopBlinnData::control_point(&right_curve.endpoints[0],
|
||||||
&subdivided_quadratic_bezier.bp1,
|
&right_curve.control_point,
|
||||||
&right_endpoint_position,
|
&right_curve.endpoints[1],
|
||||||
bottom),
|
bottom),
|
||||||
].into_iter());
|
].into_iter());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue