mirror of
https://github.com/mapillary/mapillary-js.git
synced 2026-02-01 14:33:45 +00:00
test: camera projection
This commit is contained in:
parent
f91ac44576
commit
4a9551f6dd
47
test/geometry/FisheyeCamera.test.ts
Normal file
47
test/geometry/FisheyeCamera.test.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { Vector3 } from "three";
|
||||
import {
|
||||
FisheyeCamera,
|
||||
FISHEYE_CAMERA_TYPE,
|
||||
} from "../../src/geometry/camera/FisheyeCamera";
|
||||
import { EPSILON } from "../../src/geometry/Constants";
|
||||
|
||||
describe("FisheyeCamera.ctor", () => {
|
||||
it("should be defined when constructed", () => {
|
||||
const camera = new FisheyeCamera([0.5, 0.1, 0.2]);
|
||||
expect(camera).toBeDefined();
|
||||
});
|
||||
|
||||
it("should set properties", () => {
|
||||
const camera = new FisheyeCamera([0.5, 0.1, 0.2]);
|
||||
expect(camera.type).toBe(FISHEYE_CAMERA_TYPE);
|
||||
expect(camera.parameters.focal).toBe(0.5);
|
||||
expect(camera.parameters.k1).toBe(0.1);
|
||||
expect(camera.parameters.k2).toBe(0.2);
|
||||
expect(camera.uniforms.radialPeak).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("FisheyeCamera.projectToSfm", () => {
|
||||
it("should project", () => {
|
||||
const camera = new FisheyeCamera([0.7, 0.01, 0.02]);
|
||||
const point = new Vector3(2, 3, 10).normalize().toArray();
|
||||
const sfm = camera.projectToSfm(point);
|
||||
const bearing = camera.bearingFromSfm(sfm);
|
||||
|
||||
expect(bearing[0]).toBeCloseTo(point[0], EPSILON);
|
||||
expect(bearing[1]).toBeCloseTo(point[1], EPSILON);
|
||||
expect(bearing[2]).toBeCloseTo(point[2], EPSILON);
|
||||
});
|
||||
});
|
||||
|
||||
describe("FisheyeCamera.bearingFromSfm", () => {
|
||||
it("should unproject", () => {
|
||||
const camera = new FisheyeCamera([0.7, 0.01, 0.02]);
|
||||
const point = [0.3, 0.5];
|
||||
const bearing = camera.bearingFromSfm(point);
|
||||
const sfm = camera.projectToSfm(bearing);
|
||||
|
||||
expect(sfm[0]).toBeCloseTo(point[0], EPSILON);
|
||||
expect(sfm[1]).toBeCloseTo(point[1], EPSILON);
|
||||
});
|
||||
});
|
||||
47
test/geometry/PerspectiveCamera.test.ts
Normal file
47
test/geometry/PerspectiveCamera.test.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { Vector3 } from "three";
|
||||
import {
|
||||
PerspectiveCamera,
|
||||
PERSPECTIVE_CAMERA_TYPE,
|
||||
} from "../../src/geometry/camera/PerspectiveCamera";
|
||||
import { EPSILON } from "../../src/geometry/Constants";
|
||||
|
||||
describe("PerspectiveCamera.ctor", () => {
|
||||
it("should be defined when constructed", () => {
|
||||
const camera = new PerspectiveCamera([0.5, 0.1, 0.2]);
|
||||
expect(camera).toBeDefined();
|
||||
});
|
||||
|
||||
it("should set properties", () => {
|
||||
const camera = new PerspectiveCamera([0.5, 0.1, 0.2]);
|
||||
expect(camera.type).toBe(PERSPECTIVE_CAMERA_TYPE);
|
||||
expect(camera.parameters.focal).toBe(0.5);
|
||||
expect(camera.parameters.k1).toBe(0.1);
|
||||
expect(camera.parameters.k2).toBe(0.2);
|
||||
expect(camera.uniforms.radialPeak).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("PerspectiveCamera.projectToSfm", () => {
|
||||
it("should project", () => {
|
||||
const camera = new PerspectiveCamera([0.8, 0.01, 0.02]);
|
||||
const point = new Vector3(2, 3, 10).normalize().toArray();
|
||||
const sfm = camera.projectToSfm(point);
|
||||
const bearing = camera.bearingFromSfm(sfm);
|
||||
|
||||
expect(bearing[0]).toBeCloseTo(point[0], EPSILON);
|
||||
expect(bearing[1]).toBeCloseTo(point[1], EPSILON);
|
||||
expect(bearing[2]).toBeCloseTo(point[2], EPSILON);
|
||||
});
|
||||
});
|
||||
|
||||
describe("PerspectiveCamera.bearingFromSfm", () => {
|
||||
it("should unproject", () => {
|
||||
const camera = new PerspectiveCamera([0.8, 0.01, 0.02]);
|
||||
const point = [0.3, 0.5];
|
||||
const bearing = camera.bearingFromSfm(point);
|
||||
const sfm = camera.projectToSfm(bearing);
|
||||
|
||||
expect(sfm[0]).toBeCloseTo(point[0], EPSILON);
|
||||
expect(sfm[1]).toBeCloseTo(point[1], EPSILON);
|
||||
});
|
||||
});
|
||||
43
test/geometry/SphericalCamera.test.ts
Normal file
43
test/geometry/SphericalCamera.test.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { Vector3 } from "three";
|
||||
import {
|
||||
SphericalCamera,
|
||||
SPHERICAL_CAMERA_TYPE,
|
||||
} from "../../src/geometry/camera/SphericalCamera";
|
||||
import { EPSILON } from "../../src/geometry/Constants";
|
||||
|
||||
describe("SphericalCamera.ctor", () => {
|
||||
it("should be defined when constructed", () => {
|
||||
const camera = new SphericalCamera();
|
||||
expect(camera).toBeDefined();
|
||||
});
|
||||
|
||||
it("should set properties", () => {
|
||||
const camera = new SphericalCamera();
|
||||
expect(camera.type).toBe(SPHERICAL_CAMERA_TYPE);
|
||||
});
|
||||
});
|
||||
|
||||
describe("SphericalCamera.projectToSfm", () => {
|
||||
it("should project", () => {
|
||||
const camera = new SphericalCamera();
|
||||
const point = new Vector3(2, 3, 10).normalize().toArray();
|
||||
const sfm = camera.projectToSfm(point);
|
||||
const bearing = camera.bearingFromSfm(sfm);
|
||||
|
||||
expect(bearing[0]).toBeCloseTo(point[0], EPSILON);
|
||||
expect(bearing[1]).toBeCloseTo(point[1], EPSILON);
|
||||
expect(bearing[2]).toBeCloseTo(point[2], EPSILON);
|
||||
});
|
||||
});
|
||||
|
||||
describe("SphericalCamera.bearingFromSfm", () => {
|
||||
it("should unproject", () => {
|
||||
const camera = new SphericalCamera();
|
||||
const point = [0.2, 0.1];
|
||||
const bearing = camera.bearingFromSfm(point);
|
||||
const sfm = camera.projectToSfm(bearing);
|
||||
|
||||
expect(sfm[0]).toBeCloseTo(point[0], EPSILON);
|
||||
expect(sfm[1]).toBeCloseTo(point[1], EPSILON);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user