-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Endpoint] Resolver nonlinear zoom #54936
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { maximum, minimum, zoomCurveRate } from './scaling_constants'; | ||
|
||
/** | ||
* Calculates the zoom factor (between 0 and 1) for a given scale value. | ||
*/ | ||
export const scaleToZoom = (scale: number): number => { | ||
const delta = maximum - minimum; | ||
return Math.pow((scale - minimum) / delta, 1 / zoomCurveRate); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/** | ||
* The minimum allowed value for the camera scale. This is the least scale that we will ever render something at. | ||
*/ | ||
export const minimum = 0.1; | ||
|
||
/** | ||
* The maximum allowed value for the camera scale. This is greatest scale that we will ever render something at. | ||
*/ | ||
export const maximum = 6; | ||
|
||
/** | ||
* The curve of the zoom function growth rate. The exponential rate the speed of zoom increases at the higher the scale is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uh huh There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. forgot a comma |
||
*/ | ||
export const zoomCurveRate = 4; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ import { cameraReducer } from './reducer'; | |
import { createStore, Store } from 'redux'; | ||
import { CameraState, AABB } from '../../types'; | ||
import { viewableBoundingBox, inverseProjectionMatrix } from './selectors'; | ||
import { userScaled, expectVectorsToBeClose } from './test_helpers'; | ||
import { expectVectorsToBeClose } from './test_helpers'; | ||
import { scaleToZoom } from './scale_to_zoom'; | ||
import { applyMatrix3 } from '../../lib/vector2'; | ||
|
||
describe('zooming', () => { | ||
|
@@ -43,7 +44,8 @@ describe('zooming', () => { | |
); | ||
describe('when the user has scaled in to 2x', () => { | ||
beforeEach(() => { | ||
userScaled(store, [2, 2]); | ||
const action: CameraAction = { type: 'userSetZoomLevel', payload: scaleToZoom(2) }; | ||
store.dispatch(action); | ||
}); | ||
it( | ||
...cameraShouldBeBoundBy({ | ||
|
@@ -52,20 +54,29 @@ describe('zooming', () => { | |
}) | ||
); | ||
}); | ||
describe('when the user zooms in by 1 zoom unit', () => { | ||
describe('when the user zooms in by 0.1 scaling factor', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this message matches the |
||
beforeEach(() => { | ||
const action: CameraAction = { | ||
type: 'userZoomed', | ||
payload: 1, | ||
}; | ||
store.dispatch(action); | ||
}); | ||
it( | ||
...cameraShouldBeBoundBy({ | ||
minimum: [-75, -50], | ||
maximum: [75, 50], | ||
}) | ||
); | ||
it('should zoom in a little bit', () => { | ||
const actual = viewableBoundingBox(store.getState()); | ||
expect(actual).toMatchInlineSnapshot(` | ||
Object { | ||
"maximum": Array [ | ||
25.000000000000007, | ||
16.666666666666668, | ||
], | ||
"minimum": Array [ | ||
-25, | ||
-16.666666666666668, | ||
], | ||
} | ||
`); | ||
}); | ||
}); | ||
it('the raster position 200, 50 should map to the world position 50, 50', () => { | ||
expectVectorsToBeClose(applyMatrix3([200, 50], inverseProjectionMatrix(store.getState())), [ | ||
|
@@ -126,7 +137,8 @@ describe('zooming', () => { | |
}); | ||
describe('when the user scales to 2x', () => { | ||
beforeEach(() => { | ||
userScaled(store, [2, 2]); | ||
const action: CameraAction = { type: 'userSetZoomLevel', payload: scaleToZoom(2) }; | ||
store.dispatch(action); | ||
}); | ||
it('should be centered on 100, 0', () => { | ||
const worldCenterPoint = applyMatrix3( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment wrong?