From 5361fa4190b22cca14fcefcf59f12bdd6b7b40dd Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Thu, 25 Jul 2019 12:10:51 +0300 Subject: [PATCH] aabb collision for selection is back, remove old point in square algorithm and now selected gates are moved on top --- src/common/math/helpers/pointInSquare.ts | 12 ------------ .../classes/SimulationRenderer.ts | 15 +++++++++++---- .../helpers/gatesInSelection.ts | 4 ++++ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/common/math/helpers/pointInSquare.ts b/src/common/math/helpers/pointInSquare.ts index 5eb3f76..bb9269b 100644 --- a/src/common/math/helpers/pointInSquare.ts +++ b/src/common/math/helpers/pointInSquare.ts @@ -9,15 +9,3 @@ export const pointInSquare = (point: vector2, square: Transform) => { point[1] <= square.maxY ) } - -/** - * The old version of pontInSquare - */ -export const oldPointInSquare = (point: vector2, square: Transform) => { - return ( - point[0] >= square.x && - point[0] <= square.x + square.width && - point[1] >= square.y && - point[1] <= square.y + square.height - ) -} diff --git a/src/modules/simulationRenderer/classes/SimulationRenderer.ts b/src/modules/simulationRenderer/classes/SimulationRenderer.ts index a44ae22..56cc011 100644 --- a/src/modules/simulationRenderer/classes/SimulationRenderer.ts +++ b/src/modules/simulationRenderer/classes/SimulationRenderer.ts @@ -2,10 +2,7 @@ import { Camera } from './Camera' import { Simulation } from '../../simulation/classes/Simulation' import { Subject } from 'rxjs' import { MouseEventInfo } from '../../core/components/MouseEventInfo' -import { - oldPointInSquare, - pointInSquare -} from '../../../common/math/helpers/pointInSquare' +import { pointInSquare } from '../../../common/math/helpers/pointInSquare' import { vector2 } from '../../../common/math/types/vector2' import { relativeTo, add, invert } from '../../vector2/helpers/basic' import { SimulationRendererOptions } from '../types/SimulationRendererOptions' @@ -232,6 +229,16 @@ export class SimulationRenderer { for (const { id } of selectedGates) { addIdToSelection(this, 'permanent', id) + + const node = this.simulation.gates.get(id) + + if (node) { + this.simulation.gates.moveOnTop(node) + } else { + throw new SimulationError( + `Cannot find node in gate storage with id ${id}` + ) + } } } }) diff --git a/src/modules/simulationRenderer/helpers/gatesInSelection.ts b/src/modules/simulationRenderer/helpers/gatesInSelection.ts index c82d8fa..36630ea 100644 --- a/src/modules/simulationRenderer/helpers/gatesInSelection.ts +++ b/src/modules/simulationRenderer/helpers/gatesInSelection.ts @@ -13,6 +13,10 @@ export const gatesInSelection = ( gates: Gate[] = [] ) => { return gates.filter(({ transform }) => { + if (aabbCollisionDetection(transform, selectedArea)) { + return true + } + for (const point of transform.getPoints()) { if (pointInSquare(point, selectedArea)) { return true