Skip to content

Commit

Permalink
refacto(Crs): rename toUnit to getUnit
Browse files Browse the repository at this point in the history
BREAKING CHANGE: CRS.toUnit renamed to CRS.getUnit
  • Loading branch information
Desplandis committed Nov 27, 2024
1 parent 205c27f commit 2fdf15a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Core/Geographic/Crs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function unitFromProj4Unit(proj: ProjectionDefinition) {
* @param crs - The CRS to extract the unit from.
* @returns Either `UNIT.METER`, `UNIT.DEGREE` or `undefined`.
*/
export function toUnit(crs: ProjectionLike) {
export function getUnit(crs: ProjectionLike) {
mustBeString(crs);
const p = proj4.defs(formatToEPSG(crs));
if (!p) {
Expand All @@ -134,7 +134,7 @@ export function toUnit(crs: ProjectionLike) {
* @throws {@link Error} if the CRS is not valid.
*/
export function isMetricUnit(crs: ProjectionLike) {
return (toUnit(crs) == UNIT.METER);
return getUnit(crs) === UNIT.METER;
}

/**
Expand All @@ -144,7 +144,7 @@ export function isMetricUnit(crs: ProjectionLike) {
* @throws {@link Error} if the CRS is not valid.
*/
export function isGeographic(crs: ProjectionLike) {
return (toUnit(crs) == UNIT.DEGREE);
return getUnit(crs) === UNIT.DEGREE;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions test/unit/crs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('CRS assertions', function () {
});

it('should get the correct unit for this CRS', function () {
assert.strictEqual(CRS.toUnit('EPSG:4326'), CRS.UNIT.DEGREE);
assert.strictEqual(CRS.toUnit('EPSG:7133'), CRS.UNIT.DEGREE);
assert.strictEqual(CRS.toUnit('EPSG:4978'), CRS.UNIT.METER);
assert.strictEqual(CRS.toUnit('EPSG:3857'), CRS.UNIT.METER);
assert.strictEqual(CRS.toUnit('EPSG:INVALID'), undefined);
assert.strictEqual(CRS.getUnit('EPSG:4326'), CRS.UNIT.DEGREE);
assert.strictEqual(CRS.getUnit('EPSG:7133'), CRS.UNIT.DEGREE);
assert.strictEqual(CRS.getUnit('EPSG:4978'), CRS.UNIT.METER);
assert.strictEqual(CRS.getUnit('EPSG:3857'), CRS.UNIT.METER);
assert.strictEqual(CRS.getUnit('EPSG:INVALID'), undefined);
});

it('should check if the CRS is EPSG:4326', function () {
Expand Down

0 comments on commit 2fdf15a

Please sign in to comment.