From 22ee26b6f24a35275a7069cccd3806f066e37eeb Mon Sep 17 00:00:00 2001 From: niekes Date: Sat, 24 Feb 2018 14:13:54 +0100 Subject: [PATCH] fix Rectangular 3d surface #1 --- package.json | 2 +- src/centroid.js | 5 +---- src/draw/drawTriangle.js | 8 +------- src/primitiveShapes/gridPlane.js | 2 +- src/primitiveShapes/triangle.js | 2 -- src/rotation.js | 9 +++------ test/3d-test.js | 4 ++-- 7 files changed, 9 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index ba1cd95..a1e6438 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "d3-3d", - "version": "0.0.7", + "version": "0.0.8", "description": "D3.js plugin for 3d visualization", "keywords": [ "d3", diff --git a/src/centroid.js b/src/centroid.js index 5029c06..8a3aad8 100644 --- a/src/centroid.js +++ b/src/centroid.js @@ -1,14 +1,11 @@ export function centroid(polygon){ - - var _x = 0, _y = 0, _z = 0; - var _n = polygon.length; + var _x = 0, _y = 0, _z = 0, _n = polygon.length; for (var i = _n - 1; i >= 0; i--) { _x += polygon[i].rotated.x; _y += polygon[i].rotated.y; _z += polygon[i].rotated.z; } - return { x: _x/_n, y: _y/_n, diff --git a/src/draw/drawTriangle.js b/src/draw/drawTriangle.js index 3bffbac..b1daa6a 100644 --- a/src/draw/drawTriangle.js +++ b/src/draw/drawTriangle.js @@ -1,9 +1,3 @@ export function drawTriangle(d){ - return "M" + d[0].projected.x + - "," + d[0].projected.y + - "L" + d[1].projected.x + - "," + d[1].projected.y + - "L" + d[2].projected.x + - "," + d[2].projected.y + - "Z"; + return 'M' + d[0].projected.x + ',' + d[0].projected.y + 'L' + d[1].projected.x + ',' + d[1].projected.y + 'L' + d[2].projected.x + ',' + d[2].projected.y + 'Z'; } diff --git a/src/primitiveShapes/gridPlane.js b/src/primitiveShapes/gridPlane.js index de4bf70..d19ecf1 100644 --- a/src/primitiveShapes/gridPlane.js +++ b/src/primitiveShapes/gridPlane.js @@ -12,7 +12,7 @@ export function gridPlane(grid, options, point, angles){ for (var i = numRow - 1; i > 0; i--) { for (var j = numPts - 1; j > 0; j--) { - var p1 = j + i * numRow, p4 = p1 - 1, p2 = p4 - numRow + 1, p3 = p2 - 1; + var p1 = j + i * numPts, p4 = p1 - 1, p2 = p4 - numPts + 1, p3 = p2 - 1; var pl = [points[p1], points[p2], points[p3], points[p4]]; pl.plane = 'plane_' + cnt++; diff --git a/src/primitiveShapes/triangle.js b/src/primitiveShapes/triangle.js index b4a4dc4..1283001 100644 --- a/src/primitiveShapes/triangle.js +++ b/src/primitiveShapes/triangle.js @@ -5,9 +5,7 @@ import {rotateRzRyRx} from '../rotation'; export function triangle(triangles, options, point, angles){ for (var i = triangles.length - 1; i >= 0; i--) { - var tri = triangles[i]; - var p1 = tri[0]; var p2 = tri[1]; var p3 = tri[2]; diff --git a/src/rotation.js b/src/rotation.js index 36fb694..2aac21c 100644 --- a/src/rotation.js +++ b/src/rotation.js @@ -18,8 +18,7 @@ export function rotateRzRyRx(po, angles){ } function rotateX(p, a){ - var sa = Math.sin(a); - var ca = Math.cos(a); + var sa = Math.sin(a), ca = Math.cos(a); return { x: p.x, y: p.y * ca - p.z * sa, @@ -28,8 +27,7 @@ function rotateX(p, a){ } function rotateY(p, a){ - var sa = Math.sin(a); - var ca = Math.cos(a); + var sa = Math.sin(a), ca = Math.cos(a); return { x: p.z * sa + p.x * ca, y: p.y, @@ -38,8 +36,7 @@ function rotateY(p, a){ } function rotateZ(p, a){ - var sa = Math.sin(a); - var ca = Math.cos(a); + var sa = Math.sin(a), ca = Math.cos(a); return { x: p.x * ca - p.y * sa, y: p.y * sa + p.y * ca, diff --git a/test/3d-test.js b/test/3d-test.js index 7840b2b..9bb2b0e 100644 --- a/test/3d-test.js +++ b/test/3d-test.js @@ -1,14 +1,14 @@ var tape = require('tape'); var d3 = require('../'); -tape('_3d has expected defaults', function(test) { +tape("d3-3d has expected defaults", function(test) { var _3d = d3._3d(); test.deepEqual(_3d.origin(), [0, 0]); test.equal(_3d.scale(), 1); test.equal(_3d.rotateX(), 0); test.equal(_3d.rotateY(), 0); test.equal(_3d.rotateZ(), 0); - test.equal(_3d.shape(), 'POINT'); + test.equal(_3d.shape(), "POINT"); test.deepEqual(_3d.rotateCenter(), [0,0,0]); test.end(); });