Code Monkey home page Code Monkey logo

coord-rs's Introduction

coord is deprecated. I recommend using vek, a project with near-identical aims instead.

Coord Coord

Build Status Crates.io Downloads Docs

Description

Coord is a simple, ergonomic vector mathematics crate for Rust designed for use in game development, physics engines and other programs that deal with general-purpose multi-variable mathematics.

Coord is now no_std compatible!

Example

#[macro_use]
extern crate coord;
use coord::prelude::*;

fn main() {
	// Coord supports 4 multi-variable vector types: Vec1, Vec2, Vec3 and Vec4
	let mut v = vec3!(1.0, 2.5, 3.0);

	// Coord supports common mathematical operations for both primitive and vector types
	v += vec3![1.0; 3] * 5.0;
	let _ = v * vec3!([10.0, 10.0, 10.0]);

	// Coord implements many common mathematic functions
	let _ = v.length();
	let _ = v.norm();

	// Coord supports debug and display printing of vectors
	println!("Debug => {:?}", v);
	println!("Display => {}", v);

	// Coord allows arbitrary vector component types
	let _ = vec2!(true, false); // Create a boolean vector
}

For more examples, visit https://docs.rs/coord

Features

  • Generic Vec1, Vec2, Vec3 and Vec4 types
  • Utility macros to make vector manipulation simpler
  • VecXu, VecXi and VecXf default type definitions
  • Basic mathematic operations (Add, Sub, Mul, Div)
  • Mathematic functions (i.e: .length(), .norm(), etc.)
  • Serialization support with the serialize feature
  • 64 bit default type support with the large_defaults feature
  • Hash support
  • .map() method performing arbitrary element-wise vector transformation
  • .convert_to() method allowing element-wise vector conversion
  • .div_floor() method allowing floor-like vector division

Coming Soon

  • Bitwise operations
  • More mathematic functions
  • Modulo operator for integer vector types

Using Coord

To use Coord in your Rust project, add the following line beneath the [dependencies] section in your Cargo.toml file.

coord = "0.11.0"

If you want to enable serialization or 64-bit defaults, you should specify the dependency like the following line instead.

[dependencies.coord]
version = "0.7.0"
features = ["serialize", "large_defaults"]

FAQ

Why does Coord exist?

Coord came about as a result of a general dissatisfaction with existing vector mathematics libraries during development of the Veloren Project. Existing solutions were either too complicated, awkward to use, or required too many dependencies.

Does Coord aim to eventually implement feature X?

Coord does not aim to be a fully-blown N-dimensional mathematics library. It aims to implement a small yet elegant set of features that make it suitable for applications where simple multi-variable mathematics is required.

If you think feature X falls within that scope, and is not yet on the project todo list, you can open an issue on GitHub and I'll consider implementing it.

Why does Coord choose 32 bit values for its default types?

Coord defines a set of 'default' types within the defaults module. They are included within the prelude module too. These default types, such as Vec2f, Vec3u, Vec4b, etc. exist to make writing code with Coord faster. It is still possible to program without them like Vec2<f32>, Vec3<u32>, Vec4<bool>, etc. Coord chooses 32-bit types by default because it is my belief that these are more useful when developing for games and physics engines, which require fast calculations. Additionally, 32 bit floating point types means that Coord is compatible with OpenGL.

Why does Coord not have a general-purpose vec! macro?

Such a macro would conflict with the vec! macro within Rust's standard library.

Why does Coord not rely on the standard library?

It doesn't need to. Why limit the use cases of the library by requiring std?

Bug! Bug! I've found a bug!

Open an issue on Github and I'll fix it as soon as possible.

You can open an issue here

License

Coord is open source software, licensed under the MIT license (See 'LICENSE' or http://opensource.org/licenses/MIT)

coord-rs's People

Contributors

johannesvollmer avatar zesterer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

coord-rs's Issues

alloing &Vec3 + &Vec3

currently you have to dereference it explicitly

*x = *y  + *z

new maybe:

*x = y  + z

Please mark the crate as deprecated on crates.io

I've implemented this package and looked what it would take to add a couple of features. I came to github and see it's intentionally no longer maintained. Could you please label this package as deprecated on crates.io. Thanks.

coord is not actually no_std compatible

Despite being tagged on crates.io, coord is not no_std compatible because of a transitive dependency on std through the num-traits crate.

It looks like the continuous build is only building on Travis's default target (which I'm guessing is x86-64 linux?). Crates that set #[no_std] can still access the std crate if available. To test, try a bare metal target. For example:

$ rustup target add thumbv7em-none-eabihf
$ git clone https://github.com/zesterer/coord-rs.git
$ cd coord-rs
$ cargo build --target thumbv7em-none-eabihf

You'll get an error like the following:

    Checking rustc-serialize v0.3.24
    Checking rand v0.4.6
   Compiling num-iter v0.1.37
    Checking num-traits v0.2.6
error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv7em-none-eabihf` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: Could not compile `rand`.
warning: build failed, waiting for other jobs to finish...
error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv7em-none-eabihf` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `std`
  --> /home/cbiffle/.cargo/registry/src/github.com-1ecc6299db9ec823/num-traits-0.2.6/src/lib.rs:21:1
   |
21 | extern crate std;
   | ^^^^^^^^^^^^^^^^^ can't find crate
   |
   = note: the `thumbv7em-none-eabihf` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: Could not compile `rustc-serialize`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `num-traits`.

add a map_vector method to iterate 2 vectors at once

if res.correction.x != 0.0 {
                        entity.vel_mut().x = 0.0;
                    }
                    if res.correction.y != 0.0 {
                        entity.vel_mut().y = 0.0;
                    }
                    if res.correction.z != 0.0 {
                        entity.vel_mut().z = 0.0;
                    }
if velocity.x.abs() / half_chunk_scale.x > speed_step_cnt {
            speed_step_cnt = velocity.x.abs() / half_chunk_scale.x;
        }
        if velocity.y.abs() / half_chunk_scale.y > speed_step_cnt {
            speed_step_cnt = velocity.y.abs() / half_chunk_scale.y;
        }
        if velocity.z.abs() / half_chunk_scale.z > speed_step_cnt {
            speed_step_cnt = velocity.z.abs() / half_chunk_scale.z;
        }

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.