Struct Point
#[repr(C)]pub struct Point {
pub x: f32,
pub y: f32,
}Fields§
§x: f32§y: f32Implementations§
§impl Point
impl Point
pub const fn new(x: f32, y: f32) -> Point
pub const fn new(x: f32, y: f32) -> Point
Sets x and y. Used both to set a point and a vector.
xfloat x-axis valueyfloat y-axis value
pub fn iset(&mut self, p: impl Into<IPoint>)
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.
pinteger point members promoted to float
pub fn set_abs(&mut self, p: impl Into<Point>)
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.
pmembers providing magnitude forxandy
pub fn offset_points(points: &mut [Point], offset: impl Into<Point>)
pub fn offset_points(points: &mut [Point], offset: impl Into<Point>)
Adds offset to each point in points.
pointspoint arrayoffsetvector added to points
pub fn length(self) -> f32
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
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
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
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.
xproportional value forxyproportional value fory
Example (C++): https://fiddle.skia.org/c/@Point_setNormalize
pub fn set_length(&mut self, length: f32) -> bool
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.
lengthstraight-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
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.
xproportional value forxyproportional value forylengthstraight-line distance to origin
Example (C++): https://fiddle.skia.org/c/@Point_setLength_2
pub fn scaled(self, scale: f32) -> Point
pub fn scaled(self, scale: f32) -> Point
Returns the point times scale.
scalefactor to multiply the point by
Example (C++): https://fiddle.skia.org/c/@Point_scale
pub fn scale(&mut self, scale: f32)
pub fn scale(&mut self, scale: f32)
Scales the point in place by scale.
scalefactor to multiply the point by
pub fn negate(&mut self)
pub fn negate(&mut self)
Changes the sign of x and y.
pub fn equals(self, x: f32, y: f32) -> bool
pub fn equals(self, x: f32, y: f32) -> bool
Returns true if the point is equivalent to (x, y).
xvalue compared withxyvalue compared withy
pub fn length_xy(x: f32, y: f32) -> f32
pub fn length_xy(x: f32, y: f32) -> f32
Returns the Euclidean distance from origin, computed as sqrt(x * x + y * y).
xcomponent of lengthycomponent of length
Example (C++): https://fiddle.skia.org/c/@Point_Length
pub fn normalize_vector(v: &mut Point) -> f32
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.
vnormalized to unit length
Example (C++): https://fiddle.skia.org/c/@Point_Normalize
pub fn distance(a: Point, b: Point) -> f32
pub fn distance(a: Point, b: Point) -> f32
Returns the Euclidean distance between a and b.
aline end pointbline end point
pub fn dot_product(a: Point, b: Point) -> f32
pub fn dot_product(a: Point, b: Point) -> f32
Returns the dot product of a and b.
aleft side of dot productbright side of dot product
pub fn cross_product(a: Point, b: Point) -> f32
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.
aleft side of cross productbright side of cross product
pub fn cross(self, vec: Point) -> f32
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.
vecright side of cross product
Trait Implementations§
§impl AddAssign<Size> for Point
impl AddAssign<Size> for Point
§fn add_assign(&mut self, rhs: Size)
fn add_assign(&mut self, rhs: Size)
+= operation. Read moreimpl Copy for Point
§impl DivAssign<f32> for Point
impl DivAssign<f32> for Point
§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read more§impl MulAssign<f32> for Point
impl MulAssign<f32> for Point
§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreimpl StructuralPartialEq for Point
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§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.