Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | import { v4 as uuidv4 } from 'uuid'
import {
getDistanceBetweenPoints,
get3DDistanceBetweenPoints,
isSamePoint3D,
translate2D
} from '../geometry'
import { substractVector, dotProduct } from '../vector'
export class Point {
constructor(x = 0, y = 0, z = 0, layer = null) {
this.id = uuidv4()
this.type = 'point'
this.version = 0
this.x = x
this.y = y
this.z = z
this.layer = layer
this.open = false
this.selected = false
this.visible = true
this.hasWarning = false
}
getIntersections(object) {
const intersections = []
if (!object) return
if (object.type == 'line') {
if (isSamePoint3D(object.getProjectedPoint(this), this)) {
intersections.push({ ...this })
}
} else if (object.type == 'point') {
if (isSamePoint3D(object, this)) {
intersections.push({ ...object })
}
} else if (object.type == 'circle') {
if (get3DDistanceBetweenPoints(this, object.center) == object.radius) {
intersections.push({ ...this })
}
}
return intersections
}
getPxDistanceTo(point, canvasContext) {
const toRealityRef = canvasContext.toRealityRef
const realityPoint = toRealityRef(point)
return getDistanceBetweenPoints(realityPoint, this) / canvasContext.mmPerPx
}
getProjectedPoint(point) {
return this
}
getVerticalProjectedPoint(point) {
return this
}
getDistanceToPoint(point) {
return get3DDistanceBetweenPoints(point, this.getProjectedPoint(point))
}
getHorizontalDistanceToPoint(point) {
return getDistanceBetweenPoints(
point,
this.getVerticalProjectedPoint(point)
)
}
isInPlane(plane) {
if (!plane) return false
const { point, normalVector } = plane
if (dotProduct(substractVector(point, this), normalVector) > 0.1)
return false
return true
}
translate(vectorInMm) {
let translatedPoint = translate2D({ x: this.x, y: this.y }, vectorInMm)
this.x = translatedPoint.x
this.y = translatedPoint.y
}
serialize() {
if (!this.belongsTo) {
this.belongsTo = []
}
const belongsTo = this.belongsTo.map((item) => {
return {
polygon: item.polygon.serialize(),
polygonId: item.polygonId,
index: item.index
}
})
return {
x: this.x,
y: this.y,
z: this.z,
layer: this.layer,
type: this.type,
belongsTo: belongsTo || [],
itemType: this.itemType
}
}
}
|