• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visgl / loaders.gl / 24153816851

08 Apr 2026 07:17PM UTC coverage: 53.247% (-12.1%) from 65.319%
24153816851

push

github

web-flow
chore: Move from tape to vitest (#3351)

8651 of 17291 branches covered (50.03%)

Branch coverage included in aggregate %.

7 of 7 new or added lines in 1 file covered. (100.0%)

2031 existing lines in 296 files now uncovered.

17563 of 31940 relevant lines covered (54.99%)

5279.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.87
/modules/gis/src/lib/binary-geometry-api/transform-coordinates.ts
1
import type {BinaryFeatureCollection, BinaryGeometry, Feature} from '@loaders.gl/schema';
2

3
type TransformCoordinate = (coord: number[]) => number[];
4

5
/**
6
 * Apply transformation to every coordinate of binary features
7
 * @param  binaryFeatures binary features
8
 * @param  transformCoordinate Function to call on each coordinate
9
 * @return Transformed binary features
10
 */
11
export function transformBinaryCoords(
12
  binaryFeatures: BinaryFeatureCollection,
13
  transformCoordinate: TransformCoordinate
14
): BinaryFeatureCollection {
15
  if (binaryFeatures.points) {
1!
16
    transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);
1✔
17
  }
18
  if (binaryFeatures.lines) {
1!
19
    transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);
×
20
  }
21
  if (binaryFeatures.polygons) {
1!
UNCOV
22
    transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);
×
23
  }
24
  return binaryFeatures;
1✔
25
}
26

27
/** Transform one binary geometry */
28
function transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: TransformCoordinate) {
29
  const {positions} = binaryGeometry;
1✔
30
  for (let i = 0; i < positions.value.length; i += positions.size) {
1✔
31
    // @ts-ignore inclusion of bigint causes problems
32
    const coord: Array<number> = Array.from(positions.value.subarray(i, i + positions.size));
1✔
33
    const transformedCoord = fn(coord);
1✔
34
    // @ts-ignore typescript typing for .set seems to require bigint?
35
    positions.value.set(transformedCoord, i);
1✔
36
  }
37
}
38

39
/**
40
 * Apply transformation to every coordinate of GeoJSON features
41
 * @param  features Array of GeoJSON features
42
 * @param  fn       Function to call on each coordinate
43
 * @return          Transformed GeoJSON features
44
 */
45
export function transformGeoJsonCoords(
46
  features: Feature[],
47
  fn: (coord: number[]) => number[]
48
): Feature[] {
49
  for (const feature of features) {
3✔
50
    // @ts-ignore
51
    feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);
11✔
52
  }
53
  return features;
3✔
54
}
55

56
function coordMap(array: unknown, fn: (coord: number[]) => number[]): unknown[] {
57
  if (isCoord(array)) {
183✔
58
    return fn(array as number[]);
182✔
59
  }
60

61
  return (array as unknown[]).map(item => {
1✔
62
    return coordMap(item, fn);
172✔
63
  });
64
}
65

66
function isCoord(array: unknown) {
67
  return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);
183✔
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc