This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module toybox.math.vector; | |
private | |
{ | |
import std.stdio, std.string, std.metastrings, std.typecons, std.traits; | |
static import std.math, std.algorithm; | |
import toybox.math.matrix; | |
} | |
template IsComponentType(T) { static if(is(T == float) || is(T == double) || is(T == int) || is(T == uint) || is(T == bool)) { enum IsComponentType = true; } else { enum IsComponentType = false; } } | |
template IsFloat(T) { static if(is(T == float) || is(T == double)) { enum IsFloat = true; } else { enum IsFloat = false; } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static node_size : uint = 32; | |
struct HashArrayMappedTrie<T> { | |
root : ~Node<T>, | |
length : uint | |
} | |
enum Node<T> { | |
Values([T]), | |
Children([@Node<T>, ..node_size]), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::uint; use std::vec; | |
static node_size : uint = 32; | |
struct HashArrayMappedTrie<T> { | |
root : Node<T>, | |
length : uint | |
} | |
#[deriving(Clone)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src/functions.rs:1557:109: 1557:113 error: unresolved import. maybe a missing `extern mod libc`? | |
src/functions.rs:1557 fn glDrawElementsInstancedBaseInstance(mode: ::GLenum, count: ::GLsizei, gltype: ::GLenum, indices: *::libc::c_void, instancecount: ::GLsizei, baseinstance: ::GLuint); | |
^~~~ | |
src/functions.rs:1557:109: 1557:123 error: use of undeclared module `::libc` | |
src/functions.rs:1557 fn glDrawElementsInstancedBaseInstance(mode: ::GLenum, count: ::GLsizei, gltype: ::GLenum, indices: *::libc::c_void, instancecount: ::GLsizei, baseinstance: ::GLuint); | |
^~~~~~~~~~~~~~ | |
src/functions.rs:1557:109: 1557:123 error: use of undeclared type name `libc::c_void` | |
src/functions.rs:1557 fn glDrawElementsInstancedBaseInstance(mode: ::GLenum, c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[deriving(ToStr)] | |
struct Vec3f { | |
x: f32, | |
y: f32, | |
z: f32 | |
} | |
macro_rules! impl_vec_op( | |
($tr: ident, $op: ident, $vt: ident, $($members: ident)+) => ( | |
impl $tr<$vt, $vt> for $vt { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! define_vec ( | |
($vect: ident, $vecmod: ident, $compt: ty, $($components: ident)+) => ( | |
mod $vecmod { | |
#[deriving(ToStr)] | |
pub struct $vect { $($components : $compt),+ } | |
impl $vect | |
{ | |
#[inline(always)] | |
pub fn new($($components: $compt),+) -> $vect { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub use self::_vec2::vec2; | |
pub use self::_vec3::vec3; | |
pub use self::_vec4::vec4; | |
macro_rules! impl_vec_dot( | |
($x: ident, $y: ident, $z: ident, $w: ident) => ( x.$x * y.$x + x.$y * y.$y + x.$z * y.$z + x.$w * y.$w ); | |
($x: ident, $y: ident, $z: ident) => ( x.$x * y.$x + x.$y * y.$y + x.$z * y.$z ); | |
($x: ident, $y: ident) => ( x.$x * y.$x + x.$y * y.$y ); | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo { | |
bar: ~[int] | |
} | |
fn main() { | |
let mut foo = Foo { bar: ~[0i] }; | |
foo.bar = append_one(foo.bar, 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[deriving(Clone)] | |
struct Foo<'self> | |
{ | |
foo: &'self str | |
} | |
fn main() { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo<'self> | |
{ | |
foo: &'self fn() | |
} | |
impl<'self> Foo<'self> { | |
fn foo(&self) { | |
println("Method foo"); | |
} | |
} |