Skip to content

Commit

Permalink
Add equalsEpsilon method to all Frustum types
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke San Antonio Bialecki committed Jul 19, 2018
1 parent 69b3e9d commit 8125bbf
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Source/Core/OrthographicFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ define([
'./defined',
'./defineProperties',
'./DeveloperError',
'./Math',
'./OrthographicOffCenterFrustum'
], function(
Check,
defaultValue,
defined,
defineProperties,
DeveloperError,
CesiumMath,
OrthographicOffCenterFrustum) {
'use strict';

Expand Down Expand Up @@ -273,5 +275,30 @@ define([
this._offCenterFrustum.equals(other._offCenterFrustum));
};

/**
* Compares the provided OrthographicFrustum componentwise and returns
* <code>true</code> if they pass an absolute or relative tolerance test,
* <code>false</code> otherwise.
*
* @param {OrthographicFrustum} [other] The right hand side OrthographicFrustum.
* @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
* @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
* @returns {Boolean} <code>true</code> if this and other are within the provided epsilon, <code>false</code> otherwise.
*/
OrthographicFrustum.prototype.equalsEpsilon = function(other, relativeEpsilon, absoluteEpsilon) {
if (!defined(other) || !(other instanceof OrthographicFrustum)) {
return false;
}

update(this);
update(other);

return (CesiumMath.equalsEpsilon(this.width, other.width, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.aspectRatio, other.aspectRatio, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.near, other.near, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.far, other.far, relativeEpsilon, absoluteEpsilon) &&
this._offCenterFrustum.equalsEpsilon(other._offCenterFrustum, relativeEpsilon, absoluteEpsilon));
};

return OrthographicFrustum;
});
24 changes: 24 additions & 0 deletions Source/Core/OrthographicOffCenterFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define([
'./defined',
'./defineProperties',
'./DeveloperError',
'./Math',
'./Matrix4'
], function(
Cartesian3,
Expand All @@ -15,6 +16,7 @@ define([
defined,
defineProperties,
DeveloperError,
CesiumMath,
Matrix4) {
'use strict';

Expand Down Expand Up @@ -370,5 +372,27 @@ define([
this.far === other.far);
};

/**
* Compares the provided OrthographicOffCenterFrustum componentwise and returns
* <code>true</code> if they pass an absolute or relative tolerance test,
* <code>false</code> otherwise.
*
* @param {OrthographicOffCenterFrustum} [other] The right hand side OrthographicOffCenterFrustum.
* @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
* @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
* @returns {Boolean} <code>true</code> if this and other are within the provided epsilon, <code>false</code> otherwise.
*/
OrthographicOffCenterFrustum.prototype.equalsEpsilon = function(other, relativeEpsilon, absoluteEpsilon) {
return (other === this) ||
(defined(other) &&
other instanceof OrthographicOffCenterFrustum &&
CesiumMath.equalsEpsilon(this.right, other.right, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.left, other.left, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.top, other.top, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.bottom, other.bottom, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.near, other.near, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.far, other.far, relativeEpsilon, absoluteEpsilon));
};

return OrthographicOffCenterFrustum;
});
27 changes: 27 additions & 0 deletions Source/Core/PerspectiveFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ define([
'./defined',
'./defineProperties',
'./DeveloperError',
'./Math',
'./PerspectiveOffCenterFrustum'
], function(
Check,
defaultValue,
defined,
defineProperties,
DeveloperError,
CesiumMath,
PerspectiveOffCenterFrustum) {
'use strict';

Expand Down Expand Up @@ -368,5 +370,30 @@ define([
this._offCenterFrustum.equals(other._offCenterFrustum));
};

/**
* Compares the provided PerspectiveFrustum componentwise and returns
* <code>true</code> if they pass an absolute or relative tolerance test,
* <code>false</code> otherwise.
*
* @param {PerspectiveFrustum} [other] The right hand side PerspectiveFrustum.
* @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
* @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
* @returns {Boolean} <code>true</code> if this and other are within the provided epsilon, <code>false</code> otherwise.
*/
PerspectiveFrustum.prototype.equalsEpsilon = function(other, relativeEpsilon, absoluteEpsilon) {
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
return false;
}

update(this);
update(other);

return (CesiumMath.equalsEpsilon(this.fov, other.fov, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.aspectRatio, other.aspectRatio, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.near, other.near, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.far, other.far, relativeEpsilon, absoluteEpsilon) &&
this._offCenterFrustum.equalsEpsilon(other._offCenterFrustum, relativeEpsilon, absoluteEpsilon));
};

return PerspectiveFrustum;
});
24 changes: 24 additions & 0 deletions Source/Core/PerspectiveOffCenterFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define([
'./defined',
'./defineProperties',
'./DeveloperError',
'./Math',
'./Matrix4'
], function(
Cartesian3,
Expand All @@ -15,6 +16,7 @@ define([
defined,
defineProperties,
DeveloperError,
CesiumMath,
Matrix4) {
'use strict';

Expand Down Expand Up @@ -421,5 +423,27 @@ define([
this.far === other.far);
};

/**
* Compares the provided PerspectiveOffCenterFrustum componentwise and returns
* <code>true</code> if they pass an absolute or relative tolerance test,
* <code>false</code> otherwise.
*
* @param {PerspectiveOffCenterFrustum} [other] The right hand side PerspectiveOffCenterFrustum.
* @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
* @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
* @returns {Boolean} <code>true</code> if this and other are within the provided epsilon, <code>false</code> otherwise.
*/
PerspectiveOffCenterFrustum.prototype.equalsEpsilon = function(other, relativeEpsilon, absoluteEpsilon) {
return (other === this) ||
(defined(other) &&
other instanceof PerspectiveOffCenterFrustum &&
CesiumMath.equalsEpsilon(this.right, other.right, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.left, other.left, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.top, other.top, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.bottom, other.bottom, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.near, other.near, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(this.far, other.far, relativeEpsilon, absoluteEpsilon));
};

return PerspectiveOffCenterFrustum;
});
36 changes: 36 additions & 0 deletions Specs/Core/OrthographicFrustumSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,42 @@ defineSuite([
expect(pixelSize.y).toEqual(2.0);
});

it('equals', function() {
var frustum2 = new OrthographicFrustum();
frustum2.near = 1.0;
frustum2.far = 3.0;
frustum2.width = 2.0;
frustum2.aspectRatio = 1.0;
expect(frustum.equals(frustum2)).toEqual(true);
});

it('equals epsilon', function() {
var frustum2 = new OrthographicFrustum();
frustum2.near = 1.0;
frustum2.far = 3.0;
frustum2.width = 2.0;
frustum2.aspectRatio = 1.0;
expect(frustum.equalsEpsilon(frustum2, CesiumMath.EPSILON7)).toEqual(true);

var frustum3 = new OrthographicFrustum();
frustum3.near = 1.01;
frustum3.far = 3.01;
frustum3.width = 2.01;
frustum3.aspectRatio = 1.01;
expect(frustum.equalsEpsilon(frustum3, CesiumMath.EPSILON1)).toEqual(true);

var frustum4 = new OrthographicFrustum();
frustum4.near = 1.0;
frustum4.far = 3.0;
frustum4.width = 2.0;
frustum4.aspectRatio = 1.1;
expect(frustum.equalsEpsilon(frustum4, CesiumMath.EPSILON2)).toEqual(false);
});

fit('equals undefined', function() {
expect(frustum.equals()).toEqual(false);
});

it('throws with undefined frustum parameters', function() {
var frustum = new OrthographicFrustum();
expect(function() {
Expand Down
45 changes: 45 additions & 0 deletions Specs/Core/OrthographicOffCenterFrustumSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,51 @@ defineSuite([
expect(pixelSize.y).toEqual(2.0);
});

it('equals', function() {
var frustum2 = new OrthographicOffCenterFrustum();
frustum2.near = 1.0;
frustum2.far = 3.0;
frustum2.right = 1.0;
frustum2.left = -1.0;
frustum2.top = 1.0;
frustum2.bottom = -1.0;

expect(frustum).toEqual(frustum2);
});

it('equals epsilon', function() {
var frustum2 = new OrthographicOffCenterFrustum();
frustum2.near = 1.0;
frustum2.far = 3.0;
frustum2.right = 1.0;
frustum2.left = -1.0;
frustum2.top = 1.0;
frustum2.bottom = -1.0;
expect(frustum.equalsEpsilon(frustum2, CesiumMath.EPSILON7)).toEqual(true);

var frustum3 = new OrthographicOffCenterFrustum();
frustum3.near = 1.01;
frustum3.far = 2.98;
frustum3.right = 1.02;
frustum3.left = -0.99;
frustum3.top = 0.99;
frustum3.bottom = -1.05;
expect(frustum.equalsEpsilon(frustum3, CesiumMath.EPSILON1)).toEqual(true);

var frustum4 = new OrthographicOffCenterFrustum();
frustum4.near = 1.1;
frustum4.far = 2.9;
frustum4.right = 0.0;
frustum4.left = -1.02;
frustum4.top = 1.02;
frustum4.bottom = -1.005;
expect(frustum.equalsEpsilon(frustum4, CesiumMath.EPSILON2)).toEqual(false);
});

it('equals undefined', function() {
expect(frustum.equals()).toEqual(false);
});

it('throws with undefined frustum parameters', function() {
var frustum = new OrthographicOffCenterFrustum();
expect(function() {
Expand Down
23 changes: 23 additions & 0 deletions Specs/Core/PerspectiveFrustumSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,29 @@ defineSuite([
expect(frustum.equals(frustum2)).toEqual(true);
});

it('equals epsilon', function() {
var frustum2 = new PerspectiveFrustum();
frustum2.near = 1.0;
frustum2.far = 2.0;
frustum2.fov = (Math.PI) / 3.0;
frustum2.aspectRatio = 1.0;
expect(frustum.equalsEpsilon(frustum2, CesiumMath.EPSILON7)).toEqual(true);

var frustum3 = new PerspectiveFrustum();
frustum3.near = 1.01;
frustum3.far = 2.01;
frustum3.fov = ((Math.PI) / 3.0) + 0.01;
frustum3.aspectRatio = 1.01;
expect(frustum.equalsEpsilon(frustum3, CesiumMath.EPSILON1)).toEqual(true);

var frustum4 = new PerspectiveFrustum();
frustum4.near = 1.0;
frustum4.far = 2.0;
frustum4.fov = (Math.PI) / 3.0;
frustum4.aspectRatio = 1.1;
expect(frustum.equalsEpsilon(frustum4, CesiumMath.EPSILON2)).toEqual(false);
});

it('equals undefined', function() {
expect(frustum.equals()).toEqual(false);
});
Expand Down
33 changes: 33 additions & 0 deletions Specs/Core/PerspectiveOffCenterFrustumSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,39 @@ defineSuite([
expect(frustum).toEqual(frustum2);
});

it('equals epsilon', function() {
var frustum2 = new PerspectiveOffCenterFrustum();
frustum2.right = 1.0;
frustum2.left = -frustum.right;
frustum2.top = 1.0;
frustum2.bottom = -frustum.top;
frustum2.near = 1.0;
frustum2.far = 2.0;
expect(frustum.equalsEpsilon(frustum2, CesiumMath.EPSILON7)).toEqual(true);

var frustum3 = new PerspectiveOffCenterFrustum();
frustum3.right = 1.01;
frustum3.left = -frustum.right;
frustum3.top = 1.01;
frustum3.bottom = -frustum.top;
frustum3.near = 1.01;
frustum3.far = 1.99;
expect(frustum.equalsEpsilon(frustum3, CesiumMath.EPSILON1)).toEqual(true);

var frustum4 = new PerspectiveOffCenterFrustum();
frustum4.right = 1.1;
frustum4.left = -frustum.right;
frustum4.top = 1.0;
frustum4.bottom = -frustum.top;
frustum4.near = 1.0;
frustum4.far = 2.0;
expect(frustum.equalsEpsilon(frustum4, CesiumMath.EPSILON2)).toEqual(false);
});

it('equals undefined', function() {
expect(frustum.equals()).toEqual(false);
});

it('throws with undefined frustum parameters', function() {
var frustum = new PerspectiveOffCenterFrustum();
expect(function() {
Expand Down

0 comments on commit 8125bbf

Please sign in to comment.