use crate::geom::{self, Vector3};
use crate::math::{BaseFloat, Euler, Rad};
use daggy;
pub type Index = daggy::EdgeIndex<usize>;
pub type Indices = daggy::EdgeIndices<usize>;
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Edge<S = geom::scalar::Default> {
pub kind: Kind,
pub weight: S,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Kind {
pub axis: Axis,
pub relative: Relative,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Axis {
X,
Y,
Z,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Relative {
Position,
Orientation,
Scale,
}
impl Kind {
pub fn new(axis: Axis, relative: Relative) -> Self {
Kind { axis, relative }
}
pub fn x(relative: Relative) -> Self {
Kind::new(Axis::X, relative)
}
pub fn y(relative: Relative) -> Self {
Kind::new(Axis::Y, relative)
}
pub fn z(relative: Relative) -> Self {
Kind::new(Axis::Z, relative)
}
pub fn position(axis: Axis) -> Self {
let relative = Relative::Position;
Kind { axis, relative }
}
pub fn orientation(axis: Axis) -> Self {
let relative = Relative::Orientation;
Kind { axis, relative }
}
pub fn scale(axis: Axis) -> Self {
let relative = Relative::Scale;
Kind { axis, relative }
}
pub fn x_position() -> Self {
Kind::x(Relative::Position)
}
pub fn x_orientation() -> Self {
Kind::x(Relative::Orientation)
}
pub fn x_scale() -> Self {
Kind::x(Relative::Scale)
}
pub fn y_position() -> Self {
Kind::y(Relative::Position)
}
pub fn y_orientation() -> Self {
Kind::y(Relative::Orientation)
}
pub fn y_scale() -> Self {
Kind::y(Relative::Scale)
}
pub fn z_position() -> Self {
Kind::z(Relative::Position)
}
pub fn z_orientation() -> Self {
Kind::z(Relative::Orientation)
}
pub fn z_scale() -> Self {
Kind::z(Relative::Scale)
}
}
impl<S> Edge<S> {
pub fn new(kind: Kind, weight: S) -> Self {
Edge { kind, weight }
}
pub fn x(relative: Relative, weight: S) -> Self {
Edge::new(Kind::x(relative), weight)
}
pub fn y(relative: Relative, weight: S) -> Self {
Edge::new(Kind::y(relative), weight)
}
pub fn z(relative: Relative, weight: S) -> Self {
Edge::new(Kind::z(relative), weight)
}
pub fn position(axis: Axis, weight: S) -> Self {
Edge::new(Kind::position(axis), weight)
}
pub fn orientation(axis: Axis, weight: S) -> Self {
Edge::new(Kind::orientation(axis), weight)
}
pub fn scale(axis: Axis, weight: S) -> Self {
Edge::new(Kind::scale(axis), weight)
}
pub fn x_position(weight: S) -> Self {
Edge::new(Kind::x_position(), weight)
}
pub fn x_orientation(weight: S) -> Self {
Edge::new(Kind::x_orientation(), weight)
}
pub fn x_scale(weight: S) -> Self {
Edge::new(Kind::x_scale(), weight)
}
pub fn y_position(weight: S) -> Self {
Edge::new(Kind::y_position(), weight)
}
pub fn y_orientation(weight: S) -> Self {
Edge::new(Kind::y_orientation(), weight)
}
pub fn y_scale(weight: S) -> Self {
Edge::new(Kind::y_scale(), weight)
}
pub fn z_position(weight: S) -> Self {
Edge::new(Kind::z_position(), weight)
}
pub fn z_orientation(weight: S) -> Self {
Edge::new(Kind::z_orientation(), weight)
}
pub fn z_scale(weight: S) -> Self {
Edge::new(Kind::z_scale(), weight)
}
}
pub fn displace<S>(v: Vector3<S>) -> [Edge<S>; 3] {
[
Edge::x_position(v.x),
Edge::y_position(v.y),
Edge::z_position(v.z),
]
}
pub fn rotate<S: BaseFloat>(e: Euler<Rad<S>>) -> [Edge<S>; 3] {
[
Edge::x_orientation(e.x.0),
Edge::y_orientation(e.x.0),
Edge::z_orientation(e.z.0),
]
}
pub fn scale<S: Copy>(scale: S) -> [Edge<S>; 3] {
[
Edge::x_scale(scale),
Edge::y_scale(scale),
Edge::z_scale(scale),
]
}