Giter VIP home page Giter VIP logo

bin_packer_3d's People

Contributors

modulitos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bin_packer_3d's Issues

Avoid having to always use floats as argument constructors

We wanted to support floats as dimensions, but I couldn't figure out an easy way to do without aliasing our Dimension type to f32: pub type Dimension = f32;. Doing that forces us to always use floats as argument constructors, even in the case where an int is preferable:

    let deck = Item::new("deck", [2.0, 8.0, 12.0]);
    let die = Item::new("die", [8.0, 8.0, 8.0]);
    let items = vec![deck.clone(), deck.clone(), die, deck.clone(), deck];

    let packed_items = packing_algorithm(Bin::new([8.0, 8.0, 12.0]), &items);

I think the desired use case is to have the ability to support ints as well as floats:

    let item_1 = Item::new("deck", [2, 8, 12]);
    let item_2 = Item::new("deck", [2.25, 8.34, 12.65]);

But I'm not sure about the best way to do this. Perhaps we should leverage this crate: https://docs.rs/rust_decimal/1.0.1/rust_decimal/ ? Or maybe roll our own implementation?

If using our own implementation, one idea is to create a new struct with a fixed precision of 2 decimal places:

struct Dimension {
  whole_number: u8, // 0-255
  decimal: u8, // max value of 99
}

This would give our dimensions a range of 0.00 to 255.99, and should be easy extend this further as needed. However, in order to support the current new function:

https://github.com/modulitos/bin_packer_3d/blob/master/src/block.rs#L28-L32

pub fn new(d1: Dimension, d2: Dimension, d3: Dimension) -> Self {

we'll need to convert the integers and floats into our new Dimension struct. Perhaps we can have Dimension implement the From (or Into) traits:

impl From<u8> for Dimension {...}
impl From<f32> for Dimension {...}

But I'm not sure if this is the right approach - does this seem reasonable? Any feedback here would be appreciated ๐Ÿ™

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.