Remove barrel distortion.
It was a toy implementation and isn't the approach I want to go with.
This commit is contained in:
parent
deecdb12de
commit
d06746f28d
|
@ -14,7 +14,6 @@ use gl::types::GLuint;
|
||||||
use pathfinder_geometry::basic::point::Point2DI32;
|
use pathfinder_geometry::basic::point::Point2DI32;
|
||||||
use pathfinder_geometry::basic::rect::RectI32;
|
use pathfinder_geometry::basic::rect::RectI32;
|
||||||
use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF32};
|
use pathfinder_geometry::basic::transform3d::{Perspective, Transform3DF32};
|
||||||
use pathfinder_geometry::distortion::BarrelDistortionCoefficients;
|
|
||||||
use pathfinder_gl::GLVersion;
|
use pathfinder_gl::GLVersion;
|
||||||
use pathfinder_gpu::resources::ResourceLoader;
|
use pathfinder_gpu::resources::ResourceLoader;
|
||||||
use rayon::ThreadPoolBuilder;
|
use rayon::ThreadPoolBuilder;
|
||||||
|
@ -35,11 +34,6 @@ pub trait Window {
|
||||||
fn adjust_thread_pool_settings(&self, thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder {
|
fn adjust_thread_pool_settings(&self, thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder {
|
||||||
thread_pool_builder
|
thread_pool_builder
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn barrel_distortion_coefficients(&self) -> BarrelDistortionCoefficients {
|
|
||||||
BarrelDistortionCoefficients::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
// pathfinder/geometry/src/distortion.rs
|
|
||||||
//
|
|
||||||
// Copyright © 2019 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 crate::basic::point::{Point2DF32, Point2DI32};
|
|
||||||
use crate::outline::{self, Contour};
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct BarrelDistortionCoefficients {
|
|
||||||
pub k0: f32,
|
|
||||||
pub k1: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for BarrelDistortionCoefficients {
|
|
||||||
// Matches Google Daydream (Cardboard v2.2).
|
|
||||||
#[inline]
|
|
||||||
fn default() -> BarrelDistortionCoefficients {
|
|
||||||
BarrelDistortionCoefficients { k0: 0.34, k1: 0.55 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ContourBarrelDistorter<'a> {
|
|
||||||
contour: &'a mut Contour,
|
|
||||||
window_size: Point2DI32,
|
|
||||||
coefficients: BarrelDistortionCoefficients,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ContourBarrelDistorter<'a> {
|
|
||||||
pub fn new(contour: &'a mut Contour,
|
|
||||||
coefficients: BarrelDistortionCoefficients,
|
|
||||||
window_size: Point2DI32)
|
|
||||||
-> ContourBarrelDistorter<'a> {
|
|
||||||
ContourBarrelDistorter { contour, window_size, coefficients }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn distort(&mut self) {
|
|
||||||
let one = Point2DF32::splat(1.0);
|
|
||||||
let window_size = self.window_size.to_f32();
|
|
||||||
let inv_window_size = Point2DF32(window_size.0.approx_recip());
|
|
||||||
let BarrelDistortionCoefficients { k0, k1 } = self.coefficients;
|
|
||||||
|
|
||||||
let point_count = self.contour.len();
|
|
||||||
for point_index in 0..point_count {
|
|
||||||
// Convert from window coordinates to NDC.
|
|
||||||
let mut position = self.contour.position_of(point_index);
|
|
||||||
position = position.scale_xy(inv_window_size).scale(2.0) - one;
|
|
||||||
|
|
||||||
// Apply distortion.
|
|
||||||
let r2 = position.square_length();
|
|
||||||
let scaling = 1.0 + k0 * r2 + k1 * r2 * r2;
|
|
||||||
position = position.scale(1.0 / scaling);
|
|
||||||
|
|
||||||
// Convert back to window coordinates.
|
|
||||||
position = (position + one).scale(0.5).scale_xy(window_size);
|
|
||||||
|
|
||||||
// Store resulting point.
|
|
||||||
self.contour.points[point_index as usize] = position;
|
|
||||||
outline::union_rect(&mut self.contour.bounds, position, point_index == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,7 +18,6 @@ extern crate bitflags;
|
||||||
pub mod basic;
|
pub mod basic;
|
||||||
pub mod clip;
|
pub mod clip;
|
||||||
pub mod color;
|
pub mod color;
|
||||||
pub mod distortion;
|
|
||||||
pub mod monotonic;
|
pub mod monotonic;
|
||||||
pub mod orientation;
|
pub mod orientation;
|
||||||
pub mod outline;
|
pub mod outline;
|
||||||
|
|
|
@ -11,13 +11,12 @@
|
||||||
//! 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::LineSegmentF32;
|
||||||
use crate::basic::point::{Point2DF32, Point2DI32};
|
use crate::basic::point::Point2DF32;
|
||||||
use crate::basic::rect::RectF32;
|
use crate::basic::rect::RectF32;
|
||||||
use crate::basic::transform2d::Transform2DF32;
|
use crate::basic::transform2d::Transform2DF32;
|
||||||
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;
|
||||||
use crate::distortion::{BarrelDistortionCoefficients, ContourBarrelDistorter};
|
|
||||||
use crate::orientation::Orientation;
|
use crate::orientation::Orientation;
|
||||||
use crate::segment::{Segment, SegmentFlags, SegmentKind};
|
use crate::segment::{Segment, SegmentFlags, SegmentKind};
|
||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
|
@ -136,17 +135,6 @@ impl Outline {
|
||||||
self.bounds = self.bounds.dilate(amount);
|
self.bounds = self.bounds.dilate(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn barrel_distort(&mut self,
|
|
||||||
coefficients: BarrelDistortionCoefficients,
|
|
||||||
window_size: Point2DI32) {
|
|
||||||
let mut new_bounds = None;
|
|
||||||
for contour in &mut self.contours {
|
|
||||||
contour.barrel_distort(coefficients, window_size);
|
|
||||||
contour.update_bounds(&mut new_bounds);
|
|
||||||
}
|
|
||||||
self.bounds = new_bounds.unwrap_or_else(|| RectF32::default());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prepare_for_tiling(&mut self, view_box: RectF32) {
|
pub fn prepare_for_tiling(&mut self, view_box: RectF32) {
|
||||||
self.contours.iter_mut().for_each(|contour| contour.prepare_for_tiling(view_box));
|
self.contours.iter_mut().for_each(|contour| contour.prepare_for_tiling(view_box));
|
||||||
self.bounds = self.bounds.intersection(view_box).unwrap_or_else(|| RectF32::default());
|
self.bounds = self.bounds.intersection(view_box).unwrap_or_else(|| RectF32::default());
|
||||||
|
@ -431,12 +419,6 @@ impl Contour {
|
||||||
self.bounds = self.bounds.dilate(amount);
|
self.bounds = self.bounds.dilate(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn barrel_distort(&mut self,
|
|
||||||
coefficients: BarrelDistortionCoefficients,
|
|
||||||
window_size: Point2DI32) {
|
|
||||||
ContourBarrelDistorter::new(self, coefficients, window_size).distort();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn prepare_for_tiling(&mut self, view_box: RectF32) {
|
fn prepare_for_tiling(&mut self, view_box: RectF32) {
|
||||||
// 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.
|
||||||
|
|
Loading…
Reference in New Issue