All files / src/app/touchpad/geography utils.ts

100% Statements 12/12
100% Branches 2/2
100% Functions 2/2
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98                                                                                                                                1x             1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                               1x  
/**
 * The interface for coordinates returned by the Geo Admin API.
 */
export interface GeoAdminCoordinates {
  type: string;
  coordinates: number[];
}
 
/**
 * The interface for the addresses returned by the GeoAdmin API.
 */
export interface Address {
  layerBodId: string;
  geometry: {
    spatialReference: {
      wkid: number;
    },
    x: number;
    y: number;
  };
  attributes: {
    deinr: string;
    strname1: string;
    gdename: string;
  };
}
 
/**
 * The interface for the water bodies returned by the Geo Admin API.
 */
export interface Waterbody {
  layerBodId: string;
  geometry: {
    paths: number[][][];
    spatialReference: number;
  };
  attributes: {
    name: string;
    label: string;
  };
}
 
/**
 * The interface for points returned by the Geo Admin API.
 */
export interface GeoAdminPoint {
  attrs: {
    origin: string;
    lat: number;
    lon: number;
    x: number;
    y: number;
  };
}
 
/**
 * Compute the squared euclidean distance between two points.
 *
 * @param pointA A point with x, y coordinates for which the distance must be computed.
 * @param pointB A second point with x, y coordinates for which the distance must be computed.
 *
 * @returns The squared euclidean distance between points A and B.
 */
export function squaredEuclideanDistance(pointA: {x: number, y: number}, pointB: {x: number, y: number}): number {
  return Math.pow(pointA.x - pointB.x, 2) + Math.pow(pointA.y - pointB.y, 2);
}
 
/**
 * The possible directions to locate a point on a map
 * (to go from one point to another).
 */
export enum Direction {
  UP = 'up',
  DOWN = 'down',
  LEFT = 'left',
  RIGHT = 'right',
  UP_LEFT = 'up-left',
  UP_RIGHT = 'up-right',
  DOWN_LEFT = 'down-left',
  DOWN_RIGHT = 'down-right',
  CENTER = 'center'
}
 
/**
 * The interface for directions from a point to another on a map.
 */
export interface MapDirections {
  reached: boolean;
  direction?: Direction;
  distance?: number;
  unit?: 'meters' | 'kilometers';
}
 
/**
 * The number of meters below which it is considered that a point has been reached on a map.
 */
export const metersPrecision = 10;