-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug Fix: updatePatternPositions fix (#3339)
* updatePatternPositions fix * spelling * add testing * adjust comments; better typescript * jest fn; cleanup empty lines * add changelog * add changelog --------- Co-authored-by: Craig O'Connor <[email protected]>
- Loading branch information
1 parent
32cd9fe
commit 684b314
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import {Tile} from '../source/tile'; | ||
import {OverscaledTileID} from '../source/tile_id'; | ||
import {updatePatternPositionsInProgram} from './update_pattern_positions_in_program'; | ||
import {FillStyleLayer} from '../style/style_layer/fill_style_layer'; | ||
import type {CrossFaded} from '../style/properties'; | ||
import type {FillLayerSpecification, ResolvedImage} from '@maplibre/maplibre-gl-style-spec'; | ||
import type {ProgramConfiguration} from '../data/program_configuration'; | ||
import type {ImagePosition} from './image_atlas'; | ||
import type {Rect} from './glyph_atlas'; | ||
|
||
interface MockProgramConfiguration extends ProgramConfiguration { | ||
patternPositions: { | ||
posFrom: Rect; | ||
posTo: Rect; | ||
}; | ||
} | ||
|
||
function constructMockProgramConfiguration(): MockProgramConfiguration { | ||
const mockProgramConfiguration: MockProgramConfiguration = {patternPositions: {}} as any; | ||
mockProgramConfiguration.updatePaintBuffers = jest.fn(); | ||
mockProgramConfiguration.setConstantPatternPositions = (posFrom: ImagePosition, posTo: ImagePosition) => { | ||
// this does not exist on ProgramConfiguration but we want to test the resulting output | ||
mockProgramConfiguration.patternPositions = {posFrom: posFrom.paddedRect, posTo: posTo.paddedRect}; | ||
}; | ||
|
||
return mockProgramConfiguration; | ||
} | ||
|
||
function constructMockFillStyleLayer(): FillStyleLayer { | ||
const layerSpec = { | ||
id: 'mock-layer', | ||
source: 'empty-source', | ||
type: 'fill', | ||
layout: {}, | ||
'paint': { | ||
'fill-pattern': [ | ||
'step', | ||
['zoom'], | ||
'zoo_11', | ||
4, | ||
'volcano_11' | ||
] | ||
} | ||
} as FillLayerSpecification; | ||
const layer = new FillStyleLayer(layerSpec); | ||
return layer; | ||
} | ||
|
||
describe('updatePatternPositionsInProgram', () => { | ||
test('geojson tile', () => { | ||
const config = constructMockProgramConfiguration(); | ||
const tile = new Tile(new OverscaledTileID(3, 0, 2, 1, 2), undefined); | ||
tile.imageAtlas = {} as any; | ||
tile.imageAtlas.patternPositions = { | ||
'volcano_11': {paddedRect: {x: 0, y: 0, w: 0, h: 0}, version: 0, tl: [0, 0], pixelRatio: 1, br: [0, 0], tlbr: [0, 0, 0, 0], displaySize: [0, 0], stretchX: [], stretchY: [], content: [0, 0, 0, 0]}, | ||
}; | ||
const crossFadeResolveImage: CrossFaded<ResolvedImage> = { | ||
from: {name: 'zoo_11', available: false, toString: () => 'zoo_11'}, | ||
to: {name: 'volcano_11', available: false, toString: () => 'volcano_11'} | ||
}; | ||
updatePatternPositionsInProgram( | ||
config, | ||
'fill-pattern', | ||
crossFadeResolveImage, | ||
tile, | ||
constructMockFillStyleLayer() | ||
); | ||
// we added this property to just see what the update looks like | ||
expect(config.patternPositions).toEqual({ | ||
posFrom: {x: 0, y: 0, w: 0, h: 0}, | ||
posTo: {x: 0, y: 0, w: 0, h: 0} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters