Debian Codegraph @

src/unit_vector.rs

raw symbols SCIP
1 // pathfinder/geometry/src/unit_vector.rs
2 //
3 // Copyright © 2019 The Pathfinder Project Developers.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! A utility module that allows unit vectors to be treated like angles.
12
13 use craterust-analyzer cargo pathfinder_geometry 0.5.1 crate/::vectorrust-analyzer cargo pathfinder_geometry 0.5.1 vector/::Vector2Frust-analyzer cargo pathfinder_geometry 0.5.1 vector/Vector2F#;
14 use pathfinder_simdrust-analyzer cargo pathfinder_simd 0.5.6 crate/::defaultrust-analyzer cargo pathfinder_simd 0.5.6 x86/::F32x2rust-analyzer cargo pathfinder_simd 0.5.6 x86/F32x2#;
15
16 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
17 pub struct UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#(pub Vector2Frust-analyzer cargo pathfinder_geometry 0.5.1 vector/Vector2F#);
18
19 impl UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector# {
20 #[inline]
21 pub fn from_anglerust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/impl#[UnitVector]from_angle().(theta: f32) -> UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector# {
22 UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#(Vector2Frust-analyzer cargo pathfinder_geometry 0.5.1 vector/Vector2F#::newrust-analyzer cargo pathfinder_geometry 0.5.1 vector/impl#[Vector2F]new().(theta.cosrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]cos().(), theta.sinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]sin().()))
23 }
24
25 /// Angle addition formula.
26 #[inline]
27 pub fn rotate_byrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/impl#[UnitVector]rotate_by().(&self, other: UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#) -> UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector# {
28 let products = (self.0rust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#0.).0rust-analyzer cargo pathfinder_geometry 0.5.1 vector/Vector2F#0..to_f32x4rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2]to_f32x4().().xyyxrust-analyzer cargo pathfinder_simd 0.5.6 x86/swizzle_f32x4/impl#[F32x4]xyyx().() rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Mul<Self>`]mul().*rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Mul<Self>`]mul(). rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Mul<Self>`]mul().(other.0rust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#0.).0rust-analyzer cargo pathfinder_geometry 0.5.1 vector/Vector2F#0..to_f32x4rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2]to_f32x4().().xyxyrust-analyzer cargo pathfinder_simd 0.5.6 x86/swizzle_f32x4/impl#[F32x4]xyxy().();
29 UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#(Vector2Frust-analyzer cargo pathfinder_geometry 0.5.1 vector/Vector2F#::newrust-analyzer cargo pathfinder_geometry 0.5.1 vector/impl#[Vector2F]new().(products[rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index().0]rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().products[rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index().1]rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index()., products[rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index().2]rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().products[rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index().3]rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index().))
30 }
31
32 /// Angle subtraction formula.
33 #[inline]
34 pub fn rev_rotate_byrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/impl#[UnitVector]rev_rotate_by().(&self, other: UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#) -> UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector# {
35 let products = (self.0rust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#0.).0rust-analyzer cargo pathfinder_geometry 0.5.1 vector/Vector2F#0..to_f32x4rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2]to_f32x4().().xyyxrust-analyzer cargo pathfinder_simd 0.5.6 x86/swizzle_f32x4/impl#[F32x4]xyyx().() rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Mul<Self>`]mul().*rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Mul<Self>`]mul(). rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Mul<Self>`]mul().(other.0rust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#0.).0rust-analyzer cargo pathfinder_geometry 0.5.1 vector/Vector2F#0..to_f32x4rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2]to_f32x4().().xyxyrust-analyzer cargo pathfinder_simd 0.5.6 x86/swizzle_f32x4/impl#[F32x4]xyxy().();
36 UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#(Vector2Frust-analyzer cargo pathfinder_geometry 0.5.1 vector/Vector2F#::newrust-analyzer cargo pathfinder_geometry 0.5.1 vector/impl#[Vector2F]new().(products[rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index().0]rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().products[rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index().1]rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index()., products[rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index().2]rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().products[rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index().3]rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x4][`Index<usize>`]index().))
37 }
38
39 /// Half angle formula.
40 #[inline]
41 pub fn halve_anglerust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/impl#[UnitVector]halve_angle().(&self) -> UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector# {
42 let x = self.0rust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#0..xrust-analyzer cargo pathfinder_geometry 0.5.1 vector/impl#[Vector2F]x().();
43 let term = F32x2rust-analyzer cargo pathfinder_simd 0.5.6 x86/F32x2#::newrust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2]new().(x, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().x);
44 UnitVectorrust-analyzer cargo pathfinder_geometry 0.5.1 unit_vector/UnitVector#(Vector2Frust-analyzer cargo pathfinder_geometry 0.5.1 vector/Vector2F#((F32x2rust-analyzer cargo pathfinder_simd 0.5.6 x86/F32x2#::splatrust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2]splat().(0.5) rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2][`Mul<Self>`]mul().*rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2][`Mul<Self>`]mul(). rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2][`Mul<Self>`]mul().(F32x2rust-analyzer cargo pathfinder_simd 0.5.6 x86/F32x2#::splatrust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2]splat().(1.0) rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2][`Add<Self>`]add().+rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2][`Add<Self>`]add(). rust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2][`Add<Self>`]add().term)).maxrust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2]max().(F32x2rust-analyzer cargo pathfinder_simd 0.5.6 x86/F32x2#::defaultrust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2][Default]default().())
45 .sqrtrust-analyzer cargo pathfinder_simd 0.5.6 x86/impl#[F32x2]sqrt().()))
46 }
47 }