pub mod aabb2;
pub mod align2;
mod angles2;
mod arc2;
mod boundary2;
mod circle2;
mod cubic_spline2;
mod curve2;
mod curve_group2;
pub mod hull;
mod iso2;
mod line2;
pub mod polyline2;
mod segment2;
use crate::AngleDir;
use crate::AngleDir::Cw;
use crate::common::surface_point::SurfacePoint;
use crate::common::svd_basis::SvdBasis;
use crate::common::{PCoords, SPCoords, SurfacePointCollection};
use crate::na::SVector;
use parry2d_f64::na::UnitComplex;
use serde::{Deserialize, Serialize};
use std::ops;
pub type Point2 = parry2d_f64::na::Point2<f64>;
pub type Vector2 = parry2d_f64::na::Vector2<f64>;
pub type UnitVec2 = parry2d_f64::na::Unit<Vector2>;
pub type Iso2 = parry2d_f64::na::Isometry2<f64>;
pub type SvdBasis2 = SvdBasis<2>;
pub type Ray2 = parry2d_f64::query::Ray;
pub type Align2 = crate::common::align::Alignment<UnitComplex<f64>, 2>;
pub type AlignOutcome2 = crate::common::align::AlignOutcome<UnitComplex<f64>, 2>;
pub type MultiOutcome2 = crate::common::align::MultiOutcome<UnitComplex<f64>, 2>;
pub type KdTree2 = crate::common::kd_tree::KdTree<2>;
pub type SurfacePoint2 = SurfacePoint<2>;
pub use self::aabb2::Aabb2;
pub use self::angles2::{directed_angle, rot90, rot270, signed_angle};
pub use self::arc2::Arc2;
pub use self::boundary2::*;
pub use self::circle2::{Circle2, CircleTangency};
pub use self::cubic_spline2::CubicSpline2;
pub use self::curve_group2::CurveGroup2;
pub use self::curve2::{Curve2, CurvePartitioner2, CurveStation2};
pub use self::iso2::IsoExtensions2;
pub use self::line2::{Line2, LineOps2, intersect_lines, intersect_rays, intersection_param};
pub use self::segment2::Segment2;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Manifold1Pos2 {
pub l: f64,
pub point: Point2,
pub direction: UnitVec2,
pub normal: UnitVec2,
}
impl Manifold1Pos2 {
pub fn new(l: f64, point: Point2, direction: UnitVec2, normal: UnitVec2) -> Self {
Self {
l,
point,
direction,
normal,
}
}
pub fn surface_point(&self) -> SurfacePoint2 {
SurfacePoint2::new(self.point, self.normal)
}
pub fn direction_line(&self) -> Line2 {
Line2::new(self.point, self.direction.into_inner())
}
pub fn normal_scalar_projection(&self, other: &impl PCoords<2>) -> f64 {
self.normal.dot(&(other.coords() - self.point.coords))
}
pub fn direction_scalar_project(&self, other: &impl PCoords<2>) -> f64 {
self.direction.dot(&(other.coords() - self.point.coords))
}
}
impl PCoords<2> for Manifold1Pos2 {
fn coords(&self) -> SVector<f64, 2> {
self.point.coords
}
}
impl SPCoords<2> for Manifold1Pos2 {
fn normal(&self) -> UnitVec2 {
self.normal
}
}
impl ops::Mul<SurfacePoint2> for Iso2 {
type Output = SurfacePoint2;
fn mul(self, rhs: SurfacePoint2) -> Self::Output {
rhs.transformed_by(&self)
}
}
impl ops::Mul<SurfacePoint2> for &Iso2 {
type Output = SurfacePoint2;
fn mul(self, rhs: SurfacePoint2) -> Self::Output {
rhs.transformed_by(self)
}
}
impl ops::Mul<&SurfacePoint2> for &Iso2 {
type Output = SurfacePoint2;
fn mul(self, rhs: &SurfacePoint2) -> Self::Output {
rhs.transformed_by(self)
}
}
impl ops::Mul<&SurfacePoint2> for Iso2 {
type Output = SurfacePoint2;
fn mul(self, rhs: &SurfacePoint2) -> Self::Output {
rhs.transformed_by(&self)
}
}
impl SurfacePointCollection<2> for &[SurfacePoint2] {
fn clone_points(&self) -> Vec<Point2> {
self.iter().map(|sp| sp.point).collect()
}
fn clone_normals(&self) -> Vec<UnitVec2> {
self.iter().map(|sp| sp.normal).collect()
}
}
impl SurfacePointCollection<2> for &Vec<SurfacePoint2> {
fn clone_points(&self) -> Vec<Point2> {
self.iter().map(|sp| sp.point).collect()
}
fn clone_normals(&self) -> Vec<UnitVec2> {
self.iter().map(|sp| sp.normal).collect()
}
}
impl LineOps2 for SurfacePoint2 {
fn origin(&self) -> Point2 {
self.point
}
fn dir(&self) -> Vector2 {
self.normal.into_inner()
}
fn at(&self, t: f64) -> Point2 {
self.at_distance(t)
}
fn orthogonal(&self) -> Vector2 {
rot90(Cw) * self.normal.into_inner()
}
}
impl SurfacePoint2 {
pub fn shifted_orthogonal(&self, distance: f64) -> Self {
let shift = rot90(Cw) * self.normal.into_inner() * distance;
Self::new(self.point + shift, self.normal)
}
pub fn normal_rotated(&self, angle: f64) -> Self {
let n = Iso2::rotation(angle) * self.normal.into_inner();
Self::new_normalize(self.point, n)
}
pub fn normal_rotated_90(&self, dir: AngleDir) -> Self {
Self::new_normalize(self.point, rot90(dir) * self.normal.into_inner())
}
}
#[cfg(test)]
pub mod tests {
use super::*;
use approx::assert_relative_eq;
use std::f64::consts::PI;
#[test]
fn iso2_only_rotates_vector() {
let iso = Iso2::new(Vector2::new(1.0, 2.0), -PI / 2.0);
let v = Vector2::new(1.0, 1.0);
let vt = iso * v;
assert_relative_eq!(vt, Vector2::new(1.0, -1.0), epsilon = 1e-6);
}
}