#[repr(C)]pub struct Point<T: Clone + Debug + Default + PartialEq> {
pub x: T,
pub y: T,
}Expand description
Describes a location in a 2D cartesian space.
It holds two public fields, x and y, which represent the coordinates in the space.
The type T for the coordinates can be any type that implements Default, Clone, and Debug.
§Examples
let point = Point { x: 10, y: 20 };
println!("{:?}", point); // Outputs: Point { x: 10, y: 20 }Fields§
§x: TThe x coordinate of the point.
y: TThe y coordinate of the point.
Implementations§
Source§impl<T: Clone + Debug + Default + PartialEq> Point<T>
impl<T: Clone + Debug + Default + PartialEq> Point<T>
Sourcepub fn map<U: Clone + Debug + Default + PartialEq>(
&self,
f: impl Fn(T) -> U,
) -> Point<U>
pub fn map<U: Clone + Debug + Default + PartialEq>( &self, f: impl Fn(T) -> U, ) -> Point<U>
Transforms the point to a Point<U> by applying the given function to both coordinates.
This method allows for converting a Point<T> to a Point<U> by specifying a closure
that defines how to convert between the two types. The closure is applied to both the x
and y coordinates, resulting in a new point of the desired type.
§Arguments
f- A closure that takes a value of typeTand returns a value of typeU.
§Examples
let p = Point { x: 3, y: 4 };
let p_float = p.map(|coord| coord as f32);
assert_eq!(p_float, Point { x: 3.0, y: 4.0 });Source§impl Point<Pixels>
impl Point<Pixels>
Sourcepub fn scale(&self, factor: f32) -> Point<ScaledPixels>
pub fn scale(&self, factor: f32) -> Point<ScaledPixels>
Scales the point by a given factor, which is typically derived from the resolution of a target display to ensure proper sizing of UI elements.
§Arguments
factor- The scaling factor to apply to both the x and y coordinates.
§Examples
let p = Point { x: Pixels::from(10.0), y: Pixels::from(20.0) };
let scaled_p = p.scale(1.5);
assert_eq!(scaled_p, Point { x: ScaledPixels::from(15.0), y: ScaledPixels::from(30.0) });Source§impl<T> Point<T>
impl<T> Point<T>
Sourcepub fn relative_to(&self, origin: &Point<T>) -> Point<T>
pub fn relative_to(&self, origin: &Point<T>) -> Point<T>
Get the position of this point, relative to the given origin
Source§impl<T> Point<T>
impl<T> Point<T>
Sourcepub fn clamp(&self, min: &Self, max: &Self) -> Self
pub fn clamp(&self, min: &Self, max: &Self) -> Self
Clamps the point to a specified range.
Given a minimum point and a maximum point, this method constrains the current point such that its coordinates do not exceed the range defined by the minimum and maximum points. If the current point’s coordinates are less than the minimum, they are set to the minimum. If they are greater than the maximum, they are set to the maximum.
§Arguments
min- A reference to aPointrepresenting the minimum allowable coordinates.max- A reference to aPointrepresenting the maximum allowable coordinates.
§Examples
let p = Point { x: 10, y: 20 };
let min = Point { x: 0, y: 5 };
let max = Point { x: 15, y: 25 };
let clamped_p = p.clamp(&min, &max);
assert_eq!(clamped_p, Point { x: 10, y: 20 });
let p_out_of_bounds = Point { x: -5, y: 30 };
let clamped_p_out_of_bounds = p_out_of_bounds.clamp(&min, &max);
assert_eq!(clamped_p_out_of_bounds, Point { x: 0, y: 25 });Trait Implementations§
Source§impl<T: Clone + Debug + Default + PartialEq + AddAssign> AddAssign for Point<T>
impl<T: Clone + Debug + Default + PartialEq + AddAssign> AddAssign for Point<T>
Source§fn add_assign(&mut self, rhs: Point<T>)
fn add_assign(&mut self, rhs: Point<T>)
+= operation. Read moreSource§impl<'de, T> Deserialize<'de> for Point<T>
impl<'de, T> Deserialize<'de> for Point<T>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T, T2> From<Point<T>> for Point<T2>
impl<T, T2> From<Point<T>> for Point<T2>
Source§fn from(point: TaffyPoint<T>) -> Point<T2>
fn from(point: TaffyPoint<T>) -> Point<T2>
Source§impl From<Point2D<i32, UnknownUnit>> for Point<DevicePixels>
impl From<Point2D<i32, UnknownUnit>> for Point<DevicePixels>
Source§impl<T: Clone + Debug + Default + PartialEq> From<PointRefinement<T>> for Point<T>
impl<T: Clone + Debug + Default + PartialEq> From<PointRefinement<T>> for Point<T>
Source§fn from(value: PointRefinement<T>) -> Self
fn from(value: PointRefinement<T>) -> Self
Source§impl<T> JsonSchema for Point<T>
impl<T> JsonSchema for Point<T>
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl<T, S> MulAssign<S> for Point<T>
impl<T, S> MulAssign<S> for Point<T>
Source§fn mul_assign(&mut self, rhs: S)
fn mul_assign(&mut self, rhs: S)
*= operation. Read moreSource§impl<T: Clone + Debug + Default + PartialEq> Refineable for Point<T>
impl<T: Clone + Debug + Default + PartialEq> Refineable for Point<T>
type Refinement = PointRefinement<T>
Source§fn refine(&mut self, refinement: &Self::Refinement)
fn refine(&mut self, refinement: &Self::Refinement)
Source§fn refined(self, refinement: Self::Refinement) -> Self
fn refined(self, refinement: Self::Refinement) -> Self
self and calling
refine on it.Source§fn is_superset_of(&self, refinement: &Self::Refinement) -> bool
fn is_superset_of(&self, refinement: &Self::Refinement) -> bool
true if this instance would contain all values from the refinement. Read moreSource§fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement
fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement
Source§impl<T: Clone + Debug + Default + PartialEq + SubAssign> SubAssign for Point<T>
impl<T: Clone + Debug + Default + PartialEq + SubAssign> SubAssign for Point<T>
Source§fn sub_assign(&mut self, rhs: Point<T>)
fn sub_assign(&mut self, rhs: Point<T>)
-= operation. Read moreimpl<T: Copy + Clone + Debug + Default + PartialEq> Copy for Point<T>
impl<T: Eq + Clone + Debug + Default + PartialEq> Eq for Point<T>
impl<T: Clone + Debug + Default + PartialEq> StructuralPartialEq for Point<T>
Auto Trait Implementations§
impl<T> Freeze for Point<T>where
T: Freeze,
impl<T> RefUnwindSafe for Point<T>where
T: RefUnwindSafe,
impl<T> Send for Point<T>where
T: Send,
impl<T> Sync for Point<T>where
T: Sync,
impl<T> Unpin for Point<T>where
T: Unpin,
impl<T> UnwindSafe for Point<T>where
T: UnwindSafe,
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().