#[repr(transparent)]
pub struct Point<T = i32, const N: usize = 2_usize>(_);
Expand description

A Point in N-dimensional space.

Please see the module-level documentation for examples.

Implementations

Constructs a Point from [T; N] coordinates.

Examples
let p = Point::new([1]);
assert_eq!(p.coords(), [1]);

let p = Point::new([1, 2]);
assert_eq!(p.coords(), [1, 2]);

let p = Point::new([1, -2, 1]);
assert_eq!(p.coords(), [1, -2, 1]);

Constructs a Point at the origin.

Example
let p: Point<i32> = Point::origin();
assert_eq!(p.coords(), [0, 0]);

Constructs a Point from an individual x coordinate.

Constructs a Point from individual x/y coordinates.

Constructs a Point from individual x/y/z coordinates.

Constructs a Point from a Vector.

Example
let v = vector!(1.0, 2.0);
let p = Point::from_vector(v);
assert_eq!(p.coords(), [1.0, 2.0]);

Returns Point coordinates as [T; N].

Example
let p = point!(2, 1, 3);
assert_eq!(p.coords(), [2, 1, 3]);

Returns Point coordinates as a mutable slice &mut [T; N].

Example
let mut p = point!(2, 1, 3);
for v in p.coords_mut() {
    *v *= 2;
}
assert_eq!(p.coords(), [4, 2, 6]);

Returns the x-coordinate.

Panics

If Point has zero dimensions.

Example
let p = point!(1, 2);
assert_eq!(p.x(), 1);

Sets the x-coordinate.

Panics

If Vector has zero dimensions.

Example
let mut p = point!(1, 2);
p.set_x(3);
assert_eq!(p.coords(), [3, 2]);

Returns the y-coordinate.

Panics

If Vector has less than 2 dimensions.

Example
let p = point!(1, 2);
assert_eq!(p.y(), 2);

Sets the y-coordinate.

Panics

If Vector has less than 2 dimensions.

Example
let mut p = point!(1, 2);
p.set_y(3);
assert_eq!(p.coords(), [1, 3]);

Returns the z-coordinate.

Panics

If Vector has less than 3 dimensions.

Example
let p = point!(1, 2, 2);
assert_eq!(p.z(), 2);

Sets the z-magnitude.

Panics

If Vector has less than 3 dimensions.

Example
let mut p = point!(1, 2, 1);
p.set_z(3);
assert_eq!(p.coords(), [1, 2, 3]);

Returns Point as a Vec.

Example
let p = point!(1, 1, 0);
assert_eq!(p.to_vec(), vec![1, 1, 0]);

Offsets a Point by shifting coordinates by given amount.

Examples
let mut p = point!(2, 3, 1);
p.offset([2, -4]);
assert_eq!(p.coords(), [4, -1, 1]);

Offsets the x-coordinate of the point by a given amount.

Panics

If Point has zero dimensions.

Offsets the y-coordinate of the point by a given amount.

Panics

If Vector has less than 2 dimensions.

Offsets the z-coordinate of the point by a given amount.

Panics

If Vector has less than 3 dimensions.

Constructs a Point by multiplying it by the given scale factor.

Examples
let mut p = point!(2, 3);
p.scale(2);
assert_eq!(p.coords(), [4, 6]);
Examples
let mut p = point!(200.0, 300.0);
p.wrap([150.0, 400.0], 10.0);
assert_eq!(p.coords(), [-10.0, 300.0]);

let mut p = point!(-100.0, 300.0);
p.wrap([150.0, 400.0], 10.0);
assert_eq!(p.coords(), [160.0, 300.0]);

Returns the Euclidean distance between two Points.

Example
let p1 = point!(1.0, 0.0, 0.0);
let p2 = point!(0.0, 1.0, 0.0);
let dist = p1.dist(p2);
let abs_difference: f64 = (dist - std::f64::consts::SQRT_2).abs();
assert!(abs_difference <= 1e-4);

Constructs a Point by linear interpolating between two Points by a given amount between 0.0 and 1.0.

Example
let p1 = point!(1.0, 1.0, 0.0);
let p2 = point!(3.0, 3.0, 0.0);
let p3 = p1.lerp(p2, 0.5);
assert_eq!(p3.coords(), [2.0, 2.0, 0.0]);

Returns whether two Points are approximately equal.

Example
let p1 = point!(10.0, 20.0);
let p2 = point!(10.0001, 20.0);
assert!(p1.approx_eq(p2, 1e-3));

Converts Point < T, N > to Point < U, N >.

Returns Point < T, N > with the nearest integers to the numbers. Round half-way cases away from 0.0.

Returns Point < T, N > with the largest integers less than or equal to the numbers.

Returns Point < T, N > with the smallest integers greater than or equal to the numbers.

Methods from Deref<Target = [T; N]>

Returns a slice containing the entire array. Equivalent to &s[..].

Returns a mutable slice containing the entire array. Equivalent to &mut s[..].

🔬 This is a nightly-only experimental API. (array_methods)

Borrows each element and returns an array of references with the same size as self.

Example
#![feature(array_methods)]

let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);

This method is particularly useful if combined with other methods, like map. This way, you can avoid moving the original array if its elements are not Copy.

#![feature(array_methods)]

let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);

// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
🔬 This is a nightly-only experimental API. (array_methods)

Borrows each element mutably and returns an array of mutable references with the same size as self.

Example
#![feature(array_methods)]

let mut floats = [3.1, 2.7, -1.0];
let float_refs: [&mut f64; 3] = floats.each_mut();
*float_refs[0] = 0.0;
assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);
assert_eq!(floats, [0.0, 2.7, -1.0]);
🔬 This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.split_array_ref::<0>();
   assert_eq!(left, &[]);
   assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<2>();
    assert_eq!(left, &[1, 2]);
    assert_eq!(right, &[3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<6>();
    assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
    assert_eq!(right, &[]);
}
🔬 This is a nightly-only experimental API. (split_array)

Divides one mutable array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.split_array_mut::<2>();
assert_eq!(left, &mut [1, 0][..]);
assert_eq!(right, &mut [3, 0, 5, 6]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);
🔬 This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.rsplit_array_ref::<0>();
   assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
   assert_eq!(right, &[]);
}

{
    let (left, right) = v.rsplit_array_ref::<2>();
    assert_eq!(left, &[1, 2, 3, 4]);
    assert_eq!(right, &[5, 6]);
}

{
    let (left, right) = v.rsplit_array_ref::<6>();
    assert_eq!(left, &[]);
    assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
🔬 This is a nightly-only experimental API. (split_array)

Divides one mutable array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.rsplit_array_mut::<4>();
assert_eq!(left, &mut [1, 0]);
assert_eq!(right, &mut [3, 0, 5, 6][..]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns whether this ellipse contains a given Point.

Returns whether this rectangle contains a given Point.

Returns whether this sphere contains a given Point.

Returns whether this rectangle contains a given Point.

Formats the value using the given formatter. Read more

Return default Point as origin.

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Display Point as a string of coordinates.

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Draw point to the current PixState canvas.

Converts &[T; M] to Point < T, N >.

Converts Point < T, N > to &[T; M].

Converts to this type from the input type.

Converts to this type from the input type.

Converts [T; M] to Point < T, N >.

Converts Point < T, N > to [T; M].

Converts to this type from the input type.

Converts to this type from the input type.

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

Feeds this value into the given Hasher. Read more

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

The returned type after indexing.

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

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

T * Point.

The resulting type after applying the * operator.

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.