Utilities for map projections.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.0 KiB

  1. // import * as fc from 'fast-check';
  2. import { describe, it, expect } from 'vitest';
  3. import * as orbisCore from '../src';
  4. describe('orbis-core', () => {
  5. describe('project', () => {
  6. it('throws error for invalid coordinates', () => {
  7. expect(() => orbisCore.project([-181, 90], ['Equirectangular'])).toThrowError(RangeError);
  8. expect(() => orbisCore.project([181, 90], ['Equirectangular'])).toThrowError(RangeError);
  9. expect(() => orbisCore.project([-180, 91], ['Equirectangular'])).toThrowError(RangeError);
  10. expect(() => orbisCore.project([-180, -91], ['Equirectangular'])).toThrowError(RangeError);
  11. });
  12. it('returns identity for equirectangular', () => {
  13. // fc.assert(
  14. // fc.property(
  15. // fc.tuple(
  16. // fc.float().filter((c) => -180 <= c && c <= 180),
  17. // fc.float().filter((c) => -180 <= c && c <= 180),
  18. // ),
  19. // (coords) => {
  20. // expect(orbisCore.project(coords, 'Equirectangular')).toEqual(coords);
  21. // },
  22. // ),
  23. // );
  24. [
  25. [0, 0] as [number, number],
  26. [45, 45] as [number, number],
  27. [90, 90] as [number, number],
  28. ]
  29. .forEach((coords) => {
  30. expect(orbisCore.project(coords, ['Equirectangular'])).toEqual(coords);
  31. });
  32. });
  33. it('returns coords for other projections', () => {
  34. // fc.assert(
  35. // fc.property(
  36. // fc.tuple(
  37. // fc.float().filter((c) => -180 <= c && c <= 180),
  38. // fc.float().filter((c) => -180 <= c && c <= 180),
  39. // ),
  40. // (coords) => {
  41. // expect(orbisCore.project(coords, 'Equirectangular')).toEqual(coords);
  42. // },
  43. // ),
  44. // );
  45. [
  46. [0, 0] as [number, number],
  47. [45, 45] as [number, number],
  48. [90, 90] as [number, number],
  49. ]
  50. .forEach((coords) => {
  51. expect(orbisCore.project(coords, ['Mercator'])).toEqual([
  52. expect.any(Number),
  53. expect.any(Number),
  54. ]);
  55. });
  56. });
  57. });
  58. });