rust_sc2::geometry

Struct Point2

Source
pub struct Point2 {
    pub x: f32,
    pub y: f32,
}
Expand description

Point on 2D grid, the most frequently used geometric primitive.

Fields§

§x: f32§y: f32

Implementations§

Source§

impl Point2

Source

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

Constructs new 2D Point with given coordinates.

Source

pub fn towards(self, other: Self, offset: f32) -> Self

Returns new point with offset towards other on given distance.

Source

pub fn towards_angle(self, angle: f32, offset: f32) -> Self

Returns new point with offset towards given angle on given distance.

Source

pub fn offset(self, x: f32, y: f32) -> Self

Returns new point with given offset.

Source

pub fn circle_intersection(self, other: Self, radius: f32) -> Option<[Self; 2]>

Returns points where circles with centers self and other, and given radius intersect, or None if they aren’t intersect.

Source

pub fn len_squared(self) -> f32

Returns squared length of the vector.

Source

pub fn len(self) -> f32

Returns length of the vector.

Source

pub fn normalize(self) -> Self

Normalizes the vector.

Source

pub fn rotate(self, angle: f32) -> Self

Rotates the vector on given angle.

Source

pub fn rotate90(self, clockwise: bool) -> Self

Fast rotation of the vector on 90 degrees.

Source

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

Dot product.

Source

pub fn round(self) -> Self

Returns rounded point.

Source

pub fn floor(self) -> Self

Returns point rounded to closest lower integer.

Source

pub fn ceil(self) -> Self

Returns point rounded to closest greater integer.

Source

pub fn abs(self) -> Self

Returns point with absolute coordinates.

Source

pub fn neighbors4(self) -> [Self; 4]

Returns 4 closest neighbors of point.

Source

pub fn neighbors4diagonal(self) -> [Self; 4]

Returns 4 closest diagonal neighbors of point.

Source

pub fn neighbors8(self) -> [Self; 8]

Returns 8 closest neighbors of point.

Source

pub fn as_tuple(self) -> (f32, f32)

Returns tuple with point’s coordinates.

Source

pub fn to3(self, z: f32) -> Point3

Converts 2D Point to 3D Point using given z value.

Trait Implementations§

Source§

impl Add<f32> for Point2

Source§

type Output = Point2

The resulting type after applying the + operator.
Source§

fn add(self, other: f32) -> Self

Performs the + operation. Read more
Source§

impl Add for Point2

Source§

type Output = Point2

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl AddAssign<f32> for Point2

Source§

fn add_assign(&mut self, other: f32)

Performs the += operation. Read more
Source§

impl AddAssign for Point2

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl Clone for Point2

Source§

fn clone(&self) -> Point2

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Point2

Source§

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

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

impl Default for Point2

Source§

fn default() -> Point2

Returns the “default value” for a type. Read more
Source§

impl Div<f32> for Point2

Source§

type Output = Point2

The resulting type after applying the / operator.
Source§

fn div(self, other: f32) -> Self

Performs the / operation. Read more
Source§

impl Div for Point2

Source§

type Output = Point2

The resulting type after applying the / operator.
Source§

fn div(self, other: Self) -> Self

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Point2

Source§

fn div_assign(&mut self, other: f32)

Performs the /= operation. Read more
Source§

impl DivAssign for Point2

Source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
Source§

impl From<&Point2> for Point2

Source§

fn from(p: &Point2) -> Self

Converts to this type from the input type.
Source§

impl From<&Unit> for Point2

Source§

fn from(u: &Unit) -> Self

Converts to this type from the input type.
Source§

impl From<(f32, f32)> for Point2

Source§

fn from((x, y): (f32, f32)) -> Self

Converts to this type from the input type.
Source§

impl From<(usize, usize)> for Point2

Source§

fn from((x, y): (usize, usize)) -> Self

Converts to this type from the input type.
Source§

impl From<Point2> for (f32, f32)

Source§

fn from(p: Point2) -> Self

Converts to this type from the input type.
Source§

impl From<Point2> for (usize, usize)

Source§

fn from(p: Point2) -> Self

Converts to this type from the input type.
Source§

impl From<Point3> for Point2

Source§

fn from(p3: Point3) -> Self

Converts to this type from the input type.
Source§

impl From<Unit> for Point2

Source§

fn from(u: Unit) -> Self

Converts to this type from the input type.
Source§

impl Hash for Point2

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<T> Index<Point2> for Array2<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, pos: Point2) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<Point2> for Array2<T>

Source§

fn index_mut(&mut self, pos: Point2) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Mul<f32> for Point2

Source§

type Output = Point2

The resulting type after applying the * operator.
Source§

fn mul(self, other: f32) -> Self

Performs the * operation. Read more
Source§

impl Mul for Point2

Source§

type Output = Point2

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Point2

Source§

fn mul_assign(&mut self, other: f32)

Performs the *= operation. Read more
Source§

impl MulAssign for Point2

Source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
Source§

impl Neg for Point2

Source§

type Output = Point2

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Point2

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Radius for &Point2

Source§

fn radius(&self) -> f32

Radius for struct
Source§

impl Radius for Point2

Source§

fn radius(&self) -> f32

Radius for struct
Source§

impl Sub<f32> for Point2

Source§

type Output = Point2

The resulting type after applying the - operator.
Source§

fn sub(self, other: f32) -> Self

Performs the - operation. Read more
Source§

impl Sub for Point2

Source§

type Output = Point2

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl SubAssign<f32> for Point2

Source§

fn sub_assign(&mut self, other: f32)

Performs the -= operation. Read more
Source§

impl SubAssign for Point2

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl Sum for Point2

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Copy for Point2

Source§

impl Eq for Point2

Auto Trait Implementations§

§

impl Freeze for Point2

§

impl RefUnwindSafe for Point2

§

impl Send for Point2

§

impl Sync for Point2

§

impl Unpin for Point2

§

impl UnwindSafe for Point2

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, dst: *mut u8)

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

impl<T> Distance for T
where T: Into<Point2>,

Source§

fn distance_squared<P: Into<Point2>>(self, other: P) -> f32

Calculates squared euclidean distance from self to other.
Source§

fn distance<P: Into<Point2>>(self, other: P) -> f32

Calculates euclidean distance from self to other.
Source§

fn is_closer<P: Into<Point2>>(self, distance: f32, other: P) -> bool

Checks if distance between self and other is less than given distance.
Source§

fn is_further<P: Into<Point2>>(self, distance: f32, other: P) -> bool

Checks if distance between self and other is greater than given distance.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V