use crate::math::{Pose, Vector};
use crate::shape::SupportMap;
use core::ops::Sub;
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct CsoPoint {
pub point: Vector,
pub orig1: Vector,
pub orig2: Vector,
}
impl CsoPoint {
pub const ZERO: Self = Self {
point: Vector::ZERO,
orig1: Vector::ZERO,
orig2: Vector::ZERO,
};
pub fn new(orig1: Vector, orig2: Vector) -> Self {
let point = orig1 - orig2;
Self::new_with_point(point, orig1, orig2)
}
pub fn new_with_point(point: Vector, orig1: Vector, orig2: Vector) -> Self {
CsoPoint {
point,
orig1,
orig2,
}
}
pub fn single_point(point: Vector) -> Self {
Self::new_with_point(point, point, Vector::ZERO)
}
pub fn origin() -> Self {
CsoPoint::new(Vector::ZERO, Vector::ZERO)
}
pub fn from_shapes_toward<G1, G2>(pos12: &Pose, g1: &G1, g2: &G2, dir: Vector) -> Self
where
G1: ?Sized + SupportMap,
G2: ?Sized + SupportMap,
{
let sp1 = g1.local_support_point_toward(dir);
let sp2 = g2.support_point_toward(pos12, -dir);
CsoPoint::new(sp1, sp2)
}
pub fn from_shapes<G1, G2>(pos12: &Pose, g1: &G1, g2: &G2, dir: Vector) -> Self
where
G1: ?Sized + SupportMap,
G2: ?Sized + SupportMap,
{
let sp1 = g1.local_support_point(dir);
let sp2 = g2.support_point(pos12, -dir);
CsoPoint::new(sp1, sp2)
}
pub fn translate(&self, dir: Vector) -> Self {
CsoPoint::new_with_point(self.point + dir, self.orig1, self.orig2)
}
pub fn translate_mut(&mut self, dir: Vector) {
self.point += dir;
}
}
impl Sub<CsoPoint> for CsoPoint {
type Output = Vector;
#[inline]
fn sub(self, rhs: CsoPoint) -> Vector {
self.point - rhs.point
}
}