-
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] Adding a Resolver component that lets the user click and drag to pan and pinch to zoom #53619
[Endpoint] Adding a Resolver component that lets the user click and drag to pan and pinch to zoom #53619
Changes from all commits
ccf0621
c88400c
a07d0fd
b0203ae
3e530e6
e052cd9
f2d6416
83bf9e5
84474e3
6280558
0484291
dadcb6d
2caea42
1a193a9
138fe88
c54ed96
d3c8b1d
1638551
661c726
27aca81
e7323cf
6cd3580
f4326ac
9736f6b
b314ddb
0fb78a2
1fa6edb
5157b2d
73b08da
4b381f5
d753158
183528a
1dc6683
e007b38
59703e6
5673312
750369c
b074f7b
daddda4
bc5d15f
4669d77
0a1df7d
52f79c6
f87e2b4
5863434
b2950c2
6c500e3
9eca46e
f7c66d4
b153b8c
71399aa
48df3c3
d163e1a
1dc1e18
ae4b9e7
72d575b
bfd2284
6ed3110
df21333
827bba8
8340ccd
5980c39
b6da356
8347749
f9ac348
feaf213
a438da6
261e0f1
3d89e00
ee2b076
7b241ae
bc26420
b2d8d5b
bc840fc
2ae6307
d78c475
5f37888
5112ed7
1ebcddc
1fef3b7
679fa35
57fa7f9
2462aa2
015c110
ce7880b
b5df646
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,14 @@ | ||
{ | ||
"author": "Elastic", | ||
"name": "endpoint", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "Elastic-License", | ||
"scripts": {}, | ||
"dependencies": { | ||
"react-redux": "^7.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react-redux": "^7.1.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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. | ||
*/ | ||
import { CameraAction } from './store/camera'; | ||
import { DataAction } from './store/data'; | ||
|
||
export type ResolverAction = CameraAction | DataAction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Return `value` unless it is less than `minimum`, in which case return `minimum` or unless it is greater than `maximum`, in which case return `maximum`. | ||
*/ | ||
export function clamp(value: number, minimum: number, maximum: number) { | ||
return Math.max(Math.min(value, maximum), minimum); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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 { multiply } from './matrix3'; | ||
describe('matrix3', () => { | ||
it('can multiply two matrix3s', () => { | ||
expect(multiply([1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16, 17, 18])).toEqual([ | ||
84, | ||
90, | ||
96, | ||
201, | ||
216, | ||
231, | ||
318, | ||
342, | ||
366, | ||
]); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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 { Matrix3 } from '../types'; | ||
|
||
/** | ||
* Return a new matrix which is the product of the first and second matrix. | ||
*/ | ||
export function multiply( | ||
[a11, a12, a13, a21, a22, a23, a31, a32, a33]: Matrix3, | ||
[b11, b12, b13, b21, b22, b23, b31, b32, b33]: Matrix3 | ||
): Matrix3 { | ||
const s11 = a11 * b11 + a12 * b21 + a13 * b31; | ||
const s12 = a11 * b12 + a12 * b22 + a13 * b32; | ||
const s13 = a11 * b13 + a12 * b23 + a13 * b33; | ||
|
||
const s21 = a21 * b11 + a22 * b21 + a23 * b31; | ||
const s22 = a21 * b12 + a22 * b22 + a23 * b32; | ||
const s23 = a21 * b13 + a22 * b23 + a23 * b33; | ||
|
||
const s31 = a31 * b11 + a32 * b21 + a33 * b31; | ||
const s32 = a31 * b12 + a32 * b22 + a33 * b32; | ||
const s33 = a31 * b13 + a32 * b23 + a33 * b33; | ||
|
||
// prettier-ignore | ||
return [ | ||
s11, s12, s13, | ||
s21, s22, s23, | ||
s31, s32, s33, | ||
]; | ||
} | ||
|
||
/** | ||
* Return a new matrix which is the sum of the two passed in. | ||
*/ | ||
export function add( | ||
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. Since all of these seem to have name collisions between matrix v. vector addition, multiplication, etc. wondering if it makes sense to nest this export under some sort of class or named constant. Just want to avoid littering code with things like:
as well as having to back reference whether we're operating on matrices, vectors, lists, etc. because we've lost all context of what 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. |
||
[a11, a12, a13, a21, a22, a23, a31, a32, a33]: Matrix3, | ||
[b11, b12, b13, b21, b22, b23, b31, b32, b33]: Matrix3 | ||
): Matrix3 { | ||
return [ | ||
a11 + b11, | ||
a12 + b12, | ||
a13 + b13, | ||
|
||
a21 + b21, | ||
a22 + b22, | ||
a23 + b23, | ||
|
||
a31 + b31, | ||
a32 + b32, | ||
a33 + b33, | ||
]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* 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 { applyMatrix3 } from './vector2'; | ||
import { scalingTransformation } from './transformation'; | ||
|
||
describe('transforms', () => { | ||
it('applying a scale matrix to a vector2 can invert the y value', () => { | ||
expect(applyMatrix3([1, 2], scalingTransformation([1, -1]))).toEqual([1, -2]); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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 { Matrix3, Vector2 } from '../types'; | ||
|
||
/** | ||
* The inverse of `orthographicProjection`. | ||
*/ | ||
export function inverseOrthographicProjection( | ||
top: number, | ||
right: number, | ||
bottom: number, | ||
left: number | ||
): Matrix3 { | ||
const m11 = (right - left) / 2; | ||
const m13 = (right + left) / (right - left); | ||
|
||
const m22 = (top - bottom) / 2; | ||
const m23 = (top + bottom) / (top - bottom); | ||
|
||
return [m11, 0, m13, 0, m22, m23, 0, 0, 0]; | ||
} | ||
|
||
/** | ||
* Adjust x, y to be bounded, in scale, of a clipping plane defined by top, right, bottom, left. | ||
* | ||
* See explanation: | ||
* https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix | ||
* https://en.wikipedia.org/wiki/Orthographic_projection | ||
*/ | ||
export function orthographicProjection( | ||
top: number, | ||
right: number, | ||
bottom: number, | ||
left: number | ||
): Matrix3 { | ||
const m11 = 2 / (right - left); // adjust x scale to match ndc (-1, 1) bounds | ||
const m13 = -((right + left) / (right - left)); | ||
|
||
const m22 = 2 / (top - bottom); // adjust y scale to match ndc (-1, 1) bounds | ||
const m23 = -((top + bottom) / (top - bottom)); | ||
|
||
return [m11, 0, m13, 0, m22, m23, 0, 0, 0]; | ||
} | ||
|
||
/** | ||
* Returns a 2D transformation matrix that when applied to a vector will scale the vector by `x` and `y` in their respective axises. | ||
* See https://en.wikipedia.org/wiki/Scaling_(geometry)#Matrix_representation | ||
*/ | ||
export function scalingTransformation([x, y]: Vector2): Matrix3 { | ||
// prettier-ignore | ||
return [ | ||
x, 0, 0, | ||
0, y, 0, | ||
0, 0, 0 | ||
] | ||
} | ||
|
||
/** | ||
* Returns a 2D transformation matrix that when applied to a vector will translate by `x` and `y` in their respective axises. | ||
* See https://en.wikipedia.org/wiki/Translation_(geometry)#Matrix_representation | ||
*/ | ||
export function translationTransformation([x, y]: Vector2): Matrix3 { | ||
// prettier-ignore | ||
return [ | ||
1, 0, x, | ||
0, 1, y, | ||
0, 0, 1 | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Sequences a tree, yielding children returned by the `children` function. Sequencing is done in 'depth first preorder' fashion. See https://en.wikipedia.org/wiki/Tree_traversal#Pre-order_(NLR) | ||
*/ | ||
export function* depthFirstPreorder<T>(root: T, children: (parent: T) => T[]): Iterable<T> { | ||
const nodesToVisit = [root]; | ||
while (nodesToVisit.length !== 0) { | ||
const currentNode = nodesToVisit.shift(); | ||
if (currentNode !== undefined) { | ||
nodesToVisit.unshift(...(children(currentNode) || [])); | ||
yield currentNode; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Sequences a tree, yielding children returned by the `children` function. Sequencing is done in 'level order' fashion. | ||
*/ | ||
export function* levelOrder<T>(root: T, children: (parent: T) => T[]): Iterable<T> { | ||
let level = [root]; | ||
while (level.length !== 0) { | ||
let nextLevel = []; | ||
for (const node of level) { | ||
yield node; | ||
nextLevel.push(...(children(node) || [])); | ||
} | ||
level = nextLevel; | ||
nextLevel = []; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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 { Vector2, Matrix3 } from '../types'; | ||
|
||
/** | ||
* Returns a vector which is the sum of `a` and `b`. | ||
*/ | ||
export function add(a: Vector2, b: Vector2): Vector2 { | ||
return [a[0] + b[0], a[1] + b[1]]; | ||
} | ||
|
||
/** | ||
* Returns a vector which is the difference of `a` and `b`. | ||
*/ | ||
export function subtract(a: Vector2, b: Vector2): Vector2 { | ||
return [a[0] - b[0], a[1] - b[1]]; | ||
} | ||
|
||
/** | ||
* Returns a vector which is the quotient of `a` and `b`. | ||
*/ | ||
export function divide(a: Vector2, b: Vector2): Vector2 { | ||
return [a[0] / b[0], a[1] / b[1]]; | ||
} | ||
|
||
/** | ||
* Returns a vector which is the result of applying a 2D transformation matrix to the provided vector. | ||
*/ | ||
export function applyMatrix3([x, y]: Vector2, [m11, m12, m13, m21, m22, m23]: Matrix3): Vector2 { | ||
return [x * m11 + y * m12 + m13, x * m21 + y * m22 + m23]; | ||
} | ||
|
||
/** | ||
* Returns the distance between two vectors | ||
*/ | ||
export function distance(a: Vector2, b: Vector2) { | ||
const [x1, y1] = a; | ||
const [x2, y2] = b; | ||
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)); | ||
} | ||
|
||
/** | ||
* Returns the angle between two vectors | ||
*/ | ||
export function angle(a: Vector2, b: Vector2) { | ||
const deltaX = b[0] - a[0]; | ||
const deltaY = b[1] - a[1]; | ||
return Math.atan2(deltaY, deltaX); | ||
} |
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.
We depend on react-redux's hooks.