Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for degenerate axes of OrientedBoundingBox in distanceSquaredTo #9670

Merged
merged 5 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- Fixes an error with removing a CZML datasource when the clock interval has a duration of zero. [#9637](https://github.com/CesiumGS/cesium/pull/9637)
- Fixed the ability to set a material's image to `undefined` and `Material.DefaultImageId`. [#9644](https://github.com/CesiumGS/cesium/pull/9644)
- Fixed the calculation of `OrientedBoundingBox.distancedSquaredTo` such that they handle `halfAxes` with magnitudes near zero. [#9670](https://github.com/CesiumGS/cesium/pull/9670)
- Fixed render crash when creating a `polylineVolume` with very close points. [#9669](https://github.com/CesiumGS/cesium/pull/9669)

### 1.83 - 2021-07-01
Expand Down
86 changes: 83 additions & 3 deletions Source/Core/OrientedBoundingBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ OrientedBoundingBox.intersectPlane = function (box, plane) {
var scratchCartesianU = new Cartesian3();
var scratchCartesianV = new Cartesian3();
var scratchCartesianW = new Cartesian3();
var scratchValidAxis2 = new Cartesian3();
var scratchValidAxis3 = new Cartesian3();
var scratchPPrime = new Cartesian3();

/**
Expand Down Expand Up @@ -722,9 +724,87 @@ OrientedBoundingBox.distanceSquaredTo = function (box, cartesian) {
var vHalf = Cartesian3.magnitude(v);
var wHalf = Cartesian3.magnitude(w);

Cartesian3.normalize(u, u);
Cartesian3.normalize(v, v);
Cartesian3.normalize(w, w);
var uValid = true;
var vValid = true;
var wValid = true;

if (uHalf > 0) {
Cartesian3.divideByScalar(u, uHalf, u);
} else {
uValid = false;
}

if (vHalf > 0) {
Cartesian3.divideByScalar(v, vHalf, v);
} else {
vValid = false;
}

if (wHalf > 0) {
Cartesian3.divideByScalar(w, wHalf, w);
} else {
wValid = false;
}

var numberOfDegenerateAxes = !uValid + !vValid + !wValid;
var validAxis1;
var validAxis2;
var validAxis3;

if (numberOfDegenerateAxes === 1) {
var degenerateAxis = u;
validAxis1 = v;
validAxis2 = w;
if (!vValid) {
degenerateAxis = v;
validAxis1 = u;
} else if (!wValid) {
degenerateAxis = w;
validAxis2 = u;
}

validAxis3 = Cartesian3.cross(validAxis1, validAxis2, scratchValidAxis3);

if (degenerateAxis === u) {
u = validAxis3;
} else if (degenerateAxis === v) {
v = validAxis3;
} else if (degenerateAxis === w) {
w = validAxis3;
}
} else if (numberOfDegenerateAxes === 2) {
validAxis1 = u;
if (vValid) {
validAxis1 = v;
} else if (wValid) {
validAxis1 = w;
}

var crossVector = Cartesian3.UNIT_Y;
if (crossVector.equalsEpsilon(validAxis1, CesiumMath.EPSILON3)) {
crossVector = Cartesian3.UNIT_X;
}

validAxis2 = Cartesian3.cross(validAxis1, crossVector, scratchValidAxis2);
Cartesian3.normalize(validAxis2, validAxis2);
validAxis3 = Cartesian3.cross(validAxis1, validAxis2, scratchValidAxis3);
Cartesian3.normalize(validAxis3, validAxis3);

if (validAxis1 === u) {
v = validAxis2;
w = validAxis3;
} else if (validAxis1 === v) {
w = validAxis2;
u = validAxis3;
} else if (validAxis1 === w) {
u = validAxis2;
v = validAxis3;
}
} else if (numberOfDegenerateAxes === 3) {
u = Cartesian3.UNIT_X;
v = Cartesian3.UNIT_Y;
w = Cartesian3.UNIT_Z;
}

var pPrime = scratchPPrime;
pPrime.x = Cartesian3.dot(offset, u);
Expand Down
Loading