# Struct euclid::point::Point2D[−][src]

``````#[repr(C)]pub struct Point2D<T, U> {
pub x: T,
pub y: T,
// some fields omitted
}``````
Expand description

A 2d Point tagged with a unit.

## Fields

`x: T``y: T`

## Implementations

Constructor, setting all components to zero.

Constructor taking scalar values directly.

Constructor taking properly Lengths instead of scalar values.

Tag a unitless value with units.

Create a 3d point from this one, using the specified z value.

Cast this point into a vector.

Equivalent to subtracting the origin from this point.

Swap x and y.

##### Example
``````enum Mm {}

let point: Point2D<_, Mm> = point2(1, -8);

assert_eq!(point.yx(), point2(-8, 1));``````

Drop the units, preserving only the numeric value.

##### Example
``````enum Mm {}

let point: Point2D<_, Mm> = point2(1, -8);

assert_eq!(point.x, point.to_untyped().x);
assert_eq!(point.y, point.to_untyped().y);``````

Cast the unit, preserving the numeric value.

##### Example
``````enum Mm {}
enum Cm {}

let point: Point2D<_, Mm> = point2(1, -8);

assert_eq!(point.x, point.cast_unit::<Cm>().x);
assert_eq!(point.y, point.cast_unit::<Cm>().y);``````

Cast into an array with x and y.

##### Example
``````enum Mm {}

let point: Point2D<_, Mm> = point2(1, -8);

assert_eq!(point.to_array(), [1, -8]);``````

Cast into a tuple with x and y.

##### Example
``````enum Mm {}

let point: Point2D<_, Mm> = point2(1, -8);

assert_eq!(point.to_tuple(), (1, -8));``````

Convert into a 3d point with z-coordinate equals to zero.

Rounds each component to the nearest integer value.

This behavior is preserved for negative values (unlike the basic cast).

``````enum Mm {}

assert_eq!(point2::<_, Mm>(-0.1, -0.8).round(), point2::<_, Mm>(0.0, -1.0))``````

Rounds each component to the smallest integer equal or greater than the original value.

This behavior is preserved for negative values (unlike the basic cast).

``````enum Mm {}

assert_eq!(point2::<_, Mm>(-0.1, -0.8).ceil(), point2::<_, Mm>(0.0, 0.0))``````

Rounds each component to the biggest integer equal or lower than the original value.

This behavior is preserved for negative values (unlike the basic cast).

``````enum Mm {}

assert_eq!(point2::<_, Mm>(-0.1, -0.8).floor(), point2::<_, Mm>(-1.0, -1.0))``````

Linearly interpolate between this point and another point.

##### Example
``````use euclid::point2;
use euclid::default::Point2D;

let from: Point2D<_> = point2(0.0, 10.0);
let to:  Point2D<_> = point2(8.0, -4.0);

assert_eq!(from.lerp(to, -1.0), point2(-8.0,  24.0));
assert_eq!(from.lerp(to,  0.0), point2( 0.0,  10.0));
assert_eq!(from.lerp(to,  0.5), point2( 4.0,   3.0));
assert_eq!(from.lerp(to,  1.0), point2( 8.0,  -4.0));
assert_eq!(from.lerp(to,  2.0), point2(16.0, -18.0));``````

Returns the point each component of which clamped by corresponding components of `start` and `end`.

Shortcut for `self.max(start).min(end)`.

Cast from one numeric representation to another, preserving the units.

When casting from floating point to integer coordinates, the decimals are truncated as one would expect from a simple cast, but this behavior does not always make sense geometrically. Consider using `round()`, `ceil()` or `floor()` before casting.

Fallible cast from one numeric representation to another, preserving the units.

When casting from floating point to integer coordinates, the decimals are truncated as one would expect from a simple cast, but this behavior does not always make sense geometrically. Consider using `round()`, `ceil()` or `floor()` before casting.

Cast into an `f32` point.

Cast into an `f64` point.

Cast into an `usize` point, truncating decimals if any.

When casting from floating point points, it is worth considering whether to `round()`, `ceil()` or `floor()` before the cast in order to obtain the desired conversion behavior.

Cast into an `u32` point, truncating decimals if any.

When casting from floating point points, it is worth considering whether to `round()`, `ceil()` or `floor()` before the cast in order to obtain the desired conversion behavior.

Cast into an i32 point, truncating decimals if any.

When casting from floating point points, it is worth considering whether to `round()`, `ceil()` or `floor()` before the cast in order to obtain the desired conversion behavior.

Cast into an i64 point, truncating decimals if any.

When casting from floating point points, it is worth considering whether to `round()`, `ceil()` or `floor()` before the cast in order to obtain the desired conversion behavior.

## 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

Performs the `+=` operation. Read more

Performs the `+=` operation. Read more

Default epsilon value

Returns `true` is this object is approximately equal to the other one, using a provided epsilon value. Read more

Returns `true` is this object is approximately equal to the other one, using the `approx_epsilon()` epsilon value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from `source`. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. 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 conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given `Hasher`. Read more

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

Performs the conversion.

Performs the conversion.

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

The resulting type after applying the `-` operator.

Performs the unary `-` operation. Read more

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

This method tests for `!=`.

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

Performs the `-=` operation. Read more

Performs the `-=` operation. Read more

## 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`)

Converts the given value to a `String`. Read more