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
impl Vector
pub fn y(&self) -> f32
pub fn z(&self) -> f32
pub fn set_y(&mut self, v: f32)
pub fn set_z(&mut self, v: f32)
Sourcepub fn from_start_and_end(start: &Vector, end: &Vector) -> Self
pub fn from_start_and_end(start: &Vector, end: &Vector) -> Self
Sourcefn invalidate_length_cache(&mut self)
fn invalidate_length_cache(&mut self)
Invalidates the cached length when coordinates change.
Sourcepub fn compute_length(&self) -> f32
pub fn compute_length(&self) -> f32
Computes the length (magnitude) of the vector without caching.
§Returns
f32 The length of the vector.
Sourcepub fn magnitude(&mut self) -> f32
pub fn magnitude(&mut self) -> f32
Gets the (cached) magnitude. Avoids recalculating if unchanged.
§Returns
f32 The magnitude (length) of the vector.
Sourcepub fn length_squared(&self) -> f32
pub fn length_squared(&self) -> f32
Computes the squared length of the vector (avoids sqrt for performance).
Sourcepub fn normalize_self(&mut self)
pub fn normalize_self(&mut self)
Normalizes the vector in place.
Sourcepub fn scale_down(&mut self)
pub fn scale_down(&mut self)
Scales the vector down by the global scale factor.
Sourcepub fn angle(&self, other: &Vector, sign_by_cross_product: bool) -> f32
pub fn angle(&self, other: &Vector, sign_by_cross_product: bool) -> f32
Computes the angle between this vector and another in degrees.
Sourcepub fn projection(&self, onto: &Vector) -> (Vector, f32, Vector, f32)
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
ontoonto
- projected length (scalar projection)
- perpendicular projected vector (self - projection)
- perpendicular projected vector length
Sourcepub fn projection_with(
&self,
onto: &Vector,
tolerance: f32,
) -> (Vector, f32, Vector, f32)
pub fn projection_with( &self, onto: &Vector, tolerance: f32, ) -> (Vector, f32, Vector, f32)
Same as projection
but allows specifying a tolerance.
Sourcepub fn is_parallel_to(&self, other: &Vector) -> i32
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.
Sourcepub fn get_leveled_vector(&self, vertical_height: f32) -> Vector
pub fn get_leveled_vector(&self, vertical_height: f32) -> Vector
Gets a leveled vector (replicates statics bug with degrees passed to cos).
Sourcepub fn perpendicular_to(&mut self, v: &Vector) -> bool
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.
Sourcepub fn cosine_law(
triangle_edge_length_a: f32,
triangle_edge_length_b: f32,
angle_in_degrees_between_edges: f32,
degrees: bool,
) -> f32
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.
Sourcepub 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
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.
Sourcepub 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
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.
Sourcepub fn angle_between_vector_xy_components(vector: &Vector) -> f32
pub fn angle_between_vector_xy_components(vector: &Vector) -> f32
Computes the angle between vector XY components in degrees.
Sourcepub fn angle_between_vector_xy_components_degrees(vector: &Vector) -> f32
pub fn angle_between_vector_xy_components_degrees(vector: &Vector) -> f32
Deprecated: use angle_between_vector_xy_components
.
Sourcepub fn sum_of_vectors(vectors: &[Vector]) -> Vector
pub fn sum_of_vectors(vectors: &[Vector]) -> Vector
Sums a collection of vectors.
Sourcepub fn coordinate_direction_3angles(&self, degrees: bool) -> [f32; 3]
pub fn coordinate_direction_3angles(&self, degrees: bool) -> [f32; 3]
Computes coordinate direction angles (alpha, beta, gamma) in degrees.
Sourcepub fn coordinate_direction_2angles(&self, degrees: bool) -> [f32; 2]
pub fn coordinate_direction_2angles(&self, degrees: bool) -> [f32; 2]
Computes coordinate direction angles (phi, theta) in degrees.
Sourcepub fn jsondump(&self) -> Result<String, Box<dyn Error>>
pub fn jsondump(&self) -> Result<String, Box<dyn Error>>
Serializes the Vector to a JSON string.
Sourcepub fn jsonload(json_data: &str) -> Result<Self, Box<dyn Error>>
pub fn jsonload(json_data: &str) -> Result<Self, Box<dyn Error>>
Deserializes a Vector from a JSON string.
Trait Implementations§
Source§impl Add<Vector> for PointCloud
impl Add<Vector> for PointCloud
Source§type Output = PointCloud
type Output = PointCloud
+
operator.Source§impl AddAssign<&Vector> for Line
impl AddAssign<&Vector> for Line
Source§fn add_assign(&mut self, other: &Vector)
fn add_assign(&mut self, other: &Vector)
+=
operation. Read moreSource§impl AddAssign<&Vector> for Vector
impl AddAssign<&Vector> for Vector
Source§fn add_assign(&mut self, other: &Vector)
fn add_assign(&mut self, other: &Vector)
+=
operation. Read moreSource§impl AddAssign<Vector> for Plane
impl AddAssign<Vector> for Plane
Source§fn add_assign(&mut self, other: Vector)
fn add_assign(&mut self, other: Vector)
+=
operation. Read moreSource§impl AddAssign<Vector> for Point
impl AddAssign<Vector> for Point
Source§fn add_assign(&mut self, rhs: Vector)
fn add_assign(&mut self, rhs: Vector)
+=
operation. Read moreSource§impl AddAssign<Vector> for PointCloud
impl AddAssign<Vector> for PointCloud
Source§fn add_assign(&mut self, other: Vector)
fn add_assign(&mut self, other: Vector)
+=
operation. Read moreSource§impl AddAssign for Vector
impl AddAssign for Vector
Source§fn add_assign(&mut self, other: Vector)
fn add_assign(&mut self, other: Vector)
+=
operation. Read moreSource§impl<'de> Deserialize<'de> for Vector
impl<'de> Deserialize<'de> for Vector
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 DivAssign<f32> for Vector
impl DivAssign<f32> for Vector
Source§fn div_assign(&mut self, scalar: f32)
fn div_assign(&mut self, scalar: f32)
/=
operation. Read moreSource§impl MulAssign<f32> for Vector
impl MulAssign<f32> for Vector
Source§fn mul_assign(&mut self, scalar: f32)
fn mul_assign(&mut self, scalar: f32)
*=
operation. Read moreSource§impl Sub<Vector> for PointCloud
impl Sub<Vector> for PointCloud
Source§type Output = PointCloud
type Output = PointCloud
-
operator.Source§impl SubAssign<&Vector> for Line
impl SubAssign<&Vector> for Line
Source§fn sub_assign(&mut self, other: &Vector)
fn sub_assign(&mut self, other: &Vector)
-=
operation. Read moreSource§impl SubAssign<&Vector> for Polyline
impl SubAssign<&Vector> for Polyline
Source§fn sub_assign(&mut self, other: &Vector)
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
impl SubAssign<&Vector> for Vector
Source§fn sub_assign(&mut self, other: &Vector)
fn sub_assign(&mut self, other: &Vector)
-=
operation. Read moreSource§impl SubAssign<Vector> for Plane
impl SubAssign<Vector> for Plane
Source§fn sub_assign(&mut self, other: Vector)
fn sub_assign(&mut self, other: Vector)
-=
operation. Read moreSource§impl SubAssign<Vector> for Point
impl SubAssign<Vector> for Point
Source§fn sub_assign(&mut self, rhs: Vector)
fn sub_assign(&mut self, rhs: Vector)
-=
operation. Read moreSource§impl SubAssign<Vector> for PointCloud
impl SubAssign<Vector> for PointCloud
Source§fn sub_assign(&mut self, other: Vector)
fn sub_assign(&mut self, other: Vector)
-=
operation. Read moreSource§impl SubAssign for Vector
impl SubAssign for Vector
Source§fn sub_assign(&mut self, other: Vector)
fn sub_assign(&mut self, other: Vector)
-=
operation. Read more