From 39894cf1e7f4ff52805c936d3e8fa9a9139317da Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 29 Jun 2020 14:45:03 -0400 Subject: [PATCH 1/3] Move AABB, Matrix3, and Vector2 modules from lib to models --- .../public/resolver/lib/transformation.test.ts | 2 +- .../security_solution/public/resolver/{lib => models}/aabb.ts | 0 .../models/indexed_process_tree/isometric_taxi_layout.ts | 2 +- .../public/resolver/{lib => models}/matrix3.test.ts | 0 .../public/resolver/{lib => models}/matrix3.ts | 0 .../public/resolver/{lib => models}/vector2.ts | 0 .../resolver/store/camera/inverse_projection_matrix.test.ts | 2 +- .../security_solution/public/resolver/store/camera/methods.ts | 2 +- .../public/resolver/store/camera/projection_matrix.test.ts | 2 +- .../security_solution/public/resolver/store/camera/reducer.ts | 2 +- .../public/resolver/store/camera/selectors.ts | 4 ++-- .../public/resolver/store/camera/zooming.test.ts | 2 +- .../security_solution/public/resolver/store/data/selectors.ts | 2 +- .../security_solution/public/resolver/view/edge_line.tsx | 2 +- .../public/resolver/view/process_event_dot.tsx | 2 +- .../public/resolver/view/use_camera.test.tsx | 2 +- 16 files changed, 13 insertions(+), 13 deletions(-) rename x-pack/plugins/security_solution/public/resolver/{lib => models}/aabb.ts (100%) rename x-pack/plugins/security_solution/public/resolver/{lib => models}/matrix3.test.ts (100%) rename x-pack/plugins/security_solution/public/resolver/{lib => models}/matrix3.ts (100%) rename x-pack/plugins/security_solution/public/resolver/{lib => models}/vector2.ts (100%) diff --git a/x-pack/plugins/security_solution/public/resolver/lib/transformation.test.ts b/x-pack/plugins/security_solution/public/resolver/lib/transformation.test.ts index 3fe6941279bc5..3280bad4a81ff 100644 --- a/x-pack/plugins/security_solution/public/resolver/lib/transformation.test.ts +++ b/x-pack/plugins/security_solution/public/resolver/lib/transformation.test.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { applyMatrix3 } from './vector2'; +import { applyMatrix3 } from '../models/vector2'; import { scalingTransformation } from './transformation'; describe('transforms', () => { diff --git a/x-pack/plugins/security_solution/public/resolver/lib/aabb.ts b/x-pack/plugins/security_solution/public/resolver/models/aabb.ts similarity index 100% rename from x-pack/plugins/security_solution/public/resolver/lib/aabb.ts rename to x-pack/plugins/security_solution/public/resolver/models/aabb.ts diff --git a/x-pack/plugins/security_solution/public/resolver/models/indexed_process_tree/isometric_taxi_layout.ts b/x-pack/plugins/security_solution/public/resolver/models/indexed_process_tree/isometric_taxi_layout.ts index 9095f061ee73a..61363ffa05d94 100644 --- a/x-pack/plugins/security_solution/public/resolver/models/indexed_process_tree/isometric_taxi_layout.ts +++ b/x-pack/plugins/security_solution/public/resolver/models/indexed_process_tree/isometric_taxi_layout.ts @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import * as vector2 from '../../lib/vector2'; +import * as vector2 from '../../models/vector2'; import { IndexedProcessTree, Vector2, diff --git a/x-pack/plugins/security_solution/public/resolver/lib/matrix3.test.ts b/x-pack/plugins/security_solution/public/resolver/models/matrix3.test.ts similarity index 100% rename from x-pack/plugins/security_solution/public/resolver/lib/matrix3.test.ts rename to x-pack/plugins/security_solution/public/resolver/models/matrix3.test.ts diff --git a/x-pack/plugins/security_solution/public/resolver/lib/matrix3.ts b/x-pack/plugins/security_solution/public/resolver/models/matrix3.ts similarity index 100% rename from x-pack/plugins/security_solution/public/resolver/lib/matrix3.ts rename to x-pack/plugins/security_solution/public/resolver/models/matrix3.ts diff --git a/x-pack/plugins/security_solution/public/resolver/lib/vector2.ts b/x-pack/plugins/security_solution/public/resolver/models/vector2.ts similarity index 100% rename from x-pack/plugins/security_solution/public/resolver/lib/vector2.ts rename to x-pack/plugins/security_solution/public/resolver/models/vector2.ts diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/inverse_projection_matrix.test.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/inverse_projection_matrix.test.ts index 000dbb8d52841..4eda074363647 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/inverse_projection_matrix.test.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/inverse_projection_matrix.test.ts @@ -9,7 +9,7 @@ import { CameraAction } from './action'; import { CameraState } from '../../types'; import { cameraReducer } from './reducer'; import { inverseProjectionMatrix } from './selectors'; -import { applyMatrix3 } from '../../lib/vector2'; +import { applyMatrix3 } from '../../models/vector2'; import { scaleToZoom } from './scale_to_zoom'; describe('inverseProjectionMatrix', () => { diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/methods.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/methods.ts index 3288b91ffbb50..a1410430049c4 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/methods.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/methods.ts @@ -6,7 +6,7 @@ import { translation } from './selectors'; import { CameraState, Vector2 } from '../../types'; -import { distance } from '../../lib/vector2'; +import { distance } from '../../models/vector2'; /** * Return a new `CameraState` with the `animation` property diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/projection_matrix.test.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/projection_matrix.test.ts index e868424d06c94..63abb57626e93 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/projection_matrix.test.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/projection_matrix.test.ts @@ -9,7 +9,7 @@ import { CameraAction } from './action'; import { CameraState } from '../../types'; import { cameraReducer } from './reducer'; import { projectionMatrix } from './selectors'; -import { applyMatrix3 } from '../../lib/vector2'; +import { applyMatrix3 } from '../../models/vector2'; import { scaleToZoom } from './scale_to_zoom'; describe('projectionMatrix', () => { diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/reducer.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/reducer.ts index f64864edab5b3..03b0e3e11c4fc 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/reducer.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/reducer.ts @@ -7,7 +7,7 @@ import { Reducer } from 'redux'; import { unitsPerNudge, nudgeAnimationDuration } from './scaling_constants'; import { animatePanning } from './methods'; -import * as vector2 from '../../lib/vector2'; +import * as vector2 from '../../models/vector2'; import * as selectors from './selectors'; import { clamp } from '../../lib/math'; diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/selectors.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/selectors.ts index 49c157ec8e0f5..86d934bd95663 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/selectors.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/selectors.ts @@ -7,8 +7,8 @@ import { createSelector, defaultMemoize } from 'reselect'; import { easing } from 'ts-easing'; import { clamp, lerp } from '../../lib/math'; -import * as vector2 from '../../lib/vector2'; -import { multiply, add as addMatrix } from '../../lib/matrix3'; +import * as vector2 from '../../models/vector2'; +import { multiply, add as addMatrix } from '../../models/matrix3'; import { inverseOrthographicProjection, scalingTransformation, diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/zooming.test.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/zooming.test.ts index ff03b0baf01aa..3b6749cf841fa 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/zooming.test.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/zooming.test.ts @@ -11,7 +11,7 @@ import { CameraState, AABB } from '../../types'; import { viewableBoundingBox, inverseProjectionMatrix, scalingFactor } from './selectors'; import { expectVectorsToBeClose } from './test_helpers'; import { scaleToZoom } from './scale_to_zoom'; -import { applyMatrix3 } from '../../lib/vector2'; +import { applyMatrix3 } from '../../models/vector2'; describe('zooming', () => { let store: Store; diff --git a/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts b/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts index f15cb6427dccf..e45101e97e6c1 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts @@ -22,7 +22,7 @@ import { uniquePidForProcess, } from '../../models/process_event'; import { factory as indexedProcessTreeFactory } from '../../models/indexed_process_tree'; -import { isEqual } from '../../lib/aabb'; +import { isEqual } from '../../models/aabb'; import { ResolverEvent, diff --git a/x-pack/plugins/security_solution/public/resolver/view/edge_line.tsx b/x-pack/plugins/security_solution/public/resolver/view/edge_line.tsx index 4eccb4f560220..65c70f94432c7 100644 --- a/x-pack/plugins/security_solution/public/resolver/view/edge_line.tsx +++ b/x-pack/plugins/security_solution/public/resolver/view/edge_line.tsx @@ -7,7 +7,7 @@ import React from 'react'; import styled from 'styled-components'; import { FormattedMessage } from '@kbn/i18n/react'; -import { applyMatrix3, distance, angle } from '../lib/vector2'; +import { applyMatrix3, distance, angle } from '../models/vector2'; import { Vector2, Matrix3, EdgeLineMetadata } from '../types'; import { useResolverTheme, calculateResolverFontSize } from './assets'; diff --git a/x-pack/plugins/security_solution/public/resolver/view/process_event_dot.tsx b/x-pack/plugins/security_solution/public/resolver/view/process_event_dot.tsx index a2249e1920bc4..9df9ed84f3010 100644 --- a/x-pack/plugins/security_solution/public/resolver/view/process_event_dot.tsx +++ b/x-pack/plugins/security_solution/public/resolver/view/process_event_dot.tsx @@ -13,7 +13,7 @@ import { useHistory } from 'react-router-dom'; // eslint-disable-next-line import/no-nodejs-modules import querystring from 'querystring'; import { NodeSubMenu, subMenuAssets } from './submenu'; -import { applyMatrix3 } from '../lib/vector2'; +import { applyMatrix3 } from '../models/vector2'; import { Vector2, Matrix3, AdjacentProcessMap } from '../types'; import { SymbolIds, useResolverTheme, calculateResolverFontSize } from './assets'; import { ResolverEvent, ResolverNodeStats } from '../../../common/endpoint/types'; diff --git a/x-pack/plugins/security_solution/public/resolver/view/use_camera.test.tsx b/x-pack/plugins/security_solution/public/resolver/view/use_camera.test.tsx index f772c20f8cf16..3476764a88733 100644 --- a/x-pack/plugins/security_solution/public/resolver/view/use_camera.test.tsx +++ b/x-pack/plugins/security_solution/public/resolver/view/use_camera.test.tsx @@ -14,7 +14,7 @@ import { storeFactory } from '../store'; import { Matrix3, ResolverStore, SideEffectSimulator } from '../types'; import { ResolverEvent } from '../../../common/endpoint/types'; import { SideEffectContext } from './side_effect_context'; -import { applyMatrix3 } from '../lib/vector2'; +import { applyMatrix3 } from '../models/vector2'; import { sideEffectSimulator } from './side_effect_simulator'; import { mockProcessEvent } from '../models/process_event_test_helpers'; import { mock as mockResolverTree } from '../models/resolver_tree'; From 0cb5a35348f3f81b945a62e9731060f30d765be1 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 29 Jun 2020 14:45:36 -0400 Subject: [PATCH 2/3] Add tests for AABB --- .../public/resolver/models/aabb.test.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 x-pack/plugins/security_solution/public/resolver/models/aabb.test.ts diff --git a/x-pack/plugins/security_solution/public/resolver/models/aabb.test.ts b/x-pack/plugins/security_solution/public/resolver/models/aabb.test.ts new file mode 100644 index 0000000000000..ce7d9eda6cca6 --- /dev/null +++ b/x-pack/plugins/security_solution/public/resolver/models/aabb.test.ts @@ -0,0 +1,46 @@ +/* + * 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 { isEqual } from './aabb'; +import { AABB } from '../types'; + +describe('AABB', () => { + const minimumX = 0; + const minimumY = 0; + const maximumX = 0; + const maximumY = 0; + + let aabb: AABB; + + beforeEach(() => { + aabb = { minimum: [minimumX, minimumY], maximum: [maximumX, maximumY] }; + }); + it('should be equal to an AABB with the same values', () => { + expect(isEqual(aabb, { minimum: [minimumX, minimumY], maximum: [maximumX, maximumY] })).toBe( + true + ); + }); + + it('should not be equal to an AABB with a different minimum X value', () => { + expect( + isEqual(aabb, { minimum: [minimumX + 1, minimumY], maximum: [maximumX, maximumY] }) + ).toBe(false); + }); + it('should not be equal to an AABB with a different minimum Y value', () => { + expect( + isEqual(aabb, { minimum: [minimumX, minimumY + 1], maximum: [maximumX, maximumY] }) + ).toBe(false); + }); + it('should not be equal to an AABB with a different maximum X value', () => { + expect( + isEqual(aabb, { minimum: [minimumX, minimumY], maximum: [maximumX + 1, maximumY] }) + ).toBe(false); + }); + it('should not be equal to an AABB with a different maximum Y value', () => { + expect( + isEqual(aabb, { minimum: [minimumX, minimumY], maximum: [maximumX, maximumY + 1] }) + ).toBe(false); + }); +}); From 5a83950274dcea5ccc0ec1d5c8e8fe2b45d9c485 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 29 Jun 2020 14:51:23 -0400 Subject: [PATCH 3/3] remove dead code --- .../public/resolver/lib/tree_sequencers.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/x-pack/plugins/security_solution/public/resolver/lib/tree_sequencers.ts b/x-pack/plugins/security_solution/public/resolver/lib/tree_sequencers.ts index 219c58d6efc9c..843126c0eef5a 100644 --- a/x-pack/plugins/security_solution/public/resolver/lib/tree_sequencers.ts +++ b/x-pack/plugins/security_solution/public/resolver/lib/tree_sequencers.ts @@ -4,20 +4,6 @@ * 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(root: T, children: (parent: T) => T[]): Iterable { - 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. */