You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
2.0 KiB
53 lines
2.0 KiB
import arrows from '../arrows/arrows'
|
|
|
|
export const currentBuildingFloorsList = state => {
|
|
const currentBuilding = state.buildingList.find(building => building.buildingCode === state.currentFloor.buildingCode)
|
|
return currentBuilding?.floorList ?? []
|
|
}
|
|
|
|
const getCodeByAngle = angle =>
|
|
angle < (Math.PI / 8) * 1 || angle > (Math.PI / 8) * 15
|
|
? '8003'
|
|
: angle >= (Math.PI / 8) * 1 && angle < (Math.PI / 8) * 3
|
|
? '8002'
|
|
: angle >= (Math.PI / 8) * 3 && angle < (Math.PI / 8) * 5
|
|
? '8001'
|
|
: angle >= (Math.PI / 8) * 5 && angle < (Math.PI / 8) * 7
|
|
? '8008'
|
|
: angle >= (Math.PI / 8) * 7 && angle < (Math.PI / 8) * 9
|
|
? '8007'
|
|
: angle >= (Math.PI / 8) * 9 && angle < (Math.PI / 8) * 11
|
|
? '8006'
|
|
: angle >= (Math.PI / 8) * 11 && angle < (Math.PI / 8) * 13
|
|
? '8005'
|
|
: '8004'
|
|
const getDistance = (a, b) => Math.sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y))
|
|
export const currentFloorShopMap = ({ currentFloor: device, shopList, mapData }) => {
|
|
if (!mapData || !shopList.length) return {}
|
|
device.angle = Number(device.angle)
|
|
if (isNaN(device.angle)) device.angle = 0
|
|
const building = mapData[0]
|
|
const map = building.buildArr[device.floorOrder].mapData
|
|
const nodes = map.path.nodes
|
|
const deviceX = nodes[device.location].x
|
|
const deviceY = nodes[device.location].y
|
|
return shopList
|
|
.filter(shop => shop.floor === device.floor)
|
|
.reduce((acc, shop) => {
|
|
const result = {}
|
|
try {
|
|
const xaxis = JSON.parse(shop.xaxis).map(Number)
|
|
let angle = (Math.atan2(deviceY - xaxis[2], xaxis[0] - deviceX) / Math.PI) * 180 + device.angle
|
|
if (angle < 0) angle += 360
|
|
if (angle > 360) angle -= 360
|
|
console.log(angle)
|
|
angle = (angle / 180) * Math.PI
|
|
result.distance = Math.ceil(getDistance({ x: deviceX, y: deviceY }, { x: xaxis[0], y: xaxis[2] }) / building.scale)
|
|
|
|
result.dir = arrows[getCodeByAngle(angle)]
|
|
} catch (error) {
|
|
result.dir = arrows[getCodeByAngle(0)]
|
|
}
|
|
return { ...acc, [shop.shopCode]: result }
|
|
}, {})
|
|
}
|
|
|