Skip to content

Commit 60331d6

Browse files
author
monkstone
committed
some work on Vec2D and Vec3D equals
1 parent 5d172ce commit 60331d6

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

examples/JRubyArt/implicit.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def define_lights
9595

9696
class EvaluatingVolume < Volume::VolumetricSpace
9797

98-
attr_reader :upper_bound, :lut
98+
attr_reader :upper_bound
9999
FREQ = Math::PI * 3.8
100100

101101
def initialize(scal_vec, resX, resY, resZ, upper_limit)

ext/toxi/geom/Vec2D.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public final Vec2D clear() {
277277

278278
@Override
279279
public int compareTo(ReadonlyVec2D v) {
280-
if (x == v.x() && y == v.y()) {
280+
if (this.equals(v)) {
281281
return 0;
282282
}
283283
float a = magSquared();
@@ -383,16 +383,20 @@ public final float dot(ReadonlyVec2D v) {
383383
* Returns true if the Object v is of type ReadonlyVec2D and all of the data
384384
* members of v are equal to the corresponding data members in this vector.
385385
*
386-
* @param v the object with which the comparison is made
386+
* @param obj the object with which the comparison is made
387387
* @return true or false
388388
*/
389+
389390
@Override
390-
public boolean equals(Object v) {
391-
if (v instanceof ReadonlyVec2D) {
392-
ReadonlyVec2D vv = (ReadonlyVec2D) v;
393-
return (x == vv.x() && y == vv.y());
391+
public boolean equals(Object obj) {
392+
if (obj instanceof ReadonlyVec2D) {
393+
final ReadonlyVec2D other = (ReadonlyVec2D) obj;
394+
if (!((Float) x).equals(other.x())) {
395+
return false;
396+
}
397+
return ((Float) y).equals(other.y());
394398
}
395-
return false;
399+
return false;
396400
}
397401

398402
/**
@@ -421,11 +425,12 @@ public int hashCode() {
421425
* @return true or false
422426
*/
423427
public boolean equals(ReadonlyVec2D v) {
424-
if (v instanceof ReadonlyVec2D){
425-
return (x == v.x() && y == v.y());
426-
}
427-
return false;
428-
}
428+
final ReadonlyVec2D other = (ReadonlyVec2D) v;
429+
if (!((Float) x).equals(other.x())) {
430+
return false;
431+
}
432+
return ((Float) y).equals(other.y());
433+
}
429434

430435
@Override
431436
public boolean equalsWithTolerance(ReadonlyVec2D v, float tolerance) {
@@ -441,7 +446,7 @@ public boolean equalsWithTolerance(ReadonlyVec2D v, float tolerance) {
441446
if (Float.isNaN(diff)) {
442447
return false;
443448
}
444-
return ((diff < 0 ? -diff : diff) > tolerance);
449+
return ((diff < 0 ? -diff : diff) < tolerance);
445450
}
446451
return false;
447452
}
@@ -671,7 +676,7 @@ public boolean isInRectangle(Rect r) {
671676
if (x < r.x || x > r.x + r.width) {
672677
return false;
673678
}
674-
return (y >= r.y || y >= r.y + r.height);
679+
return (y >= r.y || y <= r.y + r.height);
675680
}
676681

677682
@Override

ext/toxi/geom/Vec3D.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,13 @@ public final float dot(Vec3D v) {
468468
public boolean equals(Object v) {
469469
if (v instanceof ReadonlyVec3D) {
470470
ReadonlyVec3D vv = (ReadonlyVec3D) v;
471-
return (x == vv.x() && y == vv.y() && z == vv.z());
471+
if (!((Float)x).equals(vv.x())){
472+
return false;
473+
}
474+
if (!((Float)y).equals(vv.y())){
475+
return false;
476+
}
477+
return ((Float)z).equals(vv.z());
472478
}
473479
return false;
474480
}
@@ -501,16 +507,18 @@ public int hashCode() {
501507
* @return true or false
502508
*/
503509
public boolean equals(ReadonlyVec3D v) {
504-
try {
505-
return (x == v.x() && y == v.y() && z == v.z());
506-
} catch (NullPointerException e) {
510+
if (!((Float) x).equals(v.x())) {
511+
return false;
512+
}
513+
if (!((Float) y).equals(v.y())) {
507514
return false;
508515
}
516+
return ((Float) z).equals(v.z());
509517
}
510518

511519
@Override
512520
public boolean equalsWithTolerance(ReadonlyVec3D v, float tolerance) {
513-
try {
521+
if (v instanceof ReadonlyVec3D) {
514522
float diff = x - v.x();
515523
if (Float.isNaN(diff)) {
516524
return false;
@@ -530,9 +538,8 @@ public boolean equalsWithTolerance(ReadonlyVec3D v, float tolerance) {
530538
return false;
531539
}
532540
return ((diff < 0 ? -diff : diff) < tolerance);
533-
} catch (NullPointerException e) {
534-
return false;
535541
}
542+
return false;
536543
}
537544

538545
/**

0 commit comments

Comments
 (0)