clampf 0.1.1

Clamped floating-point types.
Documentation
  • Coverage
  • 100%
    12 out of 12 items documented0 out of 9 items with examples
  • Size
  • Source code size: 10.47 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.97 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • senet4er

Clamped floating-point types.

Provides wrappers around floating-point values clamped to the range [0,1].

Example

Basic usage:

use clampf::Clamp32; // The `Clamp64` type is also available

#[derive(Debug)]
pub struct Color {
    red: Clamp32,   // A value in the range [0,1]
    green: Clamp32, // A value in the range [0,1]
    blue: Clamp32,  // A value in the range [0,1]
}

impl Color {
    pub fn new(red: f32, green: f32, blue: f32) -> Self {
        Color {
            // Check the `red` value
            red: Clamp32::new(red),
            // Check the `green` value
            green: Clamp32::new(green),
            // Check the `blue` value
            blue: Clamp32::new(blue),
        }
    }

    pub fn set_red(&mut self, red: f32) {
        // Check the `red` value
        self.red.set(red);
    }
}

Usage without the standard library

For usage without the standard library you need exclude the std feature. This can be done by editing Cargo.toml:

[dependencies.clampf]
version = "0.1"
default-features = false

or

[dependencies]
clampf = { version = "0.1", default-features = false }