Skip to main content

Point

Struct Point 

Source
pub struct Point {
    pub x: isize,
    pub y: isize,
}
Expand description

整数座標上の点またはベクトルです。

演算結果が isize の範囲を超えないことは呼び出し側で保証してください。

§Examples

use atcoder::geometry::Point;

let a = Point::new(1, 2);
let b = Point::new(4, 6);
assert_eq!(a.distance_squared(b), 25);

Fields§

§x: isize

x 座標です。

§y: isize

y 座標です。

Implementations§

Source§

impl Point

Source

pub const fn new(x: isize, y: isize) -> Self

座標 (x, y) の点を作ります。

Source

pub const fn dot(self, other: Self) -> isize

2つのベクトルの内積を返します。

self.x * other.x + self.y * other.y です。両方が零ベクトルでない場合、 正ならなす角は鋭角、0 なら直角、負なら鈍角または反対向きです。 点を引き算して作った方向ベクトルの角度判定に使えます。計算量は O(1) です。

Source

pub const fn cross(self, other: Self) -> isize

2つのベクトルの外積を返します。

self.x * other.y - self.y * other.x です。正なら other は self の 反時計回り側、負なら時計回り側です。0 は平行で、逆向きや零ベクトルも含みます。 絶対値は2つのベクトルが作る平行四辺形の面積です。計算量は O(1) です。

Source

pub const fn is_parallel(self, other: Self) -> bool

2つのベクトルが平行なら true を返します。

外積が 0 かを判定します。逆向きも平行とし、零ベクトルを含む場合も true です。

Source

pub const fn is_orthogonal(self, other: Self) -> bool

2つのベクトルが直交するなら true を返します。

内積が 0 かを判定します。零ベクトルを含む場合も true です。

Source

pub const fn norm_squared(self) -> isize

原点からの距離の二乗を返します。

x * x + y * y です。平方根を取らずに距離の大小を比較できます。

Source

pub const fn norm2(self) -> isize

原点からの距離の二乗を返します。

norm_squared と同じです。

Source

pub fn distance_squared(self, other: Self) -> isize

other までの距離の二乗を返します。

(self.x - other.x)^2 + (self.y - other.y)^2 です。実際の距離ではなく その二乗を返すため、距離の比較にも閾値の二乗を使います。計算量は O(1) です。

Source

pub fn dist2(self, other: Self) -> isize

other までの距離の二乗を返します。

distance_squared と同じです。

Trait Implementations§

Source§

impl Add for Point

Source§

type Output = Point

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Point

Source§

fn clone(&self) -> Point

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Point

Source§

impl Debug for Point

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Point

Source§

impl Hash for Point

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul<isize> for Point

Source§

type Output = Point

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: isize) -> Self::Output

Performs the * operation. Read more
Source§

impl PartialEq for Point

Source§

fn eq(&self, other: &Point) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Point

Source§

impl Sub for Point

Source§

type Output = Point

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.