From b47fa5e4bb8318bc2fead2ceea416e131935980e Mon Sep 17 00:00:00 2001 From: Wliu Date: Fri, 18 Dec 2015 23:12:22 -0500 Subject: [PATCH 1/8] Initial conversion from eval to math.eval Closes #28 Still need to compile the equations and then measure performance, but this is a great first step :) --- js/graph.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/js/graph.js b/js/graph.js index 16f0a2f..34cafef 100644 --- a/js/graph.js +++ b/js/graph.js @@ -150,12 +150,12 @@ Graph.prototype.drawShape = function() if(graph2ComparingPoint1 > graph1ComparingPoint1 && graph2ComparingPoint2 > graph1ComparingPoint2) { console.log("\t\t\t\tGraph2 is higher than graph1"); - this.addBSP("this.axisOfRotation-graphArray[1].getY(i)", "this.axisOfRotation-graphArray[1].getY(i+step)", "this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+step)"); + this.addBSP("axis - y2", "axis - y2step", "axis - y1", "axis - y1step"); } else { console.log("\t\t\t\tGraph2 is lower than or equal to graph1"); - this.addBSP("this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+step)", "this.axisOfRotation-graphArray[1].getY(i)", "this.axisOfRotation-graphArray[1].getY(i+step)"); + this.addBSP("axis - y1", "axis - y1step", "axis - y2", "axis - y2step"); } } else @@ -164,12 +164,12 @@ Graph.prototype.drawShape = function() if(graph2ComparingPoint1 > graph1ComparingPoint1 && graph2ComparingPoint2 > graph1ComparingPoint2) { console.log("\t\t\t\tGraph2 is higher than graph1"); - this.addBSP("this.axisOfRotation+Math.abs(graphArray[1].getY(i))", "this.axisOfRotation+Math.abs(graphArray[1].getY(i+step))", "this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+step)"); + this.addBSP("axis + abs(y2)", "axis + abs(y2step)", "axis - y1", "axis - y1step"); } else { console.log("\t\t\t\tGraph2 is lower than or equal to graph1"); - this.addBSP("this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+step)", "this.axisOfRotation-graphArray[1].getY(i)", "this.axisOfRotation-graphArray[1].getY(i+step)"); + this.addBSP("axis - y1", "axis - y1step", "axis - y2", "axis - y2step"); } } } @@ -182,12 +182,12 @@ Graph.prototype.drawShape = function() if(graph2ComparingPoint1 > graph1ComparingPoint1 && graph2ComparingPoint2 > graph1ComparingPoint2) { console.log("\t\t\t\tGraph2 is higher than graph1"); - this.addBSP("Math.abs(this.axisOfRotation)+this.getY(i)", "Math.abs(this.axisOfRotation)+this.getY(i+step)", "Math.abs(this.axisOfRotation)+graphArray[1].getY(i)", "Math.abs(this.axisOfRotation)+graphArray[1].getY(i+step)"); + this.addBSP("abs(axis) + y1", "abs(axis) + y1step", "abs(axis) + y2", "abs(axis) + y2step"); } else { console.log("\t\t\t\tGraph2 is lower than or equal to graph1"); - this.addBSP("Math.abs(this.axisOfRotation)+graphArray[1].getY(i)", "Math.abs(this.axisOfRotation)+graphArray[1].getY(i+step)", "Math.abs(this.axisOfRotation)+this.getY(i)", "Math.abs(this.axisOfRotation)+this.getY(i+step)"); + this.addBSP("abs(axis) + y2", "abs(axis) + y2step", "abs(axis) + y1", "abs(axis) + y1step"); } } else @@ -196,12 +196,12 @@ Graph.prototype.drawShape = function() if(graph2ComparingPoint1 > graph1ComparingPoint1 && graph2ComparingPoint2 > graph1ComparingPoint2) { console.log("\t\t\t\tGraph2 is higher than graph1"); - this.addBSP("Math.abs(this.axisOfRotation-this.getY(i))", "Math.abs(this.axisOfRotation-this.getY(i+step))", "Math.abs(this.axisOfRotation-graphArray[1].getY(i))", "Math.abs(this.axisOfRotation-graphArray[1].getY(i+step))"); + this.addBSP("abs(axis - y1)", "abs(axis - y1step)", "abs(axis - y2)", "abs(axis - y2step)"); } else { console.log("\t\t\t\tGraph2 is lower than or equal to graph1"); - this.addBSP("Math.abs(this.axisOfRotation-graphArray[1].getY(i))", "Math.abs(this.axisOfRotation-graphArray[1].getY(i+step))", "Math.abs(this.axisOfRotation-this.getY(i))", "Math.abs(this.axisOfRotation-this.getY(i+step))"); + this.addBSP("abs(axis - y2)", "abs(axis - y2step)", "abs(axis - y1)", "abs(axis - y1step)"); } } } @@ -219,24 +219,24 @@ Graph.prototype.drawShape = function() if(this.axisOfRotation > boundY1) { console.log("\t\t\tAxis of rotation is greater than boundY1"); - this.addBSP("Math.abs(this.axisOfRotation-this.getY(i))", "Math.abs(this.axisOfRotation-this.getY(i+step))", "Math.abs(this.axisOfRotation)", "Math.abs(this.axisOfRotation)"); + this.addBSP("abs(axis - y1)", "abs(axis - y1step)", "abs(axis)", "abs(axis)"); } else if(this.axisOfRotation < boundY1) { console.log("\t\t\tAxis of rotation is less than boundY1"); - this.addBSP("Math.abs(this.axisOfRotation)", "Math.abs(this.axisOfRotation)", "Math.abs(this.axisOfRotation)+this.getY(i)", "Math.abs(this.axisOfRotation)+this.getY(i+step)"); + this.addBSP("abs(axis)", "abs(axis)", "abs(axis) + y1", "abs(axis) + y1step"); } else if(this.axisOfRotation === boundY1) { console.log("\t\t\tAxis of rotation is equal to boundY1"); - this.addSolidWithoutHoles("Math.abs(this.getY(i))", "Math.abs(this.getY(i+step))"); + this.addSolidWithoutHoles("abs(y1)", "abs(y1step)"); } } } else { console.log("Axis of rotation is 0"); - this.addSolidWithoutHoles("Math.abs(this.getY(i))", "Math.abs(this.getY(i+step))"); + this.addSolidWithoutHoles("abs(y1)", "abs(y1step)"); } scene.add(this.group); render(); @@ -249,7 +249,7 @@ Graph.prototype.addBSP = function(smallGeoR1, smallGeoR2, bigGeoR1, bigGeoR2) { if(this.getY(i) <= size) { - if(!eval(smallGeoR1) || !eval(smallGeoR2)) //Hacky bugfix woo + if(!math.eval(smallGeoR1, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}) || !math.eval(smallGeoR2, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)})) //Hacky bugfix woo { smallGeoR1 += "+0.01"; smallGeoR2 += "+0.01"; @@ -260,9 +260,9 @@ Graph.prototype.addBSP = function(smallGeoR1, smallGeoR2, bigGeoR1, bigGeoR2) step = this.bound2 - i; } - var smallCylinderGeom = new THREE.CylinderGeometry(eval(smallGeoR1), eval(smallGeoR2), step, 50); + var smallCylinderGeom = new THREE.CylinderGeometry(math.eval(smallGeoR1, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), math.eval(smallGeoR2, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), step, 50); smallCylinderGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); - var largeCylinderGeom = new THREE.CylinderGeometry(eval(bigGeoR1), eval(bigGeoR2), step, 360); + var largeCylinderGeom = new THREE.CylinderGeometry(math.eval(bigGeoR1, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), math.eval(bigGeoR2, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), step, 360); largeCylinderGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); var smallCylinderBSP = new ThreeBSP(smallCylinderGeom); var largeCylinderBSP = new ThreeBSP(largeCylinderGeom); @@ -286,7 +286,7 @@ Graph.prototype.addSolidWithoutHoles = function(leftRadius, rightRadius) step = this.bound2 - i; } - var geometry = new THREE.CylinderGeometry(eval(leftRadius), eval(rightRadius), step, 100); + var geometry = new THREE.CylinderGeometry(math.eval(leftRadius, {y1: this.getY(i), y1step: this.getY(i + step)}), math.eval(rightRadius, {y1: this.getY(i), y1step: this.getY(i + step)}), step, 100); geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); var plane = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial({color: 0xFFFF00/*, transparent: true, opacity: 0.5*/})); plane.rotation.set(0, 0, Math.PI / 2); From f7968bb0ef6fd9fc6ae9dc78c47a74597f30be6d Mon Sep 17 00:00:00 2001 From: Wliu Date: Sat, 19 Dec 2015 12:21:53 -0500 Subject: [PATCH 2/8] Compile the equations first --- .eslintrc.yaml | 2 +- js/graph.js | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 1e715e6..8d4b1fa 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -29,7 +29,7 @@ rules: no-labels: 1 no-lone-blocks: 2 no-loop-func: 1 - no-multi-spaces: 2 + no-mixed-spaces-and-tabs: 0 no-multi-str: 1 no-native-reassign: 2 no-new-func: 2 diff --git a/js/graph.js b/js/graph.js index 34cafef..799f5db 100644 --- a/js/graph.js +++ b/js/graph.js @@ -244,15 +244,24 @@ Graph.prototype.drawShape = function() Graph.prototype.addBSP = function(smallGeoR1, smallGeoR2, bigGeoR1, bigGeoR2) { + var smallGeoR1Equation = math.compile(smallGeoR1); + var smallGeoR2Equation = math.compile(smallGeoR2); + var bigGeoR1Equation = math.compile(bigGeoR1); + var bigGeoR2Equation = math.compile(bigGeoR2); var step = this.quality; for(var i = this.bound1; i < this.bound2; i += step) { if(this.getY(i) <= size) { - if(!math.eval(smallGeoR1, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}) || !math.eval(smallGeoR2, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)})) //Hacky bugfix woo + //Hacky bugfix woo + if(!smallGeoR1Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}) + || !smallGeoR2Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)})) { smallGeoR1 += "+0.01"; smallGeoR2 += "+0.01"; + + smallGeoR1Equation = math.compile(smallGeoR1 += "+ 0.01"); + smallGeoR2Equation = math.compile(smallGeoR2 += "+ 0.01"); } if(i + step > this.bound2) //Prevent the solid from extending beyond the second bound if it can't be divided by the quality @@ -260,9 +269,13 @@ Graph.prototype.addBSP = function(smallGeoR1, smallGeoR2, bigGeoR1, bigGeoR2) step = this.bound2 - i; } - var smallCylinderGeom = new THREE.CylinderGeometry(math.eval(smallGeoR1, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), math.eval(smallGeoR2, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), step, 50); + var smallCylinderGeom = new THREE.CylinderGeometry(smallGeoR1Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), + smallGeoR2Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), + step, 50); smallCylinderGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); - var largeCylinderGeom = new THREE.CylinderGeometry(math.eval(bigGeoR1, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), math.eval(bigGeoR2, {axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), step, 360); + var largeCylinderGeom = new THREE.CylinderGeometry(bigGeoR1Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), + bigGeoR2Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), + step, 360); largeCylinderGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); var smallCylinderBSP = new ThreeBSP(smallCylinderGeom); var largeCylinderBSP = new ThreeBSP(largeCylinderGeom); @@ -276,6 +289,8 @@ Graph.prototype.addBSP = function(smallGeoR1, smallGeoR2, bigGeoR1, bigGeoR2) Graph.prototype.addSolidWithoutHoles = function(leftRadius, rightRadius) { + var leftRadiusEquation = math.compile(leftRadius); + var rightRadiusEquation = math.compile(rightRadius); var step = this.quality; for(var i = this.bound1; i < this.bound2; i += step) { @@ -286,7 +301,9 @@ Graph.prototype.addSolidWithoutHoles = function(leftRadius, rightRadius) step = this.bound2 - i; } - var geometry = new THREE.CylinderGeometry(math.eval(leftRadius, {y1: this.getY(i), y1step: this.getY(i + step)}), math.eval(rightRadius, {y1: this.getY(i), y1step: this.getY(i + step)}), step, 100); + var geometry = new THREE.CylinderGeometry(leftRadiusEquation.eval({y1: this.getY(i), y1step: this.getY(i + step)}), + rightRadiusEquation.eval({y1: this.getY(i), y1step: this.getY(i + step)}), + step, 100); geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); var plane = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial({color: 0xFFFF00/*, transparent: true, opacity: 0.5*/})); plane.rotation.set(0, 0, Math.PI / 2); From 8652e4d980376c0cfdde2a5e285a58874154312d Mon Sep 17 00:00:00 2001 From: Wliu Date: Sat, 19 Dec 2015 12:50:09 -0500 Subject: [PATCH 3/8] :art: Fix indentation --- js/graph.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/graph.js b/js/graph.js index 799f5db..0d68e4a 100644 --- a/js/graph.js +++ b/js/graph.js @@ -271,11 +271,11 @@ Graph.prototype.addBSP = function(smallGeoR1, smallGeoR2, bigGeoR1, bigGeoR2) var smallCylinderGeom = new THREE.CylinderGeometry(smallGeoR1Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), smallGeoR2Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), - step, 50); + step, 50); smallCylinderGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); var largeCylinderGeom = new THREE.CylinderGeometry(bigGeoR1Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), bigGeoR2Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), - step, 360); + step, 360); largeCylinderGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); var smallCylinderBSP = new ThreeBSP(smallCylinderGeom); var largeCylinderBSP = new ThreeBSP(largeCylinderGeom); @@ -303,7 +303,7 @@ Graph.prototype.addSolidWithoutHoles = function(leftRadius, rightRadius) var geometry = new THREE.CylinderGeometry(leftRadiusEquation.eval({y1: this.getY(i), y1step: this.getY(i + step)}), rightRadiusEquation.eval({y1: this.getY(i), y1step: this.getY(i + step)}), - step, 100); + step, 100); geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); var plane = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial({color: 0xFFFF00/*, transparent: true, opacity: 0.5*/})); plane.rotation.set(0, 0, Math.PI / 2); From f76c2c1e92ce3069aee0763c70e6acd25a33ef80 Mon Sep 17 00:00:00 2001 From: Wliu Date: Thu, 3 Mar 2016 21:04:39 -0500 Subject: [PATCH 4/8] Directly translate the cylinders --- js/graph.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/js/graph.js b/js/graph.js index 75188db..5fbdd31 100644 --- a/js/graph.js +++ b/js/graph.js @@ -307,9 +307,6 @@ Graph.prototype.addBSP = function(smallGeoR1, smallGeoR2, bigGeoR1, bigGeoR2) if(!smallGeoR1Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}) || !smallGeoR2Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)})) { - smallGeoR1 += "+0.01"; - smallGeoR2 += "+0.01"; - smallGeoR1Equation = math.compile(smallGeoR1 += "+ 0.01"); smallGeoR2Equation = math.compile(smallGeoR2 += "+ 0.01"); } @@ -322,11 +319,11 @@ Graph.prototype.addBSP = function(smallGeoR1, smallGeoR2, bigGeoR1, bigGeoR2) var smallCylinderGeom = new THREE.CylinderGeometry(smallGeoR1Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), smallGeoR2Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), step, 50); - smallCylinderGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); + smallCylinderGeom.translate(0, -(i + step / 2), -this.axisOfRotation); var largeCylinderGeom = new THREE.CylinderGeometry(bigGeoR1Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), bigGeoR2Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: graphArray[1].getY(i), y2step: graphArray[1].getY(i + step)}), step, 360); - largeCylinderGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); + largeCylinderGeom.translate(0, -(i + step / 2), -this.axisOfRotation); var smallCylinderBSP = new ThreeBSP(smallCylinderGeom); var largeCylinderBSP = new ThreeBSP(largeCylinderGeom); var intersectionBSP = largeCylinderBSP.subtract(smallCylinderBSP); From 8c0db16b32998ebf4e917fd5899efc6940d4d545 Mon Sep 17 00:00:00 2001 From: Wliu Date: Thu, 3 Mar 2016 21:17:00 -0500 Subject: [PATCH 5/8] Ditto for addSolidWithoutHoles --- js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/graph.js b/js/graph.js index 5fbdd31..518dd9f 100644 --- a/js/graph.js +++ b/js/graph.js @@ -351,7 +351,7 @@ Graph.prototype.addSolidWithoutHoles = function(leftRadius, rightRadius) var geometry = new THREE.CylinderGeometry(leftRadiusEquation.eval({y1: this.getY(i), y1step: this.getY(i + step)}), rightRadiusEquation.eval({y1: this.getY(i), y1step: this.getY(i + step)}), step, 100); - geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i + step / 2), -this.axisOfRotation)); + geometry.translate(0, -(i + step / 2), -this.axisOfRotation); var plane = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial({color: 0xFFFF00/*, transparent: true, opacity: 0.5*/})); plane.rotation.set(0, 0, Math.PI / 2); this.group.add(plane); From 70ab5302ce173307d16658dcc00dab042426eb3b Mon Sep 17 00:00:00 2001 From: Wliu Date: Tue, 12 Apr 2016 21:24:41 -0400 Subject: [PATCH 6/8] Fix incorrect merge --- js/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/graph.js b/js/graph.js index c20d9a4..240e413 100644 --- a/js/graph.js +++ b/js/graph.js @@ -195,7 +195,7 @@ Graph.prototype.drawShape = function() if(graphArray[1] === undefined || Number(graphArray[1].given) === this.axisOfRotation) //FIXME: This doesn't catch constants { console.log("No second function or second function is equal to the axis of rotation"); - this.addSolidWithoutHoles("abs(y1)", "abs(y1 + y1step)"); + this.addSolidWithoutHoles("abs(y1)", "abs(y1step)"); } else { From ccc7e2f74f565ba5eb670b59b273516871c7f1ee Mon Sep 17 00:00:00 2001 From: Wliu Date: Sat, 28 May 2016 20:47:38 -0400 Subject: [PATCH 7/8] Fix previous merge --- js/graph.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/js/graph.js b/js/graph.js index 0c90d77..1134fd6 100644 --- a/js/graph.js +++ b/js/graph.js @@ -158,7 +158,7 @@ class Graph [this.equation1.points, this.equation2.points] = [this.equation2.points, this.equation1.points]; } - if(this.equation2 === undefined || Number(this.equation2.equation) === this.axisOfRotation) //FIXME: This doesn't catch constants + if(this.equation2 === undefined || Number(this.equation2.equation) === axisOfRotation) //FIXME: This doesn't catch constants { console.log("No second function or second function is equal to the axis of rotation"); this.addSolidWithoutHoles("abs(y1)", "abs(y1step)"); @@ -170,8 +170,8 @@ class Graph if(boundY1 !== boundY2) { console.log("\tboundY1 and boundY2 are not equal"); - if(this.axisOfRotation >= this.equation1.getMax() && this.axisOfRotation >= this.equation2.getMax() - || this.axisOfRotation <= this.equation1.getMin() && this.axisOfRotation <= this.equation2.getMin()) + if(axisOfRotation >= this.equation1.getMax() && axisOfRotation >= this.equation2.getMax() + || axisOfRotation <= this.equation1.getMin() && axisOfRotation <= this.equation2.getMin()) { this.addBSP("abs(axis - y2)", "abs(axis - y2step)", "abs(axis - y1)", "abs(axis - y1step)"); } @@ -186,17 +186,17 @@ class Graph { //Not complete yet (this is just for cylinders) console.log("\t\tBoundY1 is equal to boundY2 and bound1 does not equal bound2"); - if(this.axisOfRotation > boundY1) + if(axisOfRotation > boundY1) { console.log("\t\t\tAxis of rotation is greater than boundY1"); this.addBSP("abs(axis - y1)", "abs(axis - y1step)", "abs(axis)", "abs(axis)"); } - else if(this.axisOfRotation < boundY1) + else if(axisOfRotation < boundY1) { console.log("\t\t\tAxis of rotation is less than boundY1"); this.addBSP("abs(axis)", "abs(axis)", "abs(axis) + y1", "abs(axis) + y1step"); } - else if(this.axisOfRotation === boundY1) + else if(axisOfRotation === boundY1) { console.log("\t\t\tAxis of rotation is equal to boundY1"); this.addSolidWithoutHoles("abs(y1)", "abs(y1step)"); @@ -223,14 +223,14 @@ class Graph step = bound2 - i; } - const smallCylinderGeom = new THREE.CylinderGeometry(smallGeoR1Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), - smallGeoR2Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), + const smallCylinderGeom = new THREE.CylinderGeometry(smallGeoR1Equation.eval({axis: axisOfRotation, y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), + smallGeoR2Equation.eval({axis: axisOfRotation, y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), step, 50); - smallCylinderGeom.rotateZ(Math.PI / 2).translate(i + step / 2, this.axisOfRotation, 0); - const largeCylinderGeom = new THREE.CylinderGeometry(bigGeoR1Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), - bigGeoR2Equation.eval({axis: this.axisOfRotation, y1: this.getY(i), y1step: this.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), + smallCylinderGeom.rotateZ(Math.PI / 2).translate(i + step / 2, axisOfRotation, 0); + const largeCylinderGeom = new THREE.CylinderGeometry(bigGeoR1Equation.eval({axis: axisOfRotation, y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), + bigGeoR2Equation.eval({axis: axisOfRotation, y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), step, 360); - largeCylinderGeom.rotateZ(Math.PI / 2).translate(i + step / 2, this.axisOfRotation, 0); + largeCylinderGeom.rotateZ(Math.PI / 2).translate(i + step / 2, axisOfRotation, 0); const smallCylinderBSP = new ThreeBSP(smallCylinderGeom); const largeCylinderBSP = new ThreeBSP(largeCylinderGeom); smallCylinderGeom.dispose(); @@ -256,8 +256,8 @@ class Graph step = bound2 - i; } - const geometry = new THREE.CylinderGeometry(leftRadiusEquation.eval({y1: this.getY(i), y1step: this.getY(i + step)}), - rightRadiusEquation.eval({y1: this.getY(i), y1step: this.getY(i + step)}), + const geometry = new THREE.CylinderGeometry(leftRadiusEquation.eval({y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step)}), + rightRadiusEquation.eval({y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step)}), step, 100); geometry.rotateZ(Math.PI / 2).translate(i + step / 2, axisOfRotation, 0); const plane = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial({color: 0xFFFF00/*, transparent: true, opacity: 0.5*/})); From 426944947320a540f99e320118be47ed82900fea Mon Sep 17 00:00:00 2001 From: Wliu Date: Thu, 15 Dec 2016 15:41:26 -0500 Subject: [PATCH 8/8] Fix merge --- js/graph.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/graph.js b/js/graph.js index 6ec088c..c7fbe98 100644 --- a/js/graph.js +++ b/js/graph.js @@ -288,8 +288,8 @@ class Graph step = bound2 - i; } - const smallCylinderGeom = new THREE.CylinderGeometry(smallGeoR1Equation.eval({axis: rotationAxis, y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), - smallGeoR2Equation.eval({axis: rotationAxis, y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), + const smallCylinderGeom = new THREE.CylinderGeometry(smallGeoR1Equation.eval({axis: rotationAxis, y1: this.equation1.getCoord(i), y1step: this.equation1.getCoord(i + step), y2: this.equation2.getCoord(i), y2step: this.equation2.getCoord(i + step)}), + smallGeoR2Equation.eval({axis: rotationAxis, y1: this.equation1.getCoord(i), y1step: this.equation1.getCoord(i + step), y2: this.equation2.getCoord(i), y2step: this.equation2.getCoord(i + step)}), step, 50); if(this.type === EquationType.EQUATION_Y) { @@ -300,8 +300,8 @@ class Graph smallCylinderGeom.rotateZ(Math.PI).translate(rotationAxis, i + step / 2, 0); } - const largeCylinderGeom = new THREE.CylinderGeometry(bigGeoR1Equation.eval({axis: rotationAxis, y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), - bigGeoR2Equation.eval({axis: rotationAxis, y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step), y2: this.equation2.getY(i), y2step: this.equation2.getY(i + step)}), + const largeCylinderGeom = new THREE.CylinderGeometry(bigGeoR1Equation.eval({axis: rotationAxis, y1: this.equation1.getCoord(i), y1step: this.equation1.getCoord(i + step), y2: this.equation2.getCoord(i), y2step: this.equation2.getCoord(i + step)}), + bigGeoR2Equation.eval({axis: rotationAxis, y1: this.equation1.getCoord(i), y1step: this.equation1.getCoord(i + step), y2: this.equation2.getCoord(i), y2step: this.equation2.getCoord(i + step)}), step, 360); if(this.type === EquationType.EQUATION_Y) { @@ -337,8 +337,8 @@ class Graph step = bound2 - i; } - const geometry = new THREE.CylinderGeometry(leftRadiusEquation.eval({y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step)}), - rightRadiusEquation.eval({y1: this.equation1.getY(i), y1step: this.equation1.getY(i + step)}), + const geometry = new THREE.CylinderGeometry(leftRadiusEquation.eval({y1: this.equation1.getCoord(i), y1step: this.equation1.getCoord(i + step)}), + rightRadiusEquation.eval({y1: this.equation1.getCoord(i), y1step: this.equation1.getCoord(i + step)}), step, 100); if(this.type === EquationType.EQUATION_Y) {