Skip to content

Commit 0dcdd7f

Browse files
committed
projectionTransition
1 parent 946fce8 commit 0dcdd7f

File tree

8 files changed

+41
-41
lines changed

8 files changed

+41
-41
lines changed

build/generate-style-spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ fs.writeFileSync('src/types.g.ts',
126126
127127
export type ColorSpecification = string;
128128
129-
export type ProjectionPreset = ${projectionTypes.presets.map(p => `'${p}'`).join(' | ')};
130-
export type ProjectionPrimitive = ${projectionTypes.projections.map(p => `'${p}'`).join(' | ')};
131-
export type ProjectionTransition = [ProjectionPrimitive, ProjectionPrimitive, number];
132-
export type ProjectionTransitionSpecification = ProjectionPreset | ProjectionPrimitive | ProjectionTransition | PropertyValueSpecification<ProjectionTransition>
129+
export type ProjectionPresetT = ${projectionTypes.presets.map(p => `'${p}'`).join(' | ')};
130+
export type ProjectionPrimitiveT = ${projectionTypes.projections.map(p => `'${p}'`).join(' | ')};
131+
export type ProjectionTransitionT = [ProjectionPrimitiveT, ProjectionPrimitiveT, number];
132+
export type ProjectionTransitionSpecification = ProjectionPresetT | ProjectionPrimitiveT | ProjectionTransitionT | PropertyValueSpecification<ProjectionTransitionT>
133133
134134
135135
export type PaddingSpecification = number | number[];
@@ -214,7 +214,7 @@ export type ExpressionSpecification =
214214
| ['interpolate', InterpolationSpecification, number | ExpressionSpecification,
215215
...(number | number[] | ColorSpecification | ExpressionSpecification)[]] // alternating number and number | number[] | ColorSpecification
216216
| ['interpolate-projection', InterpolationSpecification, number | ExpressionSpecification,
217-
...(number | ProjectionPrimitive)[]] // alternating Projection
217+
...(number | ProjectionPrimitiveT)[]] // alternating Projection
218218
| ['interpolate-hcl', InterpolationSpecification, number | ExpressionSpecification,
219219
...(number | ColorSpecification)[]] // alternating number and ColorSpecificaton
220220
| ['interpolate-lab', InterpolationSpecification, number | ExpressionSpecification,

src/expression/definitions/interpolate.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UnitBezier from '@mapbox/unitbezier';
22

33
import interpolate from '../../util/interpolate';
4-
import {array, ArrayType, ColorType, ProjectionTransitionT, ColorTypeT, NumberType, NumberTypeT, PaddingType, PaddingTypeT, VariableAnchorOffsetCollectionType, VariableAnchorOffsetCollectionTypeT, toString, verifyType, ProjectionTransition} from '../types';
4+
import {array, ArrayType, ColorType, ProjectionTransitionTypeT, ColorTypeT, NumberType, NumberTypeT, PaddingType, PaddingTypeT, VariableAnchorOffsetCollectionType, VariableAnchorOffsetCollectionTypeT, toString, verifyType, ProjectionTransitionType} from '../types';
55
import {findStopLessThanOrEqualTo} from '../stops';
66

77
import type {Stops} from '../stops';
@@ -19,7 +19,7 @@ export type InterpolationType = {
1919
name: 'cubic-bezier';
2020
controlPoints: [number, number, number, number];
2121
};
22-
type InterpolatedValueType = NumberTypeT | ColorTypeT | ProjectionTransitionT | PaddingTypeT | VariableAnchorOffsetCollectionTypeT | ArrayType<NumberTypeT>;
22+
type InterpolatedValueType = NumberTypeT | ColorTypeT | ProjectionTransitionTypeT | PaddingTypeT | VariableAnchorOffsetCollectionTypeT | ArrayType<NumberTypeT>;
2323
type InterpolationOperator = 'interpolate' | 'interpolate-hcl' | 'interpolate-lab' | 'interpolate-projection';
2424
class Interpolate implements Expression {
2525
type: InterpolatedValueType;
@@ -109,7 +109,7 @@ class Interpolate implements Expression {
109109
if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') {
110110
outputType = ColorType;
111111
} else if (operator === 'interpolate-projection') {
112-
outputType = ProjectionTransition;
112+
outputType = ProjectionTransitionType;
113113
} else if (context.expectedType && context.expectedType.kind !== 'value') {
114114
outputType = context.expectedType;
115115
}
@@ -137,7 +137,7 @@ class Interpolate implements Expression {
137137

138138
if (!verifyType(outputType, NumberType) &&
139139
!verifyType(outputType, ColorType) &&
140-
!verifyType(outputType, ProjectionTransition) &&
140+
!verifyType(outputType, ProjectionTransitionType) &&
141141
!verifyType(outputType, PaddingType) &&
142142
!verifyType(outputType, VariableAnchorOffsetCollectionType) &&
143143
!verifyType(outputType, array(NumberType))
@@ -174,7 +174,7 @@ class Interpolate implements Expression {
174174
const outputLower = outputs[index].evaluate(ctx);
175175
const outputUpper = outputs[index + 1].evaluate(ctx);
176176

177-
if (this.type.kind === 'projection') {
177+
if (this.type.kind === 'projectionTransition') {
178178
return interpolate.projection(outputLower, outputUpper, t);
179179
}
180180

src/expression/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export type BooleanTypeT = {
1313
export type ColorTypeT = {
1414
kind: 'color';
1515
};
16-
export type ProjectionTransitionT = {
17-
kind: 'projection';
16+
export type ProjectionTransitionTypeT = {
17+
kind: 'projectionTransition';
1818
};
1919
export type ObjectTypeT = {
2020
kind: 'object';
@@ -43,7 +43,7 @@ export type VariableAnchorOffsetCollectionTypeT = {
4343

4444
export type EvaluationKind = 'constant' | 'source' | 'camera' | 'composite';
4545

46-
export type Type = NullTypeT | NumberTypeT | StringTypeT | BooleanTypeT | ColorTypeT | ProjectionTransitionT | ObjectTypeT | ValueTypeT |
46+
export type Type = NullTypeT | NumberTypeT | StringTypeT | BooleanTypeT | ColorTypeT | ProjectionTransitionTypeT | ObjectTypeT | ValueTypeT |
4747
ArrayType | ErrorTypeT | CollatorTypeT | FormattedTypeT | PaddingTypeT | ResolvedImageTypeT | VariableAnchorOffsetCollectionTypeT;
4848

4949
export interface ArrayType<T extends Type = Type> {
@@ -59,7 +59,7 @@ export const NumberType = {kind: 'number'} as NumberTypeT;
5959
export const StringType = {kind: 'string'} as StringTypeT;
6060
export const BooleanType = {kind: 'boolean'} as BooleanTypeT;
6161
export const ColorType = {kind: 'color'} as ColorTypeT;
62-
export const ProjectionTransition = {kind: 'projection'} as ProjectionTransitionT;
62+
export const ProjectionTransitionType = {kind: 'projectionTransition'} as ProjectionTransitionTypeT;
6363
export const ObjectType = {kind: 'object'} as ObjectTypeT;
6464
export const ValueType = {kind: 'value'} as ValueTypeT;
6565
export const ErrorType = {kind: 'error'} as ErrorTypeT;
@@ -94,7 +94,7 @@ const valueMemberTypes = [
9494
StringType,
9595
BooleanType,
9696
ColorType,
97-
ProjectionTransition,
97+
ProjectionTransitionType,
9898
FormattedType,
9999
ObjectType,
100100
array(ValueType),

src/expression/values.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import Formatted from './types/formatted';
55
import Padding from '../util/padding';
66
import VariableAnchorOffsetCollection from '../util/variable_anchor_offset_collection';
77
import ResolvedImage from './types/resolved_image';
8-
import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array, PaddingType, VariableAnchorOffsetCollectionType, ProjectionTransition} from './types';
8+
import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array, PaddingType, VariableAnchorOffsetCollectionType, ProjectionTransitionType} from './types';
99

1010
import type {Type} from './types';
11-
import {Projection} from '../util/projection';
11+
import {ProjectionTransition} from '../util/projection';
1212

1313
export function validateRGBA(r: unknown, g: unknown, b: unknown, a?: unknown): string | null {
1414
if (!(
@@ -29,7 +29,7 @@ export function validateRGBA(r: unknown, g: unknown, b: unknown, a?: unknown): s
2929
return null;
3030
}
3131

32-
export type Value = null | string | boolean | number | Color | Projection | Collator | Formatted | Padding | ResolvedImage | VariableAnchorOffsetCollection | ReadonlyArray<Value> | {
32+
export type Value = null | string | boolean | number | Color | ProjectionTransition | Collator | Formatted | Padding | ResolvedImage | VariableAnchorOffsetCollection | ReadonlyArray<Value> | {
3333
readonly [x: string]: Value;
3434
};
3535

@@ -38,7 +38,7 @@ export function isValue(mixed: unknown): boolean {
3838
typeof mixed === 'string' ||
3939
typeof mixed === 'boolean' ||
4040
typeof mixed === 'number' ||
41-
mixed instanceof Projection ||
41+
mixed instanceof ProjectionTransition ||
4242
mixed instanceof Color ||
4343
mixed instanceof Collator ||
4444
mixed instanceof Formatted ||
@@ -76,8 +76,8 @@ export function typeOf(value: Value): Type {
7676
return NumberType;
7777
} else if (value instanceof Color) {
7878
return ColorType;
79-
} else if (value instanceof Projection) {
80-
return ProjectionTransition;
79+
} else if (value instanceof ProjectionTransition) {
80+
return ProjectionTransitionType;
8181
} else if (value instanceof Collator) {
8282
return CollatorType;
8383
} else if (value instanceof Formatted) {
@@ -116,11 +116,11 @@ export function toString(value: Value) {
116116
return '';
117117
} else if (type === 'string' || type === 'number' || type === 'boolean') {
118118
return String(value);
119-
} else if (value instanceof Color || value instanceof Projection || value instanceof Formatted || value instanceof Padding || value instanceof VariableAnchorOffsetCollection || value instanceof ResolvedImage) {
119+
} else if (value instanceof Color || value instanceof ProjectionTransition || value instanceof Formatted || value instanceof Padding || value instanceof VariableAnchorOffsetCollection || value instanceof ResolvedImage) {
120120
return value.toString();
121121
} else {
122122
return JSON.stringify(value);
123123
}
124124
}
125125

126-
export {Color, Collator, Projection, Padding, VariableAnchorOffsetCollection};
126+
export {Color, Collator, ProjectionTransition as Projection, Padding, VariableAnchorOffsetCollection};

src/util/interpolate.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import interpolate, {isSupportedInterpolationColorSpace} from './interpolate';
33
import Color from './color';
44
import Padding from './padding';
55
import VariableAnchorOffsetCollection from './variable_anchor_offset_collection';
6-
import {Projection} from './projection';
6+
import {ProjectionTransition} from './projection';
77

88
describe('interpolate', () => {
99

@@ -120,7 +120,7 @@ describe('interpolate', () => {
120120

121121
test('interpolate projection', () => {
122122
const i11nFn = (t: number) => interpolate.projection('stereographic', 'mercator', t);
123-
expect(i11nFn(0.5)).toBeInstanceOf(Projection);
123+
expect(i11nFn(0.5)).toBeInstanceOf(ProjectionTransition);
124124
expect(`${i11nFn(0.5)}`).toBe('["stereographic", "mercator", 0.5]');
125125
});
126126

src/util/interpolate.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import Color from './color';
33
import Padding from './padding';
44
import VariableAnchorOffsetCollection from './variable_anchor_offset_collection';
55
import RuntimeError from '../expression/runtime_error';
6-
import type {ProjectionPrimitive, VariableAnchorOffsetCollectionSpecification} from '../types.g';
7-
import {Projection} from './projection';
6+
import type {ProjectionPrimitiveT, VariableAnchorOffsetCollectionSpecification} from '../types.g';
7+
import {ProjectionTransition} from './projection';
88

99
export type InterpolationColorSpace = 'rgb' | 'hcl' | 'lab';
1010

@@ -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: ProjectionPrimitive, to: ProjectionPrimitive, interpolation: number): Projection {
43-
return new Projection(from, to, interpolation);
42+
function projection(from: ProjectionPrimitiveT, to: ProjectionPrimitiveT, interpolation: number): ProjectionTransition {
43+
return new ProjectionTransition(from, to, interpolation);
4444
}
4545

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

src/util/projection.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {Projection} from './projection';
1+
import {ProjectionTransition} from './projection';
22

33
describe('Projection class', () => {
44

55
test('should serialize to rgba format', () => {
6-
expect(`${new Projection('mercator', 'stereographic', 1)}`).toBe('["mercator", "stereographic", 1]');
7-
expect(`${new Projection('stereographic', 'mercator', 0.3)}`).toBe('["stereographic", "mercator", 0.3]');
6+
expect(`${new ProjectionTransition('mercator', 'stereographic', 1)}`).toBe('["mercator", "stereographic", 1]');
7+
expect(`${new ProjectionTransition('stereographic', 'mercator', 0.3)}`).toBe('["stereographic", "mercator", 0.3]');
88
});
99
});

src/util/projection.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import v8 from '../reference/v8.json' with { type: 'json' };
2-
import {ProjectionPrimitive, ProjectionTransition, ProjectionTransitionSpecification, PropertyValueSpecification} from '../types.g';
2+
import {ProjectionPrimitiveT, ProjectionTransitionT, ProjectionTransitionSpecification, PropertyValueSpecification} from '../types.g';
33

4-
export class Projection {
5-
readonly from: ProjectionPrimitive;
6-
readonly to: ProjectionPrimitive;
4+
export class ProjectionTransition {
5+
readonly from: ProjectionPrimitiveT;
6+
readonly to: ProjectionPrimitiveT;
77
readonly transition: number;
8-
constructor(from: ProjectionPrimitive, to: ProjectionPrimitive, transition: number){
8+
constructor(from: ProjectionPrimitiveT, to: ProjectionPrimitiveT, transition: number){
99
this.from = from;
1010
this.to = to;
1111
this.transition = transition;
@@ -20,26 +20,26 @@ export function isProjectionTransitionConfig(value: unknown): value is Projectio
2020
return isProjectionPrimitive(value) || isProjectionTransitionValue(value) || isPropertyValueSpecification(value);
2121
}
2222

23-
export function isPropertyValueSpecification(value: unknown): value is PropertyValueSpecification<ProjectionTransition> {
23+
export function isPropertyValueSpecification(value: unknown): value is PropertyValueSpecification<ProjectionTransitionT> {
2424

2525
if (['interpolate-projection', 'step', 'literal'].includes(value[0])) {
2626
return true
2727
}
2828
return false
2929
}
3030

31-
export function isProjectionTransitionValue(value: unknown): value is ProjectionTransition {
31+
export function isProjectionTransitionValue(value: unknown): value is ProjectionTransitionT {
3232
return Array.isArray(value) &&
3333
value.length === 3 &&
3434
isProjectionPrimitive(value[0]) &&
3535
isProjectionPrimitive(value[1]) &&
3636
typeof value[2] === 'number';
3737
}
3838

39-
export function isProjectionPrimitive(value: unknown): value is ProjectionPrimitive {
39+
export function isProjectionPrimitive(value: unknown): value is ProjectionPrimitiveT {
4040
return v8.projection.type.values.projections.includes(value as string);
4141
}
4242

43-
export function isProjectionPreset(value: unknown): value is ProjectionPrimitive {
43+
export function isProjectionPreset(value: unknown): value is ProjectionPrimitiveT {
4444
return v8.projection.type.values.presets.includes(value as string);
4545
}

0 commit comments

Comments
 (0)