mirror of
https://github.com/lisk77/comet.git
synced 2025-10-24 13:58:49 +00:00
feat: added a Bezier struct for a general bezier curve implementation
This commit is contained in:
parent
30afffdf32
commit
d0e9a1b456
3 changed files with 130 additions and 145 deletions
|
|
@ -2,7 +2,16 @@ use crate::point::{Point2, Point3};
|
|||
use crate::quaternion::Quat;
|
||||
use std::ops::*;
|
||||
|
||||
pub trait InnerSpace {
|
||||
pub trait InnerSpace:
|
||||
std::fmt::Debug +
|
||||
Copy +
|
||||
Clone +
|
||||
Neg<Output = Self> +
|
||||
Mul<f32, Output = Self> +
|
||||
Div<f32, Output = Self> +
|
||||
Add<Self, Output = Self> +
|
||||
Sub<Self, Output = Self>
|
||||
{
|
||||
fn dot(&self, other: &Self) -> f32;
|
||||
fn dist(&self, other: &Self) -> f32;
|
||||
fn angle(&self, other: &Self) -> f32;
|
||||
|
|
@ -93,6 +102,17 @@ impl SubAssign for Vec2 {
|
|||
}
|
||||
}
|
||||
|
||||
impl Neg for Vec2 {
|
||||
type Output = Self;
|
||||
|
||||
fn neg(self) -> Self::Output {
|
||||
Self {
|
||||
x: -self.x,
|
||||
y: -self.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<f32> for Vec2 {
|
||||
type Output = Vec2;
|
||||
|
||||
|
|
@ -505,6 +525,17 @@ impl Into<[f32;3]> for Vec3 {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Vec3> for [f32;3] {
|
||||
fn into(self) -> Vec3 {
|
||||
Vec3 {
|
||||
x: self[0],
|
||||
y: self[1],
|
||||
z: self[2],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
|
@ -793,6 +824,19 @@ impl SubAssign for Vec4 {
|
|||
}
|
||||
}
|
||||
|
||||
impl Neg for Vec4 {
|
||||
type Output = Self;
|
||||
|
||||
fn neg(self) -> Self::Output {
|
||||
Self {
|
||||
x: -self.x,
|
||||
y: -self.y,
|
||||
z: -self.z,
|
||||
w: -self.w,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<f32> for Vec4 {
|
||||
type Output = Vec4;
|
||||
|
||||
|
|
@ -828,6 +872,19 @@ impl MulAssign<f32> for Vec4 {
|
|||
}
|
||||
}
|
||||
|
||||
impl Div<f32> for Vec4 {
|
||||
type Output = Vec4;
|
||||
|
||||
fn div(self, other: f32) -> Vec4 {
|
||||
Vec4 {
|
||||
x: self.x / other,
|
||||
y: self.y / other,
|
||||
z: self.z / other,
|
||||
w: self.w / other,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<[f32;4]> for Vec4 {
|
||||
fn into(self) -> [f32;4] {
|
||||
[self.x, self.y, self.z, self.w]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue