Skip to content

Commit 72bf603

Browse files
authored
Tweak - Use strings instead of strings parsed to projection arrays (#902)
1 parent 6ac2725 commit 72bf603

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

src/expression/definitions/coercion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {BooleanType, ColorType, NumberType, StringType, ValueType} from '../types';
2-
import {Color, Padding, VariableAnchorOffsetCollection, toString as valueToString, validateRGBA, Projection} from '../values';
2+
import {Color, Padding, VariableAnchorOffsetCollection, toString as valueToString, validateRGBA} from '../values';
33
import RuntimeError from '../runtime_error';
44
import Formatted from '../types/formatted';
55
import ResolvedImage from '../types/resolved_image';
@@ -124,7 +124,7 @@ class Coercion implements Expression {
124124
case 'resolvedImage':
125125
return ResolvedImage.fromString(valueToString(this.args[0].evaluate(ctx)));
126126
case 'projection':
127-
return Projection.parse(this.args[0].evaluate(ctx));
127+
return this.args[0].evaluate(ctx);
128128
default:
129129
return valueToString(this.args[0].evaluate(ctx));
130130
}

src/expression/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ export function normalizePropertyExpression<T>(
392392
} else if (specification.type === 'variableAnchorOffsetCollection' && Array.isArray(value)) {
393393
constant = VariableAnchorOffsetCollection.parse(value as VariableAnchorOffsetCollectionSpecification);
394394
} else if (specification.type === 'projection' && typeof value === 'string') {
395-
constant = Projection.parse(value);
395+
constant = value;
396396
}
397397
return {
398398
kind: 'constant',

src/util/interpolate.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('interpolate', () => {
119119
});
120120

121121
test('interpolate projection', () => {
122-
const i11nFn = (t: number) => interpolate.projection(Projection.parse('vertical-perspective'), Projection.parse('mercator'), t);
122+
const i11nFn = (t: number) => interpolate.projection('vertical-perspective', 'mercator', t);
123123
expect(i11nFn(0.5)).toBeInstanceOf(Projection);
124124
expect(`${i11nFn(0.5)}`).toBe('["vertical-perspective", "mercator", 0.5]');
125125
});

src/util/interpolate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function number(from: number, to: number, t: number): number {
3939
return from + t * (to - from);
4040
}
4141

42-
function projection(from: Projection, to: Projection, interpolation: number): Projection {
43-
return new Projection(from.from, to.to, interpolation);
42+
function projection(from: string, to: string, interpolation: number): Projection {
43+
return new Projection(from, to, interpolation);
4444
}
4545

4646
function color(from: Color, to: Color, t: number, spaceKey: InterpolationColorSpace = 'rgb'): Color {

test/integration/expression/tests/interpolate-projection/higher-than-stop/test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"type": "projection"
3939
},
4040
"outputs": [
41-
["mercator", "mercator", 1]
41+
"mercator"
4242
]
4343
}
4444
}

test/integration/expression/tests/interpolate-projection/lower-than-stop/test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"type": "projection"
3939
},
4040
"outputs": [
41-
["vertical-perspective", "vertical-perspective", 1]
41+
"vertical-perspective"
4242
]
4343
}
4444
}

test/integration/expression/tests/zoom/interpolate-projection/test.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"zoom"
1919
],
2020
0,
21-
["literal", ["vertical-perspective", "vertical-perspective", 1]],
21+
"vertical-perspective",
2222
10,
23-
["literal", ["mercator", "mercator", 1]]
23+
"mercator"
2424
],
2525
"inputs": [
2626
[

0 commit comments

Comments
 (0)