From 6817c66ccaea14e8308e68e54f4ea0da94f6b0ca Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Fri, 15 Feb 2019 19:40:30 -0800 Subject: [PATCH] implement 'surface gauge' for asserting the cad scene --- web/app/cad/tpi/tpi.js | 5 ++++- web/test/utils/surfaceGauge.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 web/test/utils/surfaceGauge.js diff --git a/web/app/cad/tpi/tpi.js b/web/app/cad/tpi/tpi.js index 4e7c5b61..e607e067 100644 --- a/web/app/cad/tpi/tpi.js +++ b/web/app/cad/tpi/tpi.js @@ -15,6 +15,7 @@ import {Plane} from '../../brep/geom/impl/plane'; import pip from '../tess/pip'; import {readShellEntityFromJson} from '../scene/wrappers/entityIO'; import * as vec from '../../math/vec' +import NurbsSurface from '../../brep/geom/surfaces/nurbsSurface'; export default { @@ -26,7 +27,9 @@ export default { pip, validator: BREPValidator, geom: { - Point, BrepCurve, Plane, createBoundingSurface + Point, BrepCurve, + Plane, createBoundingSurface, + NurbsSurface }, topo: { Edge, Loop, Face, Shell, Vertex diff --git a/web/test/utils/surfaceGauge.js b/web/test/utils/surfaceGauge.js new file mode 100644 index 00000000..5a32588a --- /dev/null +++ b/web/test/utils/surfaceGauge.js @@ -0,0 +1,33 @@ +import * as vec from '../../app/math/math' +import {assertFaceOrigination, assertFaceRole} from './asserts'; + +export class SurfaceGauge { + + constructor(surface, rayCast) { + this.surface = surface; + this.rayCast = rayCast; + } + + sample(u, v, delta = 10) { + let normal = this.surface.normal(u, v); + let pt = this.surface.point(u, v); + let deltaV = vec.mul(normal, delta); + let [face] = ui.rayCastFaces(vec.add(pt, deltaV), vec.sub(pt, deltaV)); + let sampleAssertations = { + assertFaceOrigination: (sketchId, primitiveId) => { + assertFaceOrigination(face, sketchId, primitiveId); + return sampleAssertations; + }, + assertFaceRole: role => { + assertFaceRole(face, role); + return sampleAssertations + } + } + } + + static prism(surfaceImpl, a, b, c, d) { + return new SurfaceGauge(surfaceImpl(1, 1, [0,0,1,1], [0,0,1,1], + [ [ a, b] , + [ c, d ] ] )); + } +} \ No newline at end of file