Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
MAPSJS-2660: Unit testing of ClipPlanesEvaluator.
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com>
  • Loading branch information
atomicsulfate committed Jul 26, 2021
1 parent 6164e89 commit d1c4127
Show file tree
Hide file tree
Showing 5 changed files with 389 additions and 128 deletions.
1 change: 1 addition & 0 deletions @here/harp-mapview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from "./lib/copyrights/CopyrightCoverageProvider";
export * from "./lib/copyrights/UrlCopyrightProvider";
export * from "./lib/DataSource";
export * from "./lib/EventDispatcher";
export * from "./lib/FixedClipPlanesEvaluator";
export * from "./lib/PolarTileDataSource";
export * from "./lib/DecodedTileHelpers";
export * from "./lib/DepthPrePass";
Expand Down
73 changes: 1 addition & 72 deletions @here/harp-mapview/lib/ClipPlanesEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export class TopViewClipPlanesEvaluator extends ElevationBasedClipPlanesEvaluato
) {
super(maxElevation, minElevation);
assert(nearMin > 0);
assert(nearFarMarginRatio > epsilon);
assert(nearFarMarginRatio >= 0);
assert(farMaxRatio > 1.0);
const nearFarMargin = nearFarMarginRatio * nearMin;
this.m_minimumViewRange = {
Expand Down Expand Up @@ -860,77 +860,6 @@ export class TiltViewClipPlanesEvaluator extends TopViewClipPlanesEvaluator {
}
}

/**
* Provides the most basic evaluation concept giving fixed values with some constraints.
*/
export class FixedClipPlanesEvaluator implements ClipPlanesEvaluator {
readonly minFar: number;
private m_nearPlane: number;
private m_farPlane: number;

constructor(readonly minNear: number = 1, readonly minFarOffset: number = 10) {
this.minFar = minNear + minFarOffset;
this.m_nearPlane = minNear;
this.m_farPlane = this.minFar;
}

get nearPlane(): number {
return this.m_nearPlane;
}

set nearPlane(fixedNear: number) {
this.invalidatePlanes(fixedNear, this.m_farPlane);
}

get farPlane(): number {
return this.m_farPlane;
}

set farPlane(fixedFar: number) {
this.invalidatePlanes(this.m_nearPlane, fixedFar);
}

set minElevation(elevation: number) {}

get minElevation(): number {
// This evaluator does not support elevation so its always set to 0.
return 0;
}

set maxElevation(elevation: number) {}

get maxElevation(): number {
// This evaluator does not support elevation so its always set to 0.
return 0;
}

/** @override */
evaluateClipPlanes(
camera: THREE.Camera,
projection: Projection,
elevationProvider?: ElevationProvider
): ViewRanges {
// We do not need to perform actual evaluation cause results are precomputed and
// kept stable until somebody changes the properties.
const viewRanges: ViewRanges = {
near: this.m_nearPlane,
far: this.m_farPlane,
minimum: this.minNear,
maximum: this.m_farPlane
};
return viewRanges;
}

private invalidatePlanes(near: number, far: number) {
// When clamping prefer to extend far plane at about minimum distance, giving
// near distance setup priority over far.
const nearDist: number = Math.max(this.minNear, near);
const farDist: number = Math.max(this.minFar, far, nearDist + this.minFarOffset);
this.m_nearPlane = nearDist;
this.m_farPlane = farDist;
}
}

/**
* Factory function that creates default {@link ClipPlanesEvaluator}
* that calculates near plane based
Expand Down
77 changes: 77 additions & 0 deletions @here/harp-mapview/lib/FixedClipPlanesEvaluator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { ViewRanges } from "@here/harp-datasource-protocol/lib/ViewRanges";
import { Projection } from "@here/harp-geoutils";
import * as THREE from "three";

import { ClipPlanesEvaluator } from "./ClipPlanesEvaluator";
import { ElevationProvider } from "./ElevationProvider";

/**
* Provides the most basic evaluation concept giving fixed values with some constraints.
*/
export class FixedClipPlanesEvaluator implements ClipPlanesEvaluator {
readonly minFar: number;
private m_nearPlane: number;
private m_farPlane: number;

constructor(readonly minNear: number = 1, readonly minFarOffset: number = 10) {
this.minFar = minNear + minFarOffset;
this.m_nearPlane = minNear;
this.m_farPlane = this.minFar;
}

get nearPlane(): number {
return this.m_nearPlane;
}

set nearPlane(fixedNear: number) {
this.invalidatePlanes(fixedNear, this.m_farPlane);
}

get farPlane(): number {
return this.m_farPlane;
}

set farPlane(fixedFar: number) {
this.invalidatePlanes(this.m_nearPlane, fixedFar);
}

set minElevation(elevation: number) {}

get minElevation(): number {
// This evaluator does not support elevation so its always set to 0.
return 0;
}

set maxElevation(elevation: number) {}

get maxElevation(): number {
// This evaluator does not support elevation so its always set to 0.
return 0;
}

/** @override */
evaluateClipPlanes(
camera: THREE.Camera,
projection: Projection,
elevationProvider?: ElevationProvider
): ViewRanges {
// We do not need to perform actual evaluation cause results are precomputed and
// kept stable until somebody changes the properties.
const viewRanges: ViewRanges = {
near: this.m_nearPlane,
far: this.m_farPlane,
minimum: this.minNear,
maximum: this.m_farPlane
};
return viewRanges;
}

private invalidatePlanes(near: number, far: number) {
// When clamping prefer to extend far plane at about minimum distance, giving
// near distance setup priority over far.
const nearDist: number = Math.max(this.minNear, near);
const farDist: number = Math.max(this.minFar, far, nearDist + this.minFarOffset);
this.m_nearPlane = nearDist;
this.m_farPlane = farDist;
}
}
Loading

0 comments on commit d1c4127

Please sign in to comment.