Skip to content

Commit

Permalink
feat(utils): create pointToBox()
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Dec 20, 2023
1 parent d8ebe64 commit 5c81830
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { BufferGeometry, Euler, Mesh, Object3D, Vector3 as ThreeJsVector3 } from 'three'
import { Box3, BufferGeometry, Euler, Mesh, Object3D, Vector3 as ThreeJsVector3 } from 'three'
import { Vector3 } from '@src/Vector3.js'
import { mean } from '@src/faux-ramda.js'

Expand Down Expand Up @@ -157,3 +157,17 @@ export const normalizeDegree = (degree: number) => {
export const numberOfVertices = (geometry: BufferGeometry) => {
return geometry.getAttribute('position').array.length / 3
}

/**
* Expands a 3D point into a Box3 object with the given size
*
* @param point - the center of the box
* @param size - sidelength/diameter of the box
* @returns the generated Box3 object
*/
export const pointToBox = (point: Vector3, size: number | Vector3) => {
size = typeof size === 'number' ? new Vector3(size, size, size) : size
const min = point.clone().sub(size)
const max = point.clone().add(size)
return new Box3(min, max)
}
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export {
isBetween,
circleOfVectors,
numberOfVertices,
pointToBox,
} from '@src/helpers.js'

0 comments on commit 5c81830

Please sign in to comment.