#[repr(transparent)]
pub struct Point<T, const N: 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.as_array(), [1]);

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

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

Constructs a Point at the origin.

Example
let p: PointI2 = Point::origin();
assert_eq!(p.as_array(), [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.as_array(), [1.0, 2.0]);

Returns Point coordinates as [T; N].

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

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

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

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

Example
let mut p = point!(2, 1, 3);
for v in p.as_bytes_mut() {
    *v *= 2;
}
assert_eq!(p.as_bytes(), &[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.as_array(), [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.as_array(), [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.as_array(), [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.as_array(), [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.as_array(), [4, 6]);
Examples
let mut p = point!(200.0, 300.0);
p.wrap([150.0, 400.0], 10.0);
assert_eq!(p.as_array(), [-10.0, 300.0]);

let mut p = point!(-100.0, 300.0);
p.wrap([150.0, 400.0], 10.0);
assert_eq!(p.as_array(), [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.as_array(), [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.

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

Performs the conversion.

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

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

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

Performs the conversion.

Performs the conversion.

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

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

Performs the conversion.

Performs the conversion.

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

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

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.