use curves::*;
use std::f32;
use std::ops::{Mul, Add, Sub};
#[derive(Clone, Copy, PartialEq, Debug)]
pub struct PathPoint {
pub position: (f32, f32)
}
impl PathPoint {
pub fn new(x: f32, y: f32) -> PathPoint {
PathPoint {
position: (x, y)
}
}
pub fn x(&self) -> f32 {
self.position.0
}
pub fn y(&self) -> f32 {
self.position.1
}
}
impl Add<PathPoint> for PathPoint {
type Output=PathPoint;
#[inline]
fn add(self, rhs: PathPoint) -> PathPoint {
PathPoint {
position: (self.position.0 + rhs.position.0, self.position.1 + rhs.position.1)
}
}
}
impl Sub<PathPoint> for PathPoint {
type Output=PathPoint;
#[inline]
fn sub(self, rhs: PathPoint) -> PathPoint {
PathPoint {
position: (self.position.0 - rhs.position.0, self.position.1 - rhs.position.1)
}
}
}
impl Mul<f64> for PathPoint {
type Output=PathPoint;
#[inline]
fn mul(self, rhs: f64) -> PathPoint {
let rhs = rhs as f32;
PathPoint {
position: (self.position.0 * rhs, self.position.1 * rhs)
}
}
}
impl Coordinate for PathPoint {
#[inline]
fn from_components(components: &[f64]) -> Self {
PathPoint {
position: (components[0] as f32, components[1] as f32)
}
}
#[inline]
fn origin() -> Self {
PathPoint {
position: (0.0,0.0)
}
}
fn len() -> usize {
2
}
#[inline]
fn get(&self, index: usize) -> f64 {
match index {
0 => self.position.0 as f64,
1 => self.position.1 as f64,
_ => 0.0
}
}
#[inline]
fn from_biggest_components(p1: Self, p2: Self) -> Self {
PathPoint {
position: (
f32::max(p1.position.0, p2.position.0),
f32::max(p1.position.1, p2.position.1)
)
}
}
#[inline]
fn from_smallest_components(p1: Self, p2: Self) -> Self {
PathPoint {
position: (
f32::min(p1.position.0, p2.position.0),
f32::min(p1.position.1, p2.position.1)
)
}
}
}