Debian Codegraph @

src/util.rs

raw symbols SCIP
1 // pathfinder/geometry/src/util.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 //! Various utilities.
12
13 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::f32rust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/;
14
15 pub const EPSILONrust-analyzer cargo pathfinder_geometry 0.5.1 util/EPSILON.: f32 = 0.001;
16
17 /// Approximate equality.
18 #[inline]
19 pub fn approx_eqrust-analyzer cargo pathfinder_geometry 0.5.1 util/approx_eq().(a: f32, b: f32) -> bool {
20 f32::absrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]abs().(a 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().b) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]le().EPSILONrust-analyzer cargo pathfinder_geometry 0.5.1 util/EPSILON.
21 }
22
23 /// Linear interpolation.
24 #[inline]
25 pub fn lerprust-analyzer cargo pathfinder_geometry 0.5.1 util/lerp().(a: f32, b: f32, t: f32) -> f32 {
26 a 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().(b 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().a) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().t
27 }
28
29 /// Clamping.
30 #[inline]
31 pub fn clamprust-analyzer cargo pathfinder_geometry 0.5.1 util/clamp().(x: f32, min_val: f32, max_val: f32) -> f32 {
32 f32::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]min().(max_val, f32::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]max().(min_val, x))
33 }
34
35 /// Divides `a` by `b`, rounding up.
36 #[inline]
37 pub fn alignup_i32rust-analyzer cargo pathfinder_geometry 0.5.1 util/alignup_i32().(a: i32, b: i32) -> i32 {
38 (a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub().1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Div<Self>`]div().b
39 }