aabb collision for selection is back, remove old point in square algorithm and now selected gates are moved on top

This commit is contained in:
Matei Adriel 2019-07-25 12:10:51 +03:00
parent b109519cb5
commit 5361fa4190
3 changed files with 15 additions and 16 deletions

View file

@ -9,15 +9,3 @@ export const pointInSquare = (point: vector2, square: Transform) => {
point[1] <= square.maxY 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
)
}

View file

@ -2,10 +2,7 @@ import { Camera } from './Camera'
import { Simulation } from '../../simulation/classes/Simulation' import { Simulation } from '../../simulation/classes/Simulation'
import { Subject } from 'rxjs' import { Subject } from 'rxjs'
import { MouseEventInfo } from '../../core/components/MouseEventInfo' import { MouseEventInfo } from '../../core/components/MouseEventInfo'
import { import { pointInSquare } from '../../../common/math/helpers/pointInSquare'
oldPointInSquare,
pointInSquare
} from '../../../common/math/helpers/pointInSquare'
import { vector2 } from '../../../common/math/types/vector2' import { vector2 } from '../../../common/math/types/vector2'
import { relativeTo, add, invert } from '../../vector2/helpers/basic' import { relativeTo, add, invert } from '../../vector2/helpers/basic'
import { SimulationRendererOptions } from '../types/SimulationRendererOptions' import { SimulationRendererOptions } from '../types/SimulationRendererOptions'
@ -232,6 +229,16 @@ export class SimulationRenderer {
for (const { id } of selectedGates) { for (const { id } of selectedGates) {
addIdToSelection(this, 'permanent', id) 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}`
)
}
} }
} }
}) })

View file

@ -13,6 +13,10 @@ export const gatesInSelection = (
gates: Gate[] = [] gates: Gate[] = []
) => { ) => {
return gates.filter(({ transform }) => { return gates.filter(({ transform }) => {
if (aabbCollisionDetection(transform, selectedArea)) {
return true
}
for (const point of transform.getPoints()) { for (const point of transform.getPoints()) {
if (pointInSquare(point, selectedArea)) { if (pointInSquare(point, selectedArea)) {
return true return true