-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ed8f21
commit f56fb45
Showing
19 changed files
with
984 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,84 @@ | ||
#[allow(unused_imports)] | ||
use libtrig::prelude::*; | ||
use libtrig::Vec2D; | ||
use libtrig::*; | ||
|
||
use crate::DualNum; | ||
|
||
pub struct Vec2DDual<T: Float> { | ||
/// Dual version of a 2D vector. | ||
pub struct Vec2DDual<T> { | ||
/// The x component of the vector. | ||
pub x: DualNum<T>, | ||
/// The y component of the vector. | ||
pub y: DualNum<T>, | ||
} | ||
|
||
impl Vec2DDual<Float64> { | ||
// pub const fn new(v: Vec2D, n: Int) -> Self { | ||
// Self { | ||
// x: DualNum::constant(v.x(), n as usize), | ||
// y: DualNum::constant(v.y(), n as usize), | ||
// } | ||
// } | ||
|
||
// operator fun plus(v: Vector2d) = Vector2dDual(x + v.x, y + v.y) | ||
// operator fun plus(v: Vector2dDual<Param>) = Vector2dDual(x + v.x, y + v.y) | ||
// operator fun minus(v: Vector2dDual<Param>) = Vector2dDual(x - v.x, y - v.y) | ||
// operator fun unaryMinus() = Vector2dDual(-x, -y) | ||
// | ||
// operator fun div(z: Double) = Vector2dDual(x / z, y / z) | ||
// | ||
// infix fun dot(v: Vector2dDual<Param>) = x * v.x + y * v.y | ||
// fun sqrNorm() = this dot this | ||
// fun norm() = sqrNorm().sqrt() | ||
// | ||
// fun bind() = Vector2dDual(x, y) | ||
// | ||
// fun <NewParam> reparam(oldParam: DualNum<NewParam>) = | ||
// Vector2dDual(x.reparam(oldParam), y.reparam(oldParam)) | ||
// | ||
// fun drop(n: Int) = Vector2dDual(x.drop(n), y.drop(n)) | ||
// fun value() = Vector2d(x.value(), y.value()) | ||
// | ||
// // precondition: this is normalized | ||
// fun angleCast() = Rotation2dDual(x, y) | ||
impl<T> Vec2DDual<T> { | ||
/// Construct a new Vec2DDual. | ||
#[inline] | ||
#[must_use = "This function creates a new Vec2DDual"] | ||
pub const fn new(x: DualNum<T>, y: DualNum<T>) -> Self { | ||
Self { x, y } | ||
} | ||
/// Construct a new Vec2DDual from a Vec2D. | ||
#[inline] | ||
#[must_use = "This function creates a new Vec2DDual"] | ||
pub fn constant(v: Vec2D, n: usize) -> Self { | ||
Self::new(DualNum::constant(v.x(), n), DualNum::constant(v.y(), n)) | ||
} | ||
} | ||
|
||
impl<T> core::ops::Add<Vec2D> for Vec2DDual<T> { | ||
type Output = Self; | ||
#[inline] | ||
#[must_use = "This function creates a new Vec2DDual"] | ||
fn add(self, rhs: Vec2D) -> Self::Output { | ||
Self::new(self.x + rhs.x(), self.y + rhs.y()) | ||
} | ||
} | ||
|
||
impl<T> core::ops::Add<Vec2DDual<T>> for Vec2DDual<T> { | ||
type Output = Self; | ||
#[inline] | ||
#[must_use = "This function creates a new Vec2DDual"] | ||
fn add(self, rhs: Vec2DDual<T>) -> Self::Output { | ||
Self::new(self.x + rhs.x, self.y + rhs.y) | ||
} | ||
} | ||
|
||
impl<T> core::ops::Sub<Vec2D> for Vec2DDual<T> { | ||
type Output = Self; | ||
#[inline] | ||
#[must_use = "This function creates a new Vec2DDual"] | ||
fn sub(self, rhs: Vec2D) -> Self::Output { | ||
Self::new(self.x - rhs.x(), self.y - rhs.y()) | ||
} | ||
} | ||
|
||
impl<T> core::ops::Sub<Vec2DDual<T>> for Vec2DDual<T> { | ||
type Output = Self; | ||
#[inline] | ||
#[must_use = "This function creates a new Vec2DDual"] | ||
fn sub(self, rhs: Vec2DDual<T>) -> Self::Output { | ||
Self::new(self.x - rhs.x, self.y - rhs.y) | ||
} | ||
} | ||
|
||
impl<T> core::ops::Neg for Vec2DDual<T> { | ||
type Output = Self; | ||
#[inline] | ||
#[must_use = "This function creates a new Vec2DDual"] | ||
fn neg(self) -> Self::Output { | ||
Self::new(-self.x, -self.y) | ||
} | ||
} | ||
|
||
impl<T> core::ops::Div<Float64> for Vec2DDual<T> { | ||
type Output = Self; | ||
#[inline] | ||
#[must_use = "This function creates a new Vec2DDual"] | ||
fn div(self, rhs: Float64) -> Self::Output { | ||
Self::new(self.x / rhs, self.y / rhs) | ||
} | ||
} | ||
|
||
// impl Dot for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.