From b480b7550af48b36a26d7e0ca3d6e80fc80a5b24 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Thu, 23 Mar 2017 17:49:09 -0700 Subject: [PATCH] fixing approximation module --- web/app/brep/approx.js | 66 ++++++++++++++++++++++++++++++++++++++++++ web/app/utils/utils.js | 33 +++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 web/app/brep/approx.js diff --git a/web/app/brep/approx.js b/web/app/brep/approx.js new file mode 100644 index 00000000..b73722cf --- /dev/null +++ b/web/app/brep/approx.js @@ -0,0 +1,66 @@ +const FACE_CHUNK = 'approx.face.chunk'; +const EDGE_CHUNK = 'approx.edge.chunk'; +const EDGE_AUX = 'approx.edge.aux'; + +class ApproxSurface { + constructor() { + this.faces = []; + } + + addFace(face) { + face.data[FACE_CHUNK] = this; + this.faces.push(face); + } +} + +class ApproxCurve { + constructor(surface1, surface2) { + this.surface1 = surface1; + this.surface2 = surface2; + this.edges = []; + } + + addEdge(edge) { + this.edges.push(edge); + edge.data[EDGE_CHUNK] = this; + } + + equals(other) { + return other instanceof ApproxCurve && + + ((this.surface1 == other.surface1 && + this.surface2 == other.surface2) || + + (this.surface1 == other.surface2 && + this.surface2 == other.surface1) + ) + } +} + +function update(shell) { + const index = new DoubleKeyMap(); + for (let e of shell.edges) { + const face1 = e.halfEdge1.loop.face; + const face2 = e.halfEdge2.loop.face; + const approxSurface1 = face1.data[FACE_CHUNK]; + const approxSurface2 = face2.data[FACE_CHUNK]; + if (approxSurface1 !== undefined && approxSurface1 === approxSurface2) { + e.data[EDGE_AUX] = approxSurface1; + } else if (approxSurface1 !== undefined || approxSurface2 !== undefined ) { + const o1 = approxSurface1 !== undefined ? approxSurface1 : face1.surface; + const o2 = approxSurface2 !== undefined ? approxSurface2 : face2.surface; + const approxCurve = getCurve(index, o1, o2); + approxCurve.addEdge(e); + } + } +} + +function getCurve(index, o1, o2) { + let curve = index.get(o1, o2); + if (curve == null) { + curve = new ApproxCurve(o1, o2); + index.set(o1, o2, curve); + } + return curve; +} + diff --git a/web/app/utils/utils.js b/web/app/utils/utils.js index 08787a65..4c6c6fba 100644 --- a/web/app/utils/utils.js +++ b/web/app/utils/utils.js @@ -66,3 +66,36 @@ export function camelCaseSplit(str) { } return words; } + +export class DoubleKeyMap { + + constructor() { + this.map = new Map(); + } + + get(a, b) { + let subMap = this.map.get(a); + if (subMap == null) { + subMap = this.map.get(b); + if (subMap != null) { + return subMap.get(a);; + } + return null; + } + subMap.get(b); + } + + set(a, b, value) { + let subMap = this.map.get(a); + if (subMap == null) { + subMap = this.map.get(b); + if (subMap != null) { + subMap.set(a, value); + return; + } + subMap = new Map(); + this.map.set(a, subMap); + } + subMap.set(b, value); + } +} \ No newline at end of file