Skip to content

Commit

Permalink
Fix warnings, improve some unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed May 14, 2022
1 parent 90dee2f commit 732a928
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 113 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build/
doc/
ddoc/
gl3n.pc
inmath.pc
import/
lib/
*.kdev*
Expand All @@ -11,4 +11,5 @@ __test__library__
*.rf
lt*
dub.selections.json
gl3n-test-library
inmath-test-library
out/
1 change: 1 addition & 0 deletions dscanner.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
long_line_check="disabled"
20 changes: 12 additions & 8 deletions inmath/aabb.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ private {
/// Params:
/// type = all values get stored as this type
struct AABBT(type, uint dimension_ = 3) {
alias type at; /// Holds the internal type of the AABB.
alias Vector!(at, dimension_) vec; /// Convenience alias to the corresponding vector type.
alias at = type; /// Holds the internal type of the AABB.
alias vec = Vector!(at, dimension_); /// Convenience alias to the corresponding vector type.
alias dimension = dimension_;
static assert(dimension > 0, "0 dimensional AABB don't exist.");

vec min = vec(cast(at)0.0); /// The minimum of the AABB (e.g. vec(0, 0, 0)).
vec max = vec(cast(at)0.0); /// The maximum of the AABB (e.g. vec(1, 1, 1)).


/// Gets a hash of this item
size_t toHash() const { return typeid(this).getHash(&this); }

@safe pure nothrow:

/// Constructs the AABB.
Expand Down Expand Up @@ -294,21 +298,21 @@ struct AABBT(type, uint dimension_ = 3) {
}
}

alias AABBT!(float, 3) AABB3;
alias AABBT!(float, 2) AABB2;

alias AABB3 AABB;
alias AABB3 = AABBT!(float, 3);
alias AABB2 = AABBT!(float, 2);

alias AABB = AABB3;

@("AABB")
unittest {
import inmath.util : TypeTuple;
alias TypeTuple!(ubyte, byte, short, ushort, int, uint, float, double) Types;
alias Types = TypeTuple!(ubyte, byte, short, ushort, int, uint, float, double);
foreach(type; Types)
{
foreach(dim; TupleRange!(1, 5))
{
{
alias AABBT!(type,dim) aabbTestType;
alias aabbTestType = AABBT!(type,dim);
auto instance = AABBT!(type,dim)();
}
}
Expand Down
34 changes: 21 additions & 13 deletions inmath/interpolate.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ private {
T interp(T)(T a, T b, float t) {
return a * (1 - t) + b * t;
}
alias interp interp_linear; /// ditto
alias interp lerp; /// ditto
alias interp mix; /// ditto
alias interp_linear = interp; /// ditto
alias lerp = interp; /// ditto
alias mix = interp; /// ditto


/// Interpolates spherical between to vectors or quaternions, also known as slerp.
Expand All @@ -44,7 +44,7 @@ T interp_spherical(T)(T a, T b, float t) if(is_vector!T || is_quaternion!T) {
return (sin((1.0-t)*theta)/sintheta)*a + (sin(t*theta)/sintheta)*b;
}
}
alias interp_spherical slerp; /// ditto
alias slerp = interp_spherical; /// ditto


/// Normalized quaternion linear interpolation.
Expand All @@ -63,6 +63,7 @@ quat nlerp(quat a, quat b, float t) {
return result;
}

@("vector interp")
unittest {
vec2 v2_1 = vec2(1.0f);
vec2 v2_2 = vec2(0.0f);
Expand All @@ -80,7 +81,17 @@ unittest {
assert(interp(v4_1, v4_2, 0.5f).vector == [0.5f, 0.5f, 0.5f, 0.5f]);
assert(interp(v4_1, v4_2, 0.0f) == v4_1);
assert(interp(v4_1, v4_2, 1.0f) == v4_2);

assert(interp_spherical(v2_1, v2_2, 0.0).vector == v2_1.vector);
assert(interp_spherical(v2_1, v2_2, 1.0).vector == v2_2.vector);
assert(interp_spherical(v3_1, v3_2, 0.0).vector == v3_1.vector);
assert(interp_spherical(v3_1, v3_2, 1.0).vector == v3_2.vector);
assert(interp_spherical(v4_1, v4_2, 0.0).vector == v4_1.vector);
assert(interp_spherical(v4_1, v4_2, 1.0).vector == v4_2.vector);
}

@("real interp")
unittest {
real r1 = 0.0;
real r2 = 1.0;
assert(interp(r1, r2, 0.5f) == 0.5);
Expand All @@ -94,21 +105,17 @@ unittest {
assert(interp(0.0f, 1.0f, 0.5f) == 0.5f);
assert(interp(0.0f, 1.0f, 0.0f) == 0.0f);
assert(interp(0.0f, 1.0f, 1.0f) == 1.0f);

}

@("quat interp")
unittest {
quat q1 = quat(1.0f, 1.0f, 1.0f, 1.0f);
quat q2 = quat(0.0f, 0.0f, 0.0f, 0.0f);

assert(interp(q1, q2, 0.0f).quaternion == q1.quaternion);
assert(interp(q1, q2, 0.5f).quaternion == [0.5f, 0.5f, 0.5f, 0.5f]);
assert(interp(q1, q2, 1.0f).quaternion == q2.quaternion);

assert(interp_spherical(v2_1, v2_2, 0.0).vector == v2_1.vector);
assert(interp_spherical(v2_1, v2_2, 1.0).vector == v2_2.vector);
assert(interp_spherical(v3_1, v3_2, 0.0).vector == v3_1.vector);
assert(interp_spherical(v3_1, v3_2, 1.0).vector == v3_2.vector);
assert(interp_spherical(v4_1, v4_2, 0.0).vector == v4_1.vector);
assert(interp_spherical(v4_1, v4_2, 1.0).vector == v4_2.vector);

assert(interp_spherical(q1, q2, 0.0f).quaternion == q1.quaternion);
assert(interp_spherical(q1, q2, 1.0f).quaternion == q2.quaternion);
}
Expand All @@ -119,6 +126,7 @@ T interp_nearest(T)(T x, T y, float t) {
else { return y; }
}

@("nearest interp")
unittest {
assert(interp_nearest(0.0, 1.0, 0.5f) == 1.0);
assert(interp_nearest(0.0, 1.0, 0.4f) == 0.0);
Expand Down
Loading

0 comments on commit 732a928

Please sign in to comment.