-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12255 from p-skakun/fix-collinear-lines-corners
Fix for possible normalization issue for line corner points
- Loading branch information
Showing
5 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { CorridorGeometryLibrary, Ellipsoid } from "../../index.js"; | ||
|
||
describe("Core/CorridorGeometryLibrary", () => { | ||
describe("computePositions", () => { | ||
it("should not compute corners for collinear points", () => { | ||
const options = { | ||
positions: [ | ||
{ x: 1, y: 1, z: 1 }, | ||
{ x: 2, y: 2, z: 2 }, | ||
{ x: 3, y: 3, z: 3 }, | ||
{ x: 4, y: 4, z: 4 }, | ||
], | ||
width: 0.15, | ||
ellipsoid: Ellipsoid.WGS84, | ||
}; | ||
|
||
// The fact it doesn't throw an error also verifies the fix #12255 | ||
const result = CorridorGeometryLibrary.computePositions(options); | ||
expect(result.corners.length).toEqual(0); | ||
}); | ||
|
||
it("should compute corners for non-collinear points", () => { | ||
const options = { | ||
positions: [ | ||
{ x: 0, y: 0, z: 1 }, | ||
{ x: 1, y: 0, z: 2 }, | ||
{ x: 1, y: 1, z: 3 }, | ||
{ x: 0, y: 1, z: 4 }, | ||
], | ||
width: 0.15, | ||
ellipsoid: Ellipsoid.WGS84, | ||
}; | ||
|
||
const result = CorridorGeometryLibrary.computePositions(options); | ||
expect(result.corners.length).toEqual(2); | ||
}); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
packages/engine/Specs/Core/PolylineVolumeGeometryLibrarySpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
Cartesian3, | ||
Cartesian2, | ||
BoundingRectangle, | ||
PolylineVolumeGeometry, | ||
Ellipsoid, | ||
PolylineVolumeGeometryLibrary, | ||
} from "../../index.js"; | ||
|
||
describe("Core/PolylineVolumeGeometryLibrary", () => { | ||
describe("computePositions", () => { | ||
// Tests the fix #12255 | ||
it("should not throw error if positions are collinear after scaling to geodetic surface", () => { | ||
const positions = [ | ||
new Cartesian3(1, 1, 1), | ||
new Cartesian3(2, 2, 2), | ||
new Cartesian3(3, 3, 3), | ||
new Cartesian3(4, 4, 4), | ||
]; | ||
|
||
const shape = [ | ||
new Cartesian2(-0.15, -0.15), | ||
new Cartesian2(0.15, -0.15), | ||
new Cartesian2(0.15, 0.15), | ||
new Cartesian2(-0.15, 0.15), | ||
]; | ||
|
||
const ellipsoidStub = new Ellipsoid( | ||
6378137.0, | ||
6378137.0, | ||
6356752.3142451793, | ||
); | ||
// It's easier to stub the function than to predict the values to be collinear after calling the function | ||
ellipsoidStub.scaleToGeodeticSurface = function (cartesian, result) { | ||
return Cartesian3.clone(cartesian, result); | ||
}; | ||
|
||
const boundingRectangle = new BoundingRectangle(-0.15, -0.15, 0.3, 0.3); | ||
const geometry = new PolylineVolumeGeometry({ | ||
polylinePositions: positions, | ||
shapePositions: shape, | ||
}); | ||
geometry._ellipsoid = ellipsoidStub; | ||
|
||
expect(() => | ||
PolylineVolumeGeometryLibrary.computePositions( | ||
positions, | ||
shape, | ||
boundingRectangle, | ||
geometry, | ||
true, | ||
), | ||
).not.toThrowDeveloperError(); | ||
}); | ||
}); | ||
}); |