Skip to content

Commit

Permalink
fix Rectangular 3d surface #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Niekes committed Feb 24, 2018
1 parent c64e8eb commit 22ee26b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-3d",
"version": "0.0.7",
"version": "0.0.8",
"description": "D3.js plugin for 3d visualization",
"keywords": [
"d3",
Expand Down
5 changes: 1 addition & 4 deletions src/centroid.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 1 addition & 7 deletions src/draw/drawTriangle.js
Original file line number Diff line number Diff line change
@@ -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';
}
2 changes: 1 addition & 1 deletion src/primitiveShapes/gridPlane.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
2 changes: 0 additions & 2 deletions src/primitiveShapes/triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
9 changes: 3 additions & 6 deletions src/rotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/3d-test.js
Original file line number Diff line number Diff line change
@@ -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();
});
Expand Down

0 comments on commit 22ee26b

Please sign in to comment.