Point

Struct Point 

Source
#[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: T

The x coordinate of the point.

§y: T

The y coordinate of the point.

Implementations§

Source§

impl<T: Clone + Debug + Default + PartialEq> Point<T>

Source

pub const fn new(x: T, y: T) -> Self

Creates a new Point with the specified x and y coordinates.

§Arguments
  • x - The horizontal coordinate of the point.
  • y - The vertical coordinate of the point.
§Examples
use gpui::Point;
let p = Point::new(10, 20);
assert_eq!(p.x, 10);
assert_eq!(p.y, 20);
Source

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 type T and returns a value of type U.
§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>

Source

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

pub fn magnitude(&self) -> f64

Calculates the Euclidean distance from the origin (0, 0) to this point.

§Examples
let p = Point { x: Pixels::from(3.0), y: Pixels::from(4.0) };
assert_eq!(p.magnitude(), 5.0);
Source§

impl<T> Point<T>
where T: Sub<T, Output = T> + Clone + Debug + Default + PartialEq,

Source

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>

Source

pub fn max(&self, other: &Self) -> Self

Returns a new point with the maximum values of each dimension from self and other.

§Arguments
  • other - A reference to another Point to compare with self.
§Examples
let p1 = Point { x: 3, y: 7 };
let p2 = Point { x: 5, y: 2 };
let max_point = p1.max(&p2);
assert_eq!(max_point, Point { x: 5, y: 7 });
Source

pub fn min(&self, other: &Self) -> Self

Returns a new point with the minimum values of each dimension from self and other.

§Arguments
  • other - A reference to another Point to compare with self.
§Examples
let p1 = Point { x: 3, y: 7 };
let p2 = Point { x: 5, y: 2 };
let min_point = p1.min(&p2);
assert_eq!(min_point, Point { x: 3, y: 2 });
Source

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 a Point representing the minimum allowable coordinates.
  • max - A reference to a Point representing 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> Add<Point<T>> for Bounds<T>
where T: Add<T, Output = T> + Clone + Debug + Default + PartialEq,

Source§

type Output = Bounds<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Point<T>) -> Self

Performs the + operation. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq + Add<Output = T>> Add for Point<T>

Source§

type Output = Point<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq + AddAssign> AddAssign for Point<T>

Source§

fn add_assign(&mut self, rhs: Point<T>)

Performs the += operation. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq> Along for Point<T>

Source§

type Unit = T

The unit associated with this type
Source§

fn along(&self, axis: Axis) -> T

Returns the unit along the given axis.
Source§

fn apply_along(&self, axis: Axis, f: impl FnOnce(T) -> T) -> Point<T>

Applies the given function to the unit along the given axis and returns a new value.
Source§

impl<T: Clone + Debug + Default + PartialEq> Clone for Point<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Clone + Debug + Default + PartialEq> Debug for Point<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Default + Clone + Debug + Default + PartialEq> Default for Point<T>

Source§

fn default() -> Point<T>

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

impl<'de, T> Deserialize<'de> for Point<T>
where T: Deserialize<'de> + Clone + Debug + Default + PartialEq,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq + Display> Display for Point<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T, S> Div<S> for Point<T>
where T: Div<S, Output = T> + Clone + Debug + Default + PartialEq, S: Clone,

Source§

type Output = Point<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: S) -> Self::Output

Performs the / operation. Read more
Source§

impl From<Point<Pixels>> for Point2D<f32, Pixels>

Source§

fn from(p: Point<Pixels>) -> Self

Converts to this type from the input type.
Source§

impl From<Point<Pixels>> for Point

Source§

fn from(p: Point<Pixels>) -> Self

Converts to this type from the input type.
Source§

impl From<Point<Pixels>> for Vector

Source§

fn from(p: Point<Pixels>) -> Self

Converts to this type from the input type.
Source§

impl<T, T2> From<Point<T>> for Point<T2>
where T: Into<T2>, T2: Clone + Debug + Default + PartialEq,

Source§

fn from(point: TaffyPoint<T>) -> Point<T2>

Converts to this type from the input type.
Source§

impl<T, T2> From<Point<T>> for Point<T2>
where T: Into<T2> + Clone + Debug + Default + PartialEq,

Source§

fn from(val: Point<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone + Debug + Default + PartialEq> From<Point<T>> for Size<T>

Source§

fn from(point: Point<T>) -> Self

Converts to this type from the input type.
Source§

impl From<Point<u32>> for Vector2I

Source§

fn from(size: Point<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Point2D<f32, UnknownUnit>> for Point<Pixels>

Source§

fn from(p: Point) -> Self

Converts to this type from the input type.
Source§

impl From<Point2D<i32, UnknownUnit>> for Point<DevicePixels>

Source§

fn from(value: Point) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone + Debug + Default + PartialEq> From<PointRefinement<T>> for Point<T>
where Option<T>: Clone,

Source§

fn from(value: PointRefinement<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + Clone + Debug + Default + PartialEq> Hash for Point<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T: IsZero + Clone + Debug + Default + PartialEq> IsZero for Point<T>

Source§

fn is_zero(&self) -> bool

Determines if the value is zero. Read more
Source§

impl<T> JsonSchema for Point<T>

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl<T, Rhs> Mul<Rhs> for Point<T>
where T: Mul<Rhs, Output = T> + Clone + Debug + Default + PartialEq, Rhs: Clone + Debug,

Source§

type Output = Point<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Rhs) -> Self::Output

Performs the * operation. Read more
Source§

impl<T, S> MulAssign<S> for Point<T>
where T: Mul<S, Output = T> + Clone + Debug + Default + PartialEq, S: Clone,

Source§

fn mul_assign(&mut self, rhs: S)

Performs the *= operation. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq + Negate> Negate for Point<T>

Source§

fn negate(self) -> Self

Returns the negation of the given value
Source§

impl<T: PartialEq + Clone + Debug + Default + PartialEq> PartialEq for Point<T>

Source§

fn eq(&self, other: &Point<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for Point<T>
where Option<T>: Clone,

Source§

type Refinement = PointRefinement<T>

Source§

fn refine(&mut self, refinement: &Self::Refinement)

Applies the given refinement to this instance, modifying it in place. Read more
Source§

fn refined(self, refinement: Self::Refinement) -> Self

Returns a new instance with the refinement applied, equivalent to cloning self and calling refine on it.
Source§

fn is_superset_of(&self, refinement: &Self::Refinement) -> bool

Returns true if this instance would contain all values from the refinement. Read more
Source§

fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement

Returns a refinement that represents the difference between this instance and the given refinement. Read more
Source§

fn from_cascade(cascade: &Cascade<Self>) -> Self
where Self: Sized + Default,

Creates an instance from a cascade by merging all refinements atop the default value.
Source§

impl<T> Serialize for Point<T>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Sub<Point<T>> for Bounds<T>
where T: Sub<T, Output = T> + Clone + Debug + Default + PartialEq,

Source§

type Output = Bounds<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Point<T>) -> Self

Performs the - operation. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq + Sub<Output = T>> Sub for Point<T>

Source§

type Output = Point<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq + SubAssign> SubAssign for Point<T>

Source§

fn sub_assign(&mut self, rhs: Point<T>)

Performs the -= operation. Read more
Source§

impl<T: Copy + Clone + Debug + Default + PartialEq> Copy for Point<T>

Source§

impl<T: Eq + Clone + Debug + Default + PartialEq> Eq for Point<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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
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
Source§

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

Source§

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

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

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

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

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

Source§

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

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

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

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,