Git Product home page Git Product logo

interval-rs's Introduction

generic-interval

License Rust codecov

A generic closed interval library.

An interval is a pair of numbers which represents all the numbers between them.
Intervals are considered closed so the bounds are included.
Intervals are written [a, b] to represent all the numbers between a and b inclusive, a โ‰ค b.

The library is designed to be used with any types that implement the Copy and PartialOrd traits including the floating point types: f64 and f32 and arithmetic types in new types.

The library is declared no_std so it can be used in embedded applications.

Examples

use generic_interval::{Interval, hull, intersection};

// An example new-type based on f64
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub struct Metres(pub f64);

let a = Interval::try_from((Metres(1.0), Metres(4.0))).unwrap();
let b = Interval::try_from((Metres(6.0), Metres(9.0))).unwrap();

// Note: the hull does not include 4.0-6.0
let result = hull(a, b);
assert_eq!(Metres(1.0), result.lower());
assert_eq!(Metres(9.0), result.upper());

let result = intersection(a, b);
assert!(result.is_none());

let c = Interval::try_from((Metres(4.0), Metres(9.0))).unwrap();
let result = intersection(a, c).unwrap();
assert_eq!(Metres(4.0), result.lower());
assert_eq!(Metres(4.0), result.upper());

License

generic-interval is provided under a MIT license, see LICENSE.

interval-rs's People

Contributors

kenba avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.