pub struct Point {
pub x: isize,
pub y: isize,
}Expand description
Fields§
§x: isizex 座標です。
y: isizey 座標です。
Implementations§
Source§impl Point
impl Point
Sourcepub const fn dot(self, other: Self) -> isize
pub const fn dot(self, other: Self) -> isize
2つのベクトルの内積を返します。
self.x * other.x + self.y * other.y です。両方が零ベクトルでない場合、
正ならなす角は鋭角、0 なら直角、負なら鈍角または反対向きです。
点を引き算して作った方向ベクトルの角度判定に使えます。計算量は O(1) です。
Sourcepub const fn cross(self, other: Self) -> isize
pub const fn cross(self, other: Self) -> isize
2つのベクトルの外積を返します。
self.x * other.y - self.y * other.x です。正なら other は self の
反時計回り側、負なら時計回り側です。0 は平行で、逆向きや零ベクトルも含みます。
絶対値は2つのベクトルが作る平行四辺形の面積です。計算量は O(1) です。
Sourcepub const fn is_parallel(self, other: Self) -> bool
pub const fn is_parallel(self, other: Self) -> bool
2つのベクトルが平行なら true を返します。
外積が 0 かを判定します。逆向きも平行とし、零ベクトルを含む場合も true です。
Sourcepub const fn is_orthogonal(self, other: Self) -> bool
pub const fn is_orthogonal(self, other: Self) -> bool
2つのベクトルが直交するなら true を返します。
内積が 0 かを判定します。零ベクトルを含む場合も true です。
Sourcepub const fn norm_squared(self) -> isize
pub const fn norm_squared(self) -> isize
原点からの距離の二乗を返します。
x * x + y * y です。平方根を取らずに距離の大小を比較できます。
Sourcepub const fn norm2(self) -> isize
pub const fn norm2(self) -> isize
原点からの距離の二乗を返します。
norm_squared と同じです。
Sourcepub fn distance_squared(self, other: Self) -> isize
pub fn distance_squared(self, other: Self) -> isize
other までの距離の二乗を返します。
(self.x - other.x)^2 + (self.y - other.y)^2 です。実際の距離ではなく
その二乗を返すため、距離の比較にも閾値の二乗を使います。計算量は O(1) です。
Sourcepub fn dist2(self, other: Self) -> isize
pub fn dist2(self, other: Self) -> isize
other までの距離の二乗を返します。
distance_squared と同じです。
Trait Implementations§
impl Copy for Point
impl Eq for Point
impl StructuralPartialEq for Point
Auto Trait Implementations§
impl Freeze for Point
impl RefUnwindSafe for Point
impl Send for Point
impl Sync for Point
impl Unpin for Point
impl UnsafeUnpin for Point
impl UnwindSafe for Point
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more