-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCacheManager.ts
53 lines (46 loc) · 1.75 KB
/
CacheManager.ts
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
import { PlaneGeometry } from '../core/geometries/PlaneGeometry'
/**
* Used to cache {@link PlaneGeometry} and avoid as many large array computations as possible.<br>
* Could be improved to handle other caches.
*/
export class CacheManager {
/** Array of cached {@link PlaneGeometry} */
planeGeometries: PlaneGeometry[]
/**
* CacheManager constructor
*/
constructor() {
this.planeGeometries = []
}
/**
* Check if a given {@link PlaneGeometry} is already cached based on its {@link PlaneGeometry#definition.id | definition id}
* @param planeGeometry - {@link PlaneGeometry} to check
* @returns - {@link PlaneGeometry} found or null if not found
*/
getPlaneGeometry(planeGeometry: PlaneGeometry): PlaneGeometry | null {
return this.planeGeometries.find((element) => element.definition.id === planeGeometry.definition.id)
}
/**
* Check if a given {@link PlaneGeometry} is already cached based on its {@link PlaneGeometry#definition | definition id}
* @param planeGeometryID - {@link PlaneGeometry#definition.id | PlaneGeometry definition id}
* @returns - {@link PlaneGeometry} found or null if not found
*/
getPlaneGeometryByID(planeGeometryID: number): PlaneGeometry | null {
return this.planeGeometries.find((element) => element.definition.id === planeGeometryID)
}
/**
* Add a {@link PlaneGeometry} to our cache {@link planeGeometries} array
* @param planeGeometry
*/
addPlaneGeometry(planeGeometry: PlaneGeometry) {
this.planeGeometries.push(planeGeometry)
}
/**
* Destroy our {@link CacheManager}
*/
destroy() {
this.planeGeometries = []
}
}
/** @exports @const cacheManager - {@link CacheManager} class object */
export const cacheManager = new CacheManager() as CacheManager