Skip to content

Commit

Permalink
changes zoom calculation to be exponential
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Jan 14, 2020
1 parent e8f24ba commit c816ff8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Store, createStore } from 'redux';
import { CameraAction } from './action';
import { CameraState } from '../../types';
import { cameraReducer } from './reducer';
import { projectionMatrix, scale } from './selectors';
import { projectionMatrix } from './selectors';
import { applyMatrix3 } from '../../lib/vector2';
import { scaleToZoom } from './scale_to_zoom';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { maximum, minimum } from './scaling_constants';
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 (scale - minimum) / delta;
return Math.pow((scale - minimum) / delta, 1 / zoomCurveRate);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* 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.
*/
Expand All @@ -6,4 +12,9 @@ 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;
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
*/
export const zoomCurveRate = 4;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
orthographicProjection,
translationTransformation,
} from '../../lib/transformation';
import { maximum, minimum } from './scaling_constants';
import { maximum, minimum, zoomCurveRate } from './scaling_constants';

interface ClippingPlanes {
renderWidth: number;
Expand Down Expand Up @@ -178,7 +178,7 @@ export const inverseProjectionMatrix: (state: CameraState) => Matrix3 = state =>
*/
export const scale = (state: CameraState): Vector2 => {
const delta = maximum - minimum;
const value = state.scalingFactor * delta + minimum;
const value = Math.pow(state.scalingFactor, zoomCurveRate) * delta + minimum;
return [value, value];
};

Expand Down

0 comments on commit c816ff8

Please sign in to comment.