Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Yaml needed opCmp #27

Merged
merged 2 commits into from

2 participants

@zeDoctor

Added opCmp for a yaml library which was using opCmp

gl3n/linalg.d
@@ -567,6 +567,18 @@ struct Vector(type, int dimension_) {
assert(almost_equal(v4.normalized, vec4(1.0f/sqrt(84.0f), 3.0f/sqrt(84.0f), 5.0f/sqrt(84.0f), 7.0f/sqrt(84.0f))));
}
+ const int opCmp(ref const Vector!(type, dimension_) vec) const {
@Dav1dde Owner
Dav1dde added a note

const int opCmp(ref const Vector vec) const {
Should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
gl3n/linalg.d
@@ -567,6 +567,18 @@ struct Vector(type, int dimension_) {
assert(almost_equal(v4.normalized, vec4(1.0f/sqrt(84.0f), 3.0f/sqrt(84.0f), 5.0f/sqrt(84.0f), 7.0f/sqrt(84.0f))));
}
+ const int opCmp(ref const Vector!(type, dimension_) vec) const {
+ foreach( i, a; vector ) {
@Dav1dde Owner
Dav1dde added a note

No spaces, after/before parentheses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
gl3n/linalg.d
@@ -567,6 +567,18 @@ struct Vector(type, int dimension_) {
assert(almost_equal(v4.normalized, vec4(1.0f/sqrt(84.0f), 3.0f/sqrt(84.0f), 5.0f/sqrt(84.0f), 7.0f/sqrt(84.0f))));
}
+ const int opCmp(ref const Vector!(type, dimension_) vec) const {
+ foreach( i, a; vector ) {
+ if( a < vec.vector[ i ] )
@Dav1dde Owner
Dav1dde added a note

As above (same below)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
gl3n/linalg.d
@@ -2405,6 +2417,18 @@ struct Quaternion(type) {
assert((q2 * v1).vector == [-2.0f, 36.0f, 38.0f]);
}
+ const int opCmp(ref const Quaternion!(type) qua) const {
@Dav1dde Owner
Dav1dde added a note

const int opCmp(ref const Quaternion qua) const {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
gl3n/linalg.d
@@ -2405,6 +2417,18 @@ struct Quaternion(type) {
assert((q2 * v1).vector == [-2.0f, 36.0f, 38.0f]);
}
+ const int opCmp(ref const Quaternion!(type) qua) const {
+ foreach( i, a; quaternion ) {
@Dav1dde Owner
Dav1dde added a note

Parenthesis (also below)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Dav1dde
Owner

Thanks for the pull, if you can change these minor issues and also fix the indentation (1 tab = 4 spaces) would be great!

@zeDoctor

No problem, the library has been a big help for us so we're glad we could help. :+1:

@Dav1dde
Owner

Thank you! (gonna fix the last space issue myself some other time :P). Good to hear that gl3n is useful :)

@Dav1dde Dav1dde merged commit 9919d5b into from
@Dav1dde Dav1dde referenced this pull request from a commit
@Dav1dde fix minor style issues of #27 a73bc77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 20, 2014
  1. @zeDoctor

    Yaml needed opCmp

    zeDoctor authored
Commits on Feb 21, 2014
  1. @zeDoctor

    Fixed spacing and parameters

    zeDoctor authored
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 0 deletions.
  1. +24 −0 gl3n/linalg.d
View
24 gl3n/linalg.d
@@ -567,6 +567,18 @@ struct Vector(type, int dimension_) {
assert(almost_equal(v4.normalized, vec4(1.0f/sqrt(84.0f), 3.0f/sqrt(84.0f), 5.0f/sqrt(84.0f), 7.0f/sqrt(84.0f))));
}
+ const int opCmp(ref const Vector vec) const {
+ foreach(i, a; vector) {
+ if(a < vec.vector[ i ])
+ return -1;
+ else if(a > vec.vector[ i ])
+ return 1;
+ }
+
+ // Vectors are the same
+ return 0;
+ }
+
const bool opEquals(T)(const T vec) if(!isArray!T && T.dimension == dimension) {
return vector == vec.vector;
}
@@ -2405,6 +2417,18 @@ struct Quaternion(type) {
assert((q2 * v1).vector == [-2.0f, 36.0f, 38.0f]);
}
+ const int opCmp(ref const Quaternion qua) const {
+ foreach(i, a; quaternion) {
+ if(a < qua.quaternion[ i ])
+ return -1;
+ else if(a > qua.quaternion[ i ])
+ return 1;
+ }
+
+ // Quaternions are the same
+ return 0;
+ }
+
bool opEquals(const Quaternion qu) const {
return quaternion == qu.quaternion;
}
Something went wrong with that request. Please try again.