Skip to main content

Point

Struct Point 

#[repr(C)]
pub struct Point { pub x: f32, pub y: f32, }

Fields§

§x: f32§y: f32

Implementations§

§

impl Point

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

Sets x and y. Used both to set a point and a vector.

  • x float x-axis value
  • y float y-axis value

pub fn is_zero(self) -> bool

Returns true if x and y are both zero.

pub fn set(&mut self, x: f32, y: f32)

Sets x and y.

  • x new value for x
  • y new value for y

pub fn iset(&mut self, p: impl Into<IPoint>)

Sets x and y, promoting integers to float values.

Assigning a large integer value directly to x or y may cause a compiler error, triggered by narrowing conversion of int to float. This safely casts p to avoid the error.

  • p integer point members promoted to float

pub fn set_abs(&mut self, p: impl Into<Point>)

Sets x to the absolute value of p.x, and y to the absolute value of p.y.

  • p members providing magnitude for x and y

pub fn offset_points(points: &mut [Point], offset: impl Into<Point>)

Adds offset to each point in points.

  • points point array
  • offset vector added to points

pub fn offset(&mut self, d: impl Into<Point>)

Adds d to the point.

  • d vector to add

pub fn length(self) -> f32

Returns the Euclidean distance from origin, computed as sqrt(x * x + y * y).

pub fn distance_to_origin(self) -> f32

Returns the Euclidean distance from origin, computed as sqrt(x * x + y * y).

pub fn normalize(&mut self) -> bool

Scales so that Self::length() returns one, while preserving the ratio of x to y, if possible. If the prior length is nearly zero, sets the vector to (0, 0) and returns false; otherwise returns true.

Example (C++): https://fiddle.skia.org/c/@Point_normalize_2

pub fn set_normalize(&mut self, x: f32, y: f32) -> bool

Sets the vector to (x, y) scaled so that Self::length() returns one, and so that the vector is proportional to (x, y). If the (x, y) length is nearly zero, sets the vector to (0, 0) and returns false; otherwise returns true.

  • x proportional value for x
  • y proportional value for y

Example (C++): https://fiddle.skia.org/c/@Point_setNormalize

pub fn set_length(&mut self, length: f32) -> bool

Scales the vector so that Self::distance_to_origin() returns length, if possible. If the former length is nearly zero, sets the vector to (0, 0) and returns false; otherwise returns true.

  • length straight-line distance to origin

Example (C++): https://fiddle.skia.org/c/@Point_setLength

pub fn set_length_xy(&mut self, x: f32, y: f32, length: f32) -> bool

Sets the vector to (x, y) scaled to length, if possible. If the former length is nearly zero, sets the vector to (0, 0) and returns false; otherwise returns true.

  • x proportional value for x
  • y proportional value for y
  • length straight-line distance to origin

Example (C++): https://fiddle.skia.org/c/@Point_setLength_2

pub fn scaled(self, scale: f32) -> Point

Returns the point times scale.

  • scale factor to multiply the point by

Example (C++): https://fiddle.skia.org/c/@Point_scale

pub fn scale(&mut self, scale: f32)

Scales the point in place by scale.

  • scale factor to multiply the point by

pub fn negate(&mut self)

Changes the sign of x and y.

pub fn is_finite(self) -> bool

Returns true if both x and y are measurable values.

pub fn equals(self, x: f32, y: f32) -> bool

Returns true if the point is equivalent to (x, y).

  • x value compared with x
  • y value compared with y

pub fn length_xy(x: f32, y: f32) -> f32

Returns the Euclidean distance from origin, computed as sqrt(x * x + y * y).

  • x component of length
  • y component of length

Example (C++): https://fiddle.skia.org/c/@Point_Length

pub fn normalize_vector(v: &mut Point) -> f32

Scales v so that Self::length() returns one, while preserving the ratio of v.x to v.y, if possible. If the original length is nearly zero, sets v to (0, 0) and returns zero; otherwise, returns the length of v before it is scaled.

The returned prior length may be INFINITY if it cannot be represented by a float.

Note that Self::normalize() is faster if the prior length is not required.

  • v normalized to unit length

Example (C++): https://fiddle.skia.org/c/@Point_Normalize

pub fn distance(a: Point, b: Point) -> f32

Returns the Euclidean distance between a and b.

  • a line end point
  • b line end point

pub fn dot_product(a: Point, b: Point) -> f32

Returns the dot product of a and b.

  • a left side of dot product
  • b right side of dot product

pub fn cross_product(a: Point, b: Point) -> f32

Returns the cross product of a and b.

a and b form three-dimensional vectors with z-axis value equal to zero. The cross product is a three-dimensional vector with x-axis and y-axis values equal to zero. The cross product z-axis component is returned.

  • a left side of cross product
  • b right side of cross product

pub fn cross(self, vec: Point) -> f32

Returns the cross product of the point and vec.

The point and vec form three-dimensional vectors with z-axis value equal to zero. The cross product is a three-dimensional vector with x-axis and y-axis values equal to zero. The cross product z-axis component is returned.

  • vec right side of cross product

pub fn dot(self, vec: Point) -> f32

Returns the dot product of the point and vec.

  • vec right side of dot product

Trait Implementations§

§

impl Add for Point

§

type Output = Point

The resulting type after applying the + operator.
§

fn add(self, rhs: Point) -> Point

Performs the + operation. Read more
§

impl Add<Size> for Point

§

type Output = Point

The resulting type after applying the + operator.
§

fn add(self, rhs: Size) -> Point

Performs the + operation. Read more
§

impl AddAssign for Point

§

fn add_assign(&mut self, rhs: Point)

Performs the += operation. Read more
§

impl AddAssign<Size> for Point

§

fn add_assign(&mut self, rhs: Size)

Performs the += operation. Read more
§

impl Clone for Point

§

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
§

impl Contains<&Point> for Rect

§

fn contains(&self, p: &Point) -> bool

§

impl Contains<Point> for Rect

§

fn contains(&self, p: Point) -> bool

§

impl Copy for Point

§

impl Debug for Point

§

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

Formats the value using the given formatter. Read more
§

impl Default for Point

§

fn default() -> Point

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

impl Div<f32> for Point

§

type Output = Point

The resulting type after applying the / operator.
§

fn div(self, rhs: f32) -> Point

Performs the / operation. Read more
§

impl DivAssign<f32> for Point

§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
§

impl From<(f32, f32)> for Point

§

fn from(source: (f32, f32)) -> Point

Converts to this type from the input type.
§

impl From<(i32, i32)> for Point

§

fn from(source: (i32, i32)) -> Point

Converts to this type from the input type.
§

impl From<IPoint> for Point

§

fn from(source: IPoint) -> Point

Converts to this type from the input type.
§

impl Mul<f32> for Point

§

type Output = Point

The resulting type after applying the * operator.
§

fn mul(self, rhs: f32) -> Point

Performs the * operation. Read more
§

impl MulAssign<f32> for Point

§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
§

impl Neg for Point

§

type Output = Point

The resulting type after applying the - operator.
§

fn neg(self) -> <Point as Neg>::Output

Performs the unary - operation. Read more
§

impl PartialEq for Point

§

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
§

impl StructuralPartialEq for Point

§

impl Sub for Point

§

type Output = Point

The resulting type after applying the - operator.
§

fn sub(self, rhs: Point) -> Point

Performs the - operation. Read more
§

impl Sub<Size> for Point

§

type Output = Point

The resulting type after applying the - operator.
§

fn sub(self, rhs: Size) -> Point

Performs the - operation. Read more
§

impl SubAssign for Point

§

fn sub_assign(&mut self, rhs: Point)

Performs the -= operation. Read more
§

impl SubAssign<Size> for Point

§

fn sub_assign(&mut self, rhs: Size)

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
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<N, T> NativeTransmutableWrapper<N> for T
where T: NativeTransmutable<N>,

§

fn wrap(native: N) -> T

§

fn unwrap(self) -> N

§

fn inner(&self) -> &N

§

fn inner_mut(&mut self) -> &mut N

§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more