From 2f40461c7827ca9cfe69f3f4d098a378def59315 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Tue, 3 Nov 2015 23:09:20 -0800 Subject: [PATCH] debugging tools --- .gitignore | 1 + web/app/3d/ctrl.js | 25 +++++++++++-- web/app/3d/main.js | 20 +++++++++++ web/app/engine.js | 4 ++- web/app/test/craft-fixtures.js | 4 +++ web/app/test/craft-scripts.js | 21 +++++++++++ web/app/test/craft-tests.js | 15 ++++++++ web/app/test/headless-loader.js | 64 +++++++++++++++++++++++++++++++++ web/app/test/viz.sh | 2 ++ 9 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 web/app/test/craft-fixtures.js create mode 100644 web/app/test/craft-scripts.js create mode 100644 web/app/test/craft-tests.js create mode 100644 web/app/test/headless-loader.js create mode 100755 web/app/test/viz.sh diff --git a/.gitignore b/.gitignore index 81d153e1..fb221cbf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ *.iml *.ipr *.iws +/web/app/test/viz/** \ No newline at end of file diff --git a/web/app/3d/ctrl.js b/web/app/3d/ctrl.js index c925dce7..cb945f91 100644 --- a/web/app/3d/ctrl.js +++ b/web/app/3d/ctrl.js @@ -7,16 +7,21 @@ TCAD.UI = function(app) { var mainBox = new tk.Box(); mainBox.root.css({height : '100%'}); var propFolder = new tk.Folder("Solid's Properties"); + var debugFolder = new tk.Folder("Debug"); var cameraFolder = new tk.Folder("Camera"); var objectsFolder = new tk.Folder("Objects"); var modificationsFolder = new tk.Folder("Modifications"); - var extrude, cut, edit, refreshSketches; + var extrude, cut, edit, refreshSketches, printSolids, printFace, printFaceId; tk.add(mainBox, propFolder); tk.add(propFolder, extrude = new tk.Button("Extrude")); tk.add(propFolder, cut = new tk.Button("Cut")); tk.add(propFolder, edit = new tk.Button("Edit")); tk.add(propFolder, refreshSketches = new tk.Button("Refresh Sketches")); tk.add(propFolder, new tk.Text("Message")); + tk.add(mainBox, debugFolder); + tk.add(debugFolder, printSolids = new tk.Button("Print Solids")); + tk.add(debugFolder, printFace = new tk.Button("Print Face")); + tk.add(debugFolder, printFaceId = new tk.Button("Print Face ID")); tk.add(mainBox, cameraFolder); tk.add(cameraFolder, new tk.Number("x")); tk.add(cameraFolder, new tk.Number("y")); @@ -106,7 +111,23 @@ TCAD.UI = function(app) { extrude.root.click(cutExtrude(false)); edit.root.click(tk.methodRef(app, "sketchFace")); refreshSketches.root.click(tk.methodRef(app, "refreshSketches")); - + printSolids.root.click(function () { + app.viewer.scene.children.map(function(o) { + if (o.geometry instanceof TCAD.Solid) { + console.log(JSON.stringify(o.geometry.csg)); + } + }); + }); + printFace.root.click(function () { + var s = app.viewer.selectionMgr.selection[0]; + console.log(JSON.stringify({ + polygons : s.csgGroup.polygons, + basis : s._basis + })); + }); + printFaceId.root.click(function () { + console.log(app.viewer.selectionMgr.selection[0].id); + }); this.solidFolder = null; }; diff --git a/web/app/3d/main.js b/web/app/3d/main.js index 348ef667..28b09968 100644 --- a/web/app/3d/main.js +++ b/web/app/3d/main.js @@ -51,6 +51,23 @@ TCAD.App = function() { window.addEventListener('storage', storage_handler, false); }; +TCAD.App.prototype.findFace = function(faceId) { + var solidId = faceId.split(":")[0]; + var children = this.viewer.scene.children; + for (var i = 0; i < children.length; i++) { + var obj = children[i]; + if (!!obj.geometry && obj.geometry.tCadId !== undefined) { + for (var j = 0; j < obj.geometry.polyFaces.length; j++) { + var face = obj.geometry.polyFaces[j]; + if (face.id == faceId) { + return face; + } + } + } + } + return null; +}; + TCAD.App.prototype.faceStorageKey = function(polyFaceId) { return "TCAD.projects."+this.id+".sketch." + polyFaceId; }; @@ -101,6 +118,9 @@ TCAD.App.prototype.sketchFace = function() { var mid = (arc.length / 2) >> 0; var c = TCAD.math.circleFromPoints(arc[0], arc[mid], arc[arc.length-1]); if (c == null) { + for (var i = 1; i < arc.length; i++) { + addSegment(arc[i - 1], arc[i]); + } return; } if (!TCAD.geom.isCCW([arc[0], arc[mid], arc[arc.length-1]])) { diff --git a/web/app/engine.js b/web/app/engine.js index 3518d951..e869d716 100644 --- a/web/app/engine.js +++ b/web/app/engine.js @@ -153,6 +153,9 @@ TCAD.utils.equal = function(v1, v2) { return TCAD.utils.areEqual(v1, v2, TCAD.TOLERANCE); }; +TCAD.utils.strictEqual = function(a, b) { + return a.x == b.x && a.y == b.y && a.z == b.z; +}; TCAD.utils.isPointInsidePolygon = function( inPt, inPolygon ) { var EPSILON = TCAD.TOLERANCE; @@ -858,7 +861,6 @@ TCAD.utils.arrFlatten1L = function(arr) { var result = []; for (var i = 0; i < arr.length; i++) { TCAD.utils.addAll(result, arr[i]); - } return result; }; diff --git a/web/app/test/craft-fixtures.js b/web/app/test/craft-fixtures.js new file mode 100644 index 00000000..2b57985d --- /dev/null +++ b/web/app/test/craft-fixtures.js @@ -0,0 +1,4 @@ +box = {"polygons":[{"vertices":[{"pos":{"_x":-353.3319072242888,"_y":12.512527212621677,"_z":0}},{"pos":{"_x":12.512527212621677,"_y":353.3319072242888,"_z":0}},{"pos":{"_x":353.3319072242888,"_y":-12.512527212621677,"_z":0}},{"pos":{"_x":-12.512527212621677,"_y":-353.3319072242888,"_z":0}}],"shared":{"color":[4,4,4,4],"__tcad":{"faceId":"0:0"},"tag":1},"plane":{"normal":{"_x":0,"_y":0,"_z":-1},"w":0}},{"vertices":[{"pos":{"_x":-12.512527212621677,"_y":-353.3319072242888,"_z":500}},{"pos":{"_x":353.3319072242888,"_y":-12.512527212621677,"_z":500}},{"pos":{"_x":12.512527212621677,"_y":353.3319072242888,"_z":500}},{"pos":{"_x":-353.3319072242888,"_y":12.512527212621677,"_z":500}}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500}},{"vertices":[{"pos":{"_x":-353.3319072242888,"_y":12.512527212621677,"_z":0}},{"pos":{"_x":-12.512527212621677,"_y":-353.3319072242888,"_z":0}},{"pos":{"_x":-12.512527212621677,"_y":-353.3319072242888,"_z":500}},{"pos":{"_x":-353.3319072242888,"_y":12.512527212621677,"_z":500}}],"shared":{"color":[0,0,0,0],"__tcad":{"csgInfo":{},"faceId":"0:2"},"tag":3},"plane":{"normal":{"_x":-0.7316888688738208,"_y":-0.6816387600233342,"_z":0},"w":249.99999999999994}},{"vertices":[{"pos":{"_x":-12.512527212621677,"_y":-353.3319072242888,"_z":0}},{"pos":{"_x":353.3319072242888,"_y":-12.512527212621677,"_z":0}},{"pos":{"_x":353.3319072242888,"_y":-12.512527212621677,"_z":500}},{"pos":{"_x":-12.512527212621677,"_y":-353.3319072242888,"_z":500}}],"shared":{"color":[1,1,1,1],"__tcad":{"csgInfo":{},"faceId":"0:3"},"tag":4},"plane":{"normal":{"_x":0.6816387600233342,"_y":-0.7316888688738208,"_z":0},"w":249.99999999999994}},{"vertices":[{"pos":{"_x":353.3319072242888,"_y":-12.512527212621677,"_z":0}},{"pos":{"_x":12.512527212621677,"_y":353.3319072242888,"_z":0}},{"pos":{"_x":12.512527212621677,"_y":353.3319072242888,"_z":500}},{"pos":{"_x":353.3319072242888,"_y":-12.512527212621677,"_z":500}}],"shared":{"color":[2,2,2,2],"__tcad":{"csgInfo":{},"faceId":"0:4"},"tag":5},"plane":{"normal":{"_x":0.7316888688738208,"_y":0.6816387600233342,"_z":0},"w":249.99999999999994}},{"vertices":[{"pos":{"_x":12.512527212621677,"_y":353.3319072242888,"_z":0}},{"pos":{"_x":-353.3319072242888,"_y":12.512527212621677,"_z":0}},{"pos":{"_x":-353.3319072242888,"_y":12.512527212621677,"_z":500}},{"pos":{"_x":12.512527212621677,"_y":353.3319072242888,"_z":500}}],"shared":{"color":[3,3,3,3],"__tcad":{"csgInfo":{},"faceId":"0:5"},"tag":6},"plane":{"normal":{"_x":-0.6816387600233342,"_y":0.7316888688738208,"_z":0},"w":249.99999999999994}}],"properties":{},"isCanonicalized":false,"isRetesselated":false}; +face0 = {"polygons":[{"vertices":[{"pos":{"_x":-139.91971276733113,"_y":-42.04243972612939,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":0}},"tag":141},{"pos":{"_x":67.02471603558078,"_y":-71.94608279168925,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":227},{"pos":{"_x":67.02471603558077,"_y":-71.94608279168925,"_z":250,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":174},{"pos":{"_x":-139.91971276733108,"_y":-42.042439726129395,"_z":250,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":223}],"shared":{"color":[6,6,6,6],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":2}},"faceId":"1:1"},"tag":15},"plane":{"normal":{"_x":0.1430154341016014,"_y":0.9897204583157461,"_z":0},"w":-61.62094117524815,"tag":127}},{"vertices":[{"pos":{"_x":67.02471603558078,"_y":-71.94608279168925,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":227},{"pos":{"_x":170.7656318170002,"_y":-86.9367318986355,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":140},{"pos":{"_x":170.76563181700018,"_y":-86.93673189863549,"_z":250,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":1}},"tag":222},{"pos":{"_x":118.91187028001812,"_y":-79.44381998224206,"_z":249.99999999999997,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":201},{"pos":{"_x":67.02471603558077,"_y":-71.94608279168925,"_z":295.3227460786163,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":176}],"shared":{"color":[6,6,6,6],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":2}},"faceId":"1:1"},"tag":15},"plane":{"normal":{"_x":0.1430154341016014,"_y":0.9897204583157461,"_z":0},"w":-61.62094117524815,"tag":127}}],"basis":[{"x":-0.989720458315746,"y":0.14301543410160136,"z":0},{"x":0,"y":0,"z":0.9999999999999999},{"x":0.1430154341016014,"y":0.9897204583157461,"z":0}]}; +face1 = {"polygons":[{"vertices":[{"pos":{"_x":186.76017988553747,"_y":-167.6901587281717,"_z":500},"tag":252},{"pos":{"_x":-185.45572292943226,"_y":-167.6901587281717,"_z":500},"tag":253},{"pos":{"_x":-12.512527212621677,"_y":-353.3319072242888,"_z":500},"tag":131}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":186.76017988553747,"_y":-167.6901587281717,"_z":500},"tag":252},{"pos":{"_x":187.82928632605396,"_y":-166.69418295288312,"_z":500},"tag":254},{"pos":{"_x":-10.468669108347044,"_y":-166.69418295288295,"_z":499.99999999999994,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":231},{"pos":{"_x":-49.09887613352758,"_y":-167.6901587281717,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":233}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-49.09887613352758,"_y":-167.6901587281717,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":233},{"pos":{"_x":-78.41019051675583,"_y":-164.25274670199042,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":234},{"pos":{"_x":-188.65800380439185,"_y":-164.25274670199047,"_z":500},"tag":255},{"pos":{"_x":-185.45572292943226,"_y":-167.6901587281717,"_z":500},"tag":253}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":187.82928632605396,"_y":-166.69418295288312,"_z":500},"tag":254},{"pos":{"_x":195.19899679951467,"_y":-159.82858676499436,"_z":500},"tag":256},{"pos":{"_x":41.935823053894126,"_y":-159.82858676499427,"_z":499.99999999999994,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":229},{"pos":{"_x":-10.468669108347044,"_y":-166.69418295288295,"_z":499.99999999999994,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":231}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-78.41019051675583,"_y":-164.25274670199042,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":234},{"pos":{"_x":-100.99472718823785,"_y":-157.05626748938366,"_z":499.9999999999999,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":236},{"pos":{"_x":-195.36221836291742,"_y":-157.0562674893837,"_z":500},"tag":257},{"pos":{"_x":-188.65800380439185,"_y":-164.25274670199047,"_z":500},"tag":255}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-100.99472718823785,"_y":-157.05626748938366,"_z":499.9999999999999,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":236},{"pos":{"_x":-118.40911170807782,"_y":-146.29689162837445,"_z":499.99999999999994,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":238},{"pos":{"_x":-205.3856148262412,"_y":-146.2968916283746,"_z":500},"tag":258},{"pos":{"_x":-195.36221836291742,"_y":-157.0562674893837,"_z":500},"tag":257}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":195.19899679951467,"_y":-159.82858676499436,"_z":500},"tag":256},{"pos":{"_x":211.9595984695577,"_y":-144.21446958264957,"_z":500},"tag":259},{"pos":{"_x":116.29066512165514,"_y":-144.2144695826496,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":227},{"pos":{"_x":41.935823053894126,"_y":-159.82858676499427,"_z":499.99999999999994,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":229}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":211.9595984695577,"_y":-144.21446958264957,"_z":500},"tag":259},{"pos":{"_x":216.13725708581467,"_y":-140.32257760488972,"_z":500},"tag":260},{"pos":{"_x":130.7240165469426,"_y":-140.32257760488986,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":154},{"pos":{"_x":116.29066512165514,"_y":-144.2144695826496,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":227}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-118.40911170807782,"_y":-146.29689162837445,"_z":499.99999999999994,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":238},{"pos":{"_x":-131.5719934078236,"_y":-131.7992925395276,"_z":499.9999999999999,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":241},{"pos":{"_x":-218.8915268150999,"_y":-131.79929253952716,"_z":500},"tag":261},{"pos":{"_x":-205.3856148262412,"_y":-146.2968916283746,"_z":500},"tag":258}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-131.5719934078236,"_y":-131.7992925395276,"_z":499.9999999999999,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":241},{"pos":{"_x":-140.95547887260085,"_y":-113.01987083485247,"_z":499.9999999999999,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":243},{"pos":{"_x":-236.386369594972,"_y":-113.01987083485217,"_z":500},"tag":262},{"pos":{"_x":-218.8915268150999,"_y":-131.79929253952716,"_z":500},"tag":261}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-140.95547887260085,"_y":-113.01987083485247,"_z":499.9999999999999,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":243},{"pos":{"_x":-146.65827348701345,"_y":-88.95906997611296,"_z":500.00000000000006,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":245},{"pos":{"_x":-258.8013264983923,"_y":-88.95906997611341,"_z":500},"tag":263},{"pos":{"_x":-236.386369594972,"_y":-113.01987083485217,"_z":500},"tag":262}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-146.65827348701345,"_y":-88.95906997611296,"_z":500.00000000000006,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":245},{"pos":{"_x":-148.3860834315919,"_y":-57.95087638517974,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":247},{"pos":{"_x":-287.68844987696707,"_y":-57.950876385179214,"_z":500},"tag":264},{"pos":{"_x":-258.8013264983923,"_y":-88.95906997611341,"_z":500},"tag":263}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-148.3860834315919,"_y":-57.95087638517974,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":247},{"pos":{"_x":-145.3190408272563,"_y":-17.23172254604061,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":249},{"pos":{"_x":-325.62226944542664,"_y":-17.231722546040665,"_z":500},"tag":265},{"pos":{"_x":-287.68844987696707,"_y":-57.950876385179214,"_z":500},"tag":264}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-145.3190408272563,"_y":-17.23172254604061,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":249},{"pos":{"_x":-135.77660147151167,"_y":37.95878915956841,"_z":499.9999999999999,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":251},{"pos":{"_x":-326.01722426759903,"_y":37.95878915956856,"_z":500},"tag":266},{"pos":{"_x":-353.3319072242888,"_y":12.512527212621677,"_z":500},"tag":134},{"pos":{"_x":-325.62226944542664,"_y":-17.231722546040665,"_z":500},"tag":265}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-135.77660147151167,"_y":37.95878915956841,"_z":499.9999999999999,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":251},{"pos":{"_x":-116.41704398014676,"_y":116.41238076953938,"_z":499.99999999999994,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":190},{"pos":{"_x":-241.80308758584388,"_y":116.41238076953792,"_z":500},"tag":267},{"pos":{"_x":-326.01722426759903,"_y":37.95878915956856,"_z":500},"tag":266}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":-116.41704398014676,"_y":116.41238076953938,"_z":499.99999999999994,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":190},{"pos":{"_x":-114.46231703302026,"_y":122.86684412679392,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":169},{"pos":{"_x":-234.87469784331117,"_y":122.8668441267942,"_z":500},"tag":268},{"pos":{"_x":-241.80308758584388,"_y":116.41238076953792,"_z":500},"tag":267}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":216.13725708581467,"_y":-140.32257760488972,"_z":500},"tag":260},{"pos":{"_x":353.3319072242888,"_y":-12.512527212621677,"_z":500},"tag":132},{"pos":{"_x":227.2129641350349,"_y":122.8668441267942,"_z":500},"tag":269},{"pos":{"_x":-114.46231703302026,"_y":122.86684412679392,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":169},{"pos":{"_x":130.7240165469426,"_y":-140.32257760488986,"_z":500,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":0}},"tag":154}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}},{"vertices":[{"pos":{"_x":227.2129641350349,"_y":122.8668441267942,"_z":500},"tag":269},{"pos":{"_x":12.512527212621677,"_y":353.3319072242888,"_z":500},"tag":133},{"pos":{"_x":-234.87469784331117,"_y":122.8668441267942,"_z":500},"tag":268}],"shared":{"color":[5,5,5,5],"__tcad":{"faceId":"0:1"},"tag":2},"plane":{"normal":{"_x":0,"_y":0,"_z":1},"w":500,"tag":125}}],"basis":[{"x":1,"y":0,"z":0},{"x":0,"y":1,"z":0},{"x":0,"y":0,"z":1}]} +face2 = {"polygons":[{"vertices":[{"pos":{"_x":-41.80886661701135,"_y":-243.95416083551567,"_z":238,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":539},{"pos":{"_x":-50.52655387509194,"_y":-243.41119825127814,"_z":234.98609503037457,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":540},{"pos":{"_x":-109.39918449298024,"_y":-249.33123585400983,"_z":217.96725899468242},"tag":541},{"pos":{"_x":-80.67640321495499,"_y":-280.1630203369067,"_z":237.99999999999997,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":0}},"tag":489}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-50.52655387509194,"_y":-243.41119825127814,"_z":234.98609503037457,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":540},{"pos":{"_x":-63.611126395836386,"_y":-240.8061372198943,"_z":229.8397617108925,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":542},{"pos":{"_x":-112.73892876116642,"_y":-245.74626702707087,"_z":215.63795002905817},"tag":543},{"pos":{"_x":-109.39918449298024,"_y":-249.33123585400983,"_z":217.96725899468242},"tag":541}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-63.611126395836386,"_y":-240.8061372198943,"_z":229.8397617108925,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":542},{"pos":{"_x":-74.49162737865471,"_y":-236.72742424698856,"_z":224.89506200074408,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":544},{"pos":{"_x":-117.14514327162097,"_y":-241.0165211554313,"_z":212.5648300116266},"tag":545},{"pos":{"_x":-112.73892876116642,"_y":-245.74626702707087,"_z":215.63795002905817},"tag":543}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-74.49162737865471,"_y":-236.72742424698856,"_z":224.89506200074408,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":544},{"pos":{"_x":-83.4081104931287,"_y":-231.2547589941904,"_z":220.10192833629395,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":546},{"pos":{"_x":-122.5705013907885,"_y":-235.1927998850722,"_z":208.78090696426034},"tag":547},{"pos":{"_x":-117.14514327162097,"_y":-241.0165211554313,"_z":212.5648300116266},"tag":545}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-83.4081104931287,"_y":-231.2547589941904,"_z":220.10192833629395,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":546},{"pos":{"_x":-90.51363525869118,"_y":-224.40149359647938,"_z":215.4154051588147,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":548},{"pos":{"_x":-129.01673996310396,"_y":-228.27323884176116,"_z":204.28496952255858},"tag":549},{"pos":{"_x":-122.5705013907885,"_y":-235.1927998850722,"_z":208.78090696426034},"tag":547}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-90.51363525869118,"_y":-224.40149359647938,"_z":215.4154051588147,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":548},{"pos":{"_x":-95.88354470309952,"_y":-216.11996220938153,"_z":210.79449631126568,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":550},{"pos":{"_x":-136.53091426782672,"_y":-220.20732765831394,"_z":199.04419892105386},"tag":551},{"pos":{"_x":-129.01673996310396,"_y":-228.27323884176116,"_z":204.28496952255858},"tag":549}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-95.88354470309952,"_y":-216.11996220938153,"_z":210.79449631126568,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":550},{"pos":{"_x":-99.51816659905046,"_y":-206.30140737461008,"_z":206.201264067711,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":552},{"pos":{"_x":-145.20569211346054,"_y":-210.89559428595373,"_z":192.9939638766781},"tag":553},{"pos":{"_x":-136.53091426782672,"_y":-220.20732765831394,"_z":199.04419892105386},"tag":551}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-99.51816659905046,"_y":-206.30140737461008,"_z":206.201264067711,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":552},{"pos":{"_x":-101.33906616609596,"_y":-194.77074009778977,"_z":201.60022075649456,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":554},{"pos":{"_x":-155.18349623756214,"_y":-200.18515843403927,"_z":186.03493146665028},"tag":555},{"pos":{"_x":-145.20569211346054,"_y":-210.89559428595373,"_z":192.9939638766781},"tag":553}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-101.33906616609596,"_y":-194.77074009778977,"_z":201.60022075649456,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":554},{"pos":{"_x":-101.17811224628832,"_y":-181.2756954790067,"_z":196.95809971446477,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":556},{"pos":{"_x":-166.6648050243523,"_y":-187.86082136272898,"_z":178.02727778222763},"tag":557},{"pos":{"_x":-155.18349623756214,"_y":-200.18515843403927,"_z":186.03493146665028},"tag":555}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-101.17811224628832,"_y":-181.2756954790067,"_z":196.95809971446477,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":556},{"pos":{"_x":-98.75758889671056,"_y":-165.46923870300824,"_z":192.24418016697518,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":558},{"pos":{"_x":-179.92143557534422,"_y":-173.63080748763574,"_z":168.78142363389077},"tag":559},{"pos":{"_x":-166.6648050243523,"_y":-187.86082136272898,"_z":178.02727778222763},"tag":557}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-98.75758889671056,"_y":-165.46923870300824,"_z":192.24418016697518,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":558},{"pos":{"_x":-93.65820084551937,"_y":-146.88324001506635,"_z":187.4314980939492,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":560},{"pos":{"_x":-195.3162269255655,"_y":-157.10563590084647,"_z":158.04430646669525},"tag":561},{"pos":{"_x":-179.92143557534422,"_y":-173.63080748763574,"_z":168.78142363389077},"tag":559}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-93.65820084551937,"_y":-146.88324001506635,"_z":187.4314980939492,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":560},{"pos":{"_x":-85.26982797616907,"_y":-124.89039282462304,"_z":182.499557754907,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":562},{"pos":{"_x":-213.33126015737423,"_y":-137.76782816283696,"_z":145.47969820533865},"tag":563},{"pos":{"_x":-195.3162269255655,"_y":-157.10563590084647,"_z":158.04430646669525},"tag":561}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-85.26982797616907,"_y":-124.89039282462304,"_z":182.499557754907,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":562},{"pos":{"_x":-72.71693880241358,"_y":-98.65008331419722,"_z":177.43967266259995,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":564},{"pos":{"_x":-234.60757807442712,"_y":-114.92927216582272,"_z":130.6405027161049},"tag":565},{"pos":{"_x":-213.33126015737423,"_y":-137.76782816283696,"_z":145.47969820533865},"tag":563}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-72.71693880241358,"_y":-98.65008331419722,"_z":177.43967266259995,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":564},{"pos":{"_x":-54.74629213257765,"_y":-67.03265356611891,"_z":172.26501150209978,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":566},{"pos":{"_x":-228.62618902804553,"_y":-84.51744262984232,"_z":122.00000000000004,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":567},{"pos":{"_x":-246.99626066064857,"_y":-101.63093633169436,"_z":122.00000000000003},"tag":526},{"pos":{"_x":-234.60757807442712,"_y":-114.92927216582272,"_z":130.6405027161049},"tag":565}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-54.74629213257765,"_y":-67.03265356611891,"_z":172.26501150209978,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":566},{"pos":{"_x":-29.558807403816747,"_y":-28.516185435013973,"_z":167.02917791036108,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":568},{"pos":{"_x":-185.32657863001418,"_y":-44.17967886607878,"_z":122.00000000000004,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":569},{"pos":{"_x":-228.62618902804553,"_y":-84.51744262984232,"_z":122.00000000000004,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":567}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":-29.558807403816747,"_y":-28.516185435013973,"_z":167.02917791036108,"sketchConnectionObject":{"_class":"TCAD.TWO.Arc","id":1}},"tag":568},{"pos":{"_x":-4.762425750311214,"_y":5.112112330914562,"_z":163.36696458211253,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":1}},"tag":430},{"pos":{"_x":-147.86163773628067,"_y":-9.277472557462694,"_z":122.00000000000004,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":570},{"pos":{"_x":-185.32657863001418,"_y":-44.17967886607878,"_z":122.00000000000004,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":569}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":253.4128758293174,"_y":31.07336932600507,"_z":238,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":0}},"tag":571},{"pos":{"_x":-4.762425750311214,"_y":5.112112330914562,"_z":163.36696458211253,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":1}},"tag":430},{"pos":{"_x":102.24581400350128,"_y":-109.75333033107214,"_z":238.00000000000006,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":0}},"tag":427}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}},{"vertices":[{"pos":{"_x":253.4128758293174,"_y":31.07336932600507,"_z":238,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":0}},"tag":571},{"pos":{"_x":285.16803122195523,"_y":60.65635967476035,"_z":238.00000000000006},"tag":536},{"pos":{"_x":118.8481737762617,"_y":239.18844367997264,"_z":122.00000000000003,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":572},{"pos":{"_x":-147.86163773628067,"_y":-9.277472557462694,"_z":122.00000000000004,"sketchConnectionObject":{"_class":"TCAD.TWO.Segment","id":2}},"tag":570}],"shared":{"color":[66,66,66,66],"__tcad":{"csgInfo":{"derivedFrom":{"_class":"TCAD.TWO.Segment","id":1}},"faceId":"2:2"},"tag":382},"plane":{"normal":{"_x":-0.292667592585567,"_y":0.31415704671434347,"_z":0.9031340045917275},"w":150.5420747326014,"tag":381}}],"basis":[{"x":0.9031340045917278,"y":1.3877787807814457e-17,"z":0.29266759258556707},{"x":0.09194358655567841,"y":0.901305349999722,"z":-0.28372591166983546},{"x":-0.292667592585567,"y":0.31415704671434347,"z":0.9031340045917275}]} \ No newline at end of file diff --git a/web/app/test/craft-scripts.js b/web/app/test/craft-scripts.js new file mode 100644 index 00000000..de810f41 --- /dev/null +++ b/web/app/test/craft-scripts.js @@ -0,0 +1,21 @@ +function test1() { + + var face; + var app = window._TCAD_APP; + face = app.findFace('0:2'); + + app.craft.modify({ + type: 'CUT', + solids : [face.solid], + face : face, + params : {target : face.basis()[2].multiply(-250), expansionFactor : 2.5} + }); + + face = app.findFace('0:4'); + app.craft.modify({ + type: 'CUT', + solids : [face.solid], + face : face, + params : {target : face.basis()[2].multiply(-550), expansionFactor : 1} + }); +} \ No newline at end of file diff --git a/web/app/test/craft-tests.js b/web/app/test/craft-tests.js new file mode 100644 index 00000000..af3f66b2 --- /dev/null +++ b/web/app/test/craft-tests.js @@ -0,0 +1,15 @@ +require("./headless-loader.js"); + +function testReconstruct0() { + +} + +testReconstruct0(); +var face = face2; +var polygons2D = face.polygons.map(csgPolyToSimple).map(polygonTransform(basisTransformation(face.basis))); +var csgPolygons = polygons2D.map(function(p) {return new CSG.Polygon( p.map(function(v) { return new CSG.Vertex(new CSG.Vector3D(v));}) )} ); +var outline = TCAD.craft.findOutline(csgPolygons); + + + +viz("1", polygons2D, outline); diff --git a/web/app/test/headless-loader.js b/web/app/test/headless-loader.js new file mode 100644 index 00000000..c80a552c --- /dev/null +++ b/web/app/test/headless-loader.js @@ -0,0 +1,64 @@ +TCAD = {}; + +require("../engine.js"); +require("../math/vector.js"); +require("../math/math.js"); +require("../workbench.js"); +require("../math/graph.js"); +require("../3d/hashmap.js"); +CSG = require("../../lib/csg.js").CSG; + +require("./craft-fixtures.js"); + +var assert = require('assert'); +viz = function(name, polygons, segments) { + var colors = ['aqua', 'black', 'blue', 'brown', 'crimson', 'fuchsia', 'fuschia', 'gray', 'green', 'lemon', 'lime', 'olive', 'orange', 'peach', 'pink', 'purple', 'salmon', 'tan', 'teal', 'violet', 'violet', 'blue', 'white', 'yellow']; + var bbox = new TCAD.BBox(); + var fs = require('fs'); + var builder = require('xmlbuilder'); + var svg = builder.create('html') + .ele('body') + .ele('svg', {width: 800, height: 600}); + for (var pi = 0; pi < polygons.length; ++ pi) { + var poly = polygons[pi]; + var pointsStr = ""; + for (var pointIdx = 0; pointIdx < poly.length; ++ pointIdx) { + pointsStr += " " + poly[pointIdx].x + "," + poly[pointIdx].y; + bbox.checkBounds(poly[pointIdx].x, poly[pointIdx].y); + } + svg.ele('polygon', {points: pointsStr, style:"fill:"+colors[pi % colors.length]}); + } + for (var si = 0; si < segments.length; ++ si) { + var s = segments[si]; + svg.ele('line', {x1 : s[0].x, y1 : s[0].y, x2 : s[1].x, y2 : s[1].y, stroke:'magenta', 'stroke-width':'2'}); + svg.ele('ellipse', {cx : s[0].x, cy : s[0].y, rx:3, ry:2, fill : "red"}); + svg.ele('ellipse', {cx : s[1].x, cy : s[1].y, rx:2, ry:3, fill : "red"}); + } + var length = Math.max(bbox.maxX - bbox.minX, bbox.maxY - bbox.minY) + 100; + svg.att('viewBox', (bbox.minX - 100) + " " + (bbox.minY - 100) + " " + length + " " + length) + var htmlText = svg.end({ pretty: true}); + if (!fs.existsSync('viz')) fs.mkdirSync('viz', function(err) {}); + fs.writeFile("viz/" + name + ".html", htmlText); +} + +vertToPoint = function(v) { + return {x : v.pos._x, y : v.pos._y, z : v.pos._z}; +} + +csgPolyToSimple = function(p) { + return p.vertices.map(vertToPoint); +} + +basisTransformation = function(basis) { + var tr = new TCAD.Matrix().setBasis(basis).invert(); + return function(p) { + return tr.apply(p); + } +} + +polygonTransform = function(tr) { + return function(polygon) { + return polygon.map(tr); + } +}; + diff --git a/web/app/test/viz.sh b/web/app/test/viz.sh new file mode 100755 index 00000000..27a44978 --- /dev/null +++ b/web/app/test/viz.sh @@ -0,0 +1,2 @@ +node ./craft-tests.js +open viz/1.html