Struct Vector

Source
pub struct Vector {
    pub guid: String,
    pub name: String,
    _x: f32,
    _y: f32,
    _z: f32,
    _length: f32,
    _has_length: bool,
}
Expand description

A 3D vector with visual properties and JSON serialization support.

Fields§

§guid: String§name: String§_x: f32§_y: f32§_z: f32§_length: f32§_has_length: bool

Implementations§

Source§

impl Vector

Source

pub fn new(x: f32, y: f32, z: f32) -> Self

Creates a new Vector with specified coordinates.

Source

pub fn zero() -> Self

Creates a zero vector.

Source

pub fn x_axis() -> Self

Creates a unit vector along X-axis.

§Returns

Vector Unit vector (1, 0, 0).

Source

pub fn y_axis() -> Self

Creates a unit vector along Y-axis.

§Returns

Vector Unit vector (0, 1, 0).

Source

pub fn x(&self) -> f32

Getters for coordinates

Source

pub fn y(&self) -> f32

Source

pub fn z(&self) -> f32

Source

pub fn set_x(&mut self, v: f32)

Setters for coordinates (invalidate cached length)

Source

pub fn set_y(&mut self, v: f32)

Source

pub fn set_z(&mut self, v: f32)

Source

pub fn z_axis() -> Self

Creates a unit vector along Z-axis.

§Returns

Vector Unit vector (0, 0, 1).

Source

pub fn from_start_and_end(start: &Vector, end: &Vector) -> Self

Creates a vector from start point to end point.

§Parameters

start : &Vector The starting point. end : &Vector The ending point.

§Returns

Vector The vector from start to end (end - start).

Source

fn invalidate_length_cache(&mut self)

Invalidates the cached length when coordinates change.

Source

pub fn compute_length(&self) -> f32

Computes the length (magnitude) of the vector without caching.

§Returns

f32 The length of the vector.

Source

pub fn magnitude(&mut self) -> f32

Gets the (cached) magnitude. Avoids recalculating if unchanged.

§Returns

f32 The magnitude (length) of the vector.

Source

pub fn length_squared(&self) -> f32

Computes the squared length of the vector (avoids sqrt for performance).

Source

pub fn normalize_self(&mut self)

Normalizes the vector in place.

Source

pub fn normalize(&self) -> Self

Returns a normalized copy of the vector.

Source

pub fn reverse(&mut self)

Reverses the vector direction in place.

Source

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

Scales the vector by a factor.

Source

pub fn scale_up(&mut self)

Scales the vector up by the global scale factor.

Source

pub fn scale_down(&mut self)

Scales the vector down by the global scale factor.

Source

pub fn dot(&self, other: &Vector) -> f32

Computes the dot product with another vector.

§Parameters

other : &Vector Other vector.

§Returns

f32 Dot product value.

Source

pub fn cross(&self, other: &Vector) -> Vector

Computes the cross product with another vector.

§Parameters

other : &Vector Other vector.

§Returns

Vector Cross product vector (orthogonal to inputs).

Source

pub fn angle(&self, other: &Vector, sign_by_cross_product: bool) -> f32

Computes the angle between this vector and another in degrees.

Source

pub fn projection(&self, onto: &Vector) -> (Vector, f32, Vector, f32)

Projects this vector onto another vector and returns detailed results.

Returns a tuple of:

  • projection vector of self onto onto
  • projected length (scalar projection)
  • perpendicular projected vector (self - projection)
  • perpendicular projected vector length
Source

pub fn projection_with( &self, onto: &Vector, tolerance: f32, ) -> (Vector, f32, Vector, f32)

Same as projection but allows specifying a tolerance.

Source

pub fn is_parallel_to(&self, other: &Vector) -> i32

Checks if this vector is parallel to another vector. Returns: 1 for parallel, -1 for antiparallel, 0 for not parallel.

Source

pub fn get_leveled_vector(&self, vertical_height: f32) -> Vector

Gets a leveled vector (replicates statics bug with degrees passed to cos).

Source

pub fn perpendicular_to(&mut self, v: &Vector) -> bool

Set this vector to be perpendicular to v (matches Python semantics). Returns true on success, false otherwise.

Source

pub fn cosine_law( triangle_edge_length_a: f32, triangle_edge_length_b: f32, angle_in_degrees_between_edges: f32, degrees: bool, ) -> f32

Computes the cosine law for triangle edge length.

Source

pub fn sine_law_angle( triangle_edge_length_a: f32, angle_in_degrees_in_front_of_a: f32, triangle_edge_length_b: f32, degrees: bool, ) -> f32

Computes the sine law for triangle angle.

Source

pub fn sine_law_length( triangle_edge_length_a: f32, angle_in_degrees_in_front_of_a: f32, angle_in_degrees_in_front_of_b: f32, degrees: bool, ) -> f32

Computes the sine law for triangle edge length.

Source

pub fn angle_between_vector_xy_components(vector: &Vector) -> f32

Computes the angle between vector XY components in degrees.

Source

pub fn angle_between_vector_xy_components_degrees(vector: &Vector) -> f32

Deprecated: use angle_between_vector_xy_components.

Source

pub fn sum_of_vectors(vectors: &[Vector]) -> Vector

Sums a collection of vectors.

Source

pub fn coordinate_direction_3angles(&self, degrees: bool) -> [f32; 3]

Computes coordinate direction angles (alpha, beta, gamma) in degrees.

Source

pub fn coordinate_direction_2angles(&self, degrees: bool) -> [f32; 2]

Computes coordinate direction angles (phi, theta) in degrees.

Source

pub fn jsondump(&self) -> Result<String, Box<dyn Error>>

Serializes the Vector to a JSON string.

Source

pub fn jsonload(json_data: &str) -> Result<Self, Box<dyn Error>>

Deserializes a Vector from a JSON string.

Source

pub fn to_json(&self, filepath: &str) -> Result<(), Box<dyn Error>>

Serializes the Vector to a JSON file.

Source

pub fn from_json(filepath: &str) -> Result<Self, Box<dyn Error>>

Deserializes a Vector from a JSON file.

Trait Implementations§

Source§

impl Add<&Vector> for Line

Source§

type Output = Line

The resulting type after applying the + operator.
Source§

fn add(self, other: &Vector) -> Line

Performs the + operation. Read more
Source§

impl Add<&Vector> for Polyline

Source§

fn add(self, other: &Vector) -> Polyline

Translates the polyline by a vector and returns a new polyline.

§Arguments
  • other - The translation vector.
Source§

type Output = Polyline

The resulting type after applying the + operator.
Source§

impl Add<Vector> for Plane

Source§

type Output = Plane

The resulting type after applying the + operator.
Source§

fn add(self, other: Vector) -> Plane

Performs the + operation. Read more
Source§

impl Add<Vector> for Point

Source§

type Output = Point

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vector) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Vector> for PointCloud

Source§

type Output = PointCloud

The resulting type after applying the + operator.
Source§

fn add(self, other: Vector) -> PointCloud

Performs the + operation. Read more
Source§

impl Add for &Vector

Source§

type Output = Vector

The resulting type after applying the + operator.
Source§

fn add(self, other: &Vector) -> Vector

Performs the + operation. Read more
Source§

impl Add for Vector

Source§

type Output = Vector

The resulting type after applying the + operator.
Source§

fn add(self, other: Vector) -> Vector

Performs the + operation. Read more
Source§

impl AddAssign<&Vector> for Line

Source§

fn add_assign(&mut self, other: &Vector)

Performs the += operation. Read more
Source§

impl AddAssign<&Vector> for Polyline

Source§

fn add_assign(&mut self, other: &Vector)

Translates all points in the polyline by a vector.

§Arguments
  • other - The translation vector.
Source§

impl AddAssign<&Vector> for Vector

Source§

fn add_assign(&mut self, other: &Vector)

Performs the += operation. Read more
Source§

impl AddAssign<Vector> for Plane

Source§

fn add_assign(&mut self, other: Vector)

Performs the += operation. Read more
Source§

impl AddAssign<Vector> for Point

Source§

fn add_assign(&mut self, rhs: Vector)

Performs the += operation. Read more
Source§

impl AddAssign<Vector> for PointCloud

Source§

fn add_assign(&mut self, other: Vector)

Performs the += operation. Read more
Source§

impl AddAssign for Vector

Source§

fn add_assign(&mut self, other: Vector)

Performs the += operation. Read more
Source§

impl Clone for Vector

Source§

fn clone(&self) -> Vector

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 Debug for Vector

Source§

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

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

impl Default for Vector

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Vector

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 Display for Vector

Source§

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

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

impl Div<f32> for &Vector

Source§

type Output = Vector

The resulting type after applying the / operator.
Source§

fn div(self, scalar: f32) -> Vector

Performs the / operation. Read more
Source§

impl Div<f32> for Vector

Source§

type Output = Vector

The resulting type after applying the / operator.
Source§

fn div(self, scalar: f32) -> Vector

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Vector

Source§

fn div_assign(&mut self, scalar: f32)

Performs the /= operation. Read more
Source§

impl Index<usize> for Vector

Source§

type Output = f32

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Vector

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Mul<f32> for &Vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: f32) -> Vector

Performs the * operation. Read more
Source§

impl Mul<f32> for Vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: f32) -> Vector

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Vector

Source§

fn mul_assign(&mut self, scalar: f32)

Performs the *= operation. Read more
Source§

impl Neg for &Vector

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vector

Performs the unary - operation. Read more
Source§

impl Neg for Vector

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vector

Performs the unary - operation. Read more
Source§

impl PartialEq for Vector

Source§

fn eq(&self, other: &Vector) -> 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 Serialize for Vector

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 Sub<&Vector> for Line

Source§

type Output = Line

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Vector) -> Line

Performs the - operation. Read more
Source§

impl Sub<&Vector> for Polyline

Source§

fn sub(self, other: &Vector) -> Polyline

Translates the polyline by the negative of a vector and returns a new polyline.

§Arguments
  • other - The vector to subtract.
Source§

type Output = Polyline

The resulting type after applying the - operator.
Source§

impl Sub<Vector> for Plane

Source§

type Output = Plane

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vector) -> Plane

Performs the - operation. Read more
Source§

impl Sub<Vector> for Point

Source§

type Output = Point

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vector) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Vector> for PointCloud

Source§

type Output = PointCloud

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vector) -> PointCloud

Performs the - operation. Read more
Source§

impl Sub for &Vector

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Vector) -> Vector

Performs the - operation. Read more
Source§

impl Sub for Vector

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vector) -> Vector

Performs the - operation. Read more
Source§

impl SubAssign<&Vector> for Line

Source§

fn sub_assign(&mut self, other: &Vector)

Performs the -= operation. Read more
Source§

impl SubAssign<&Vector> for Polyline

Source§

fn sub_assign(&mut self, other: &Vector)

Translates all points in the polyline by the negative of a vector.

§Arguments
  • other - The vector to subtract.
Source§

impl SubAssign<&Vector> for Vector

Source§

fn sub_assign(&mut self, other: &Vector)

Performs the -= operation. Read more
Source§

impl SubAssign<Vector> for Plane

Source§

fn sub_assign(&mut self, other: Vector)

Performs the -= operation. Read more
Source§

impl SubAssign<Vector> for Point

Source§

fn sub_assign(&mut self, rhs: Vector)

Performs the -= operation. Read more
Source§

impl SubAssign<Vector> for PointCloud

Source§

fn sub_assign(&mut self, other: Vector)

Performs the -= operation. Read more
Source§

impl SubAssign for Vector

Source§

fn sub_assign(&mut self, other: Vector)

Performs the -= operation. Read more
Source§

impl StructuralPartialEq for Vector

Auto Trait Implementations§

§

impl Freeze for Vector

§

impl RefUnwindSafe for Vector

§

impl Send for Vector

§

impl Sync for Vector

§

impl Unpin for Vector

§

impl UnwindSafe for Vector

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,