Skip to content

Commit

Permalink
remove polygon and add coce coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Niekes committed Sep 12, 2017
1 parent 6c84757 commit c64e8eb
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 52 deletions.
4 changes: 0 additions & 4 deletions src/3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import {lineStrip} from './primitiveShapes/lineStrip';
import {line} from './primitiveShapes/line';
import {plane} from './primitiveShapes/plane';
import {point} from './primitiveShapes/point';
import {polygon} from './primitiveShapes/polygon';
import {triangle} from './primitiveShapes/triangle';

import {drawLineStrip} from './draw/drawLineStrip';
import {drawPlane} from './draw/drawPlane';
import {drawPolygon} from './draw/drawPolygon';
import {drawTriangle} from './draw/drawTriangle';

import {orthographic} from './projection-orthographic';
Expand Down Expand Up @@ -41,7 +39,6 @@ export default function() {
'LINE_STRIP' : lineStrip,
'PLANE' : plane,
'POINT' : point,
'POLYGON' : polygon,
'SURFACE' : gridPlane,
'TRIANGLE' : triangle,
},
Expand All @@ -50,7 +47,6 @@ export default function() {
'GRID' : drawPlane,
'LINE_STRIP' : drawLineStrip,
'PLANE' : drawPlane,
'POLYGON' : drawPolygon,
'SURFACE' : drawPlane,
'TRIANGLE' : drawTriangle,
};
Expand Down
2 changes: 0 additions & 2 deletions src/primitiveShapes/lineStrip.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ export function lineStrip(lineStrip, options, point, angles){

l.centroid = t === m ? centroid([ l[m - 1], l[m] ]) : { x: l[t].rotated.x, y: l[t].rotated.y, z: l[t].rotated.z };
}


return lineStrip;
}
34 changes: 34 additions & 0 deletions test/3d-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ tape('set origin', function(test) {
test.end();
});

tape('set rotateCenter', function(test) {
var _3d = d3._3d().rotateCenter([100, 100, 100]);
test.deepEqual(_3d.rotateCenter(), [100, 100, 100]);
test.end();
});

tape('set scale', function(test) {
var _3d1 = d3._3d();
var _3d2 = d3._3d().scale(2);
Expand All @@ -45,3 +51,31 @@ tape('set angles', function(test){
test.equal(_3d.rotateZ(), 3/2*Math.PI);
test.end();
});

tape('test x,y,z accesor', function(test){
var cubes3D = d3._3d().shape('CUBE').x(function(d){ return d.x; }).y(function(d){ return d.y; }).z(function(d){ return d.z; });

test.equal(typeof cubes3D.x(), 'function');
test.equal(typeof cubes3D.y(), 'function');
test.equal(typeof cubes3D.z(), 'function');
cubes3D.x(1);
cubes3D.y(1);
cubes3D.z(1);
test.deepEqual(cubes3D.x(), 1);
test.deepEqual(cubes3D.y(), 1);
test.deepEqual(cubes3D.z(), 1);

test.end();
});

tape('test ascending sorting', function(test){

test.deepEqual(d3._3d().sort({centroid: { z: 1 } }, {centroid: { z:10 } }), -1);
test.deepEqual(d3._3d().sort({centroid: { z:10 } }, {centroid: { z: 1 } }), 1);
test.deepEqual(d3._3d().sort({centroid: { z: 1 } }, {centroid: { z: 1 } }), 0);
test.deepEqual(d3._3d().sort({centroid: { z: 1 } }, {centroid: { z:'1'} }), 0);
test.deepEqual(isNaN(d3._3d().sort({centroid: { z: function(){ return false ;} } }, {centroid: { z:false} })), true);

test.end();

});
2 changes: 0 additions & 2 deletions test/cube-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ tape('cube naming is correct', function(test){
]
];

console.log(cubes(data)[0].faces);

test.equal(cubes(data)[0].faces[0].face, 'front');
test.equal(cubes(data)[0].faces[1].face, 'back');
test.equal(cubes(data)[0].faces[2].face, 'left');
Expand Down
55 changes: 55 additions & 0 deletions test/linestrip-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var tape = require('tape');
var d3 = require('../');

tape('linestrip draws correctly', function(test){

var data = [
[ 3,5,2],
[ 2,45,2],
[ 1,1,2],
[ 0,9,3],
[-1,3,2],
[-2,8,4],
[-3,0,2],
];

var ls3D = d3._3d()
.scale(30)
.origin([220,340])
.shape('LINE_STRIP');

test.equal(ls3D.draw(ls3D([data])[0]), 'M130,340L160,580L190,430L220,610L250,370L280,1690L310,490');
test.end();
});

tape('centroid calculation for linesstrip', function(test){

var data = [
[ 3,5,2],
[ 2,45,2],
[ 1,1,2],
[ 0,9,3],
[-1,3,2],
[-2,8,4],
[-3,0,2],
];

var data2 = [
[ 3,5,2],
[ 2,45,2],
[ 1,1,2],
[ 0,9,3],
[-1,3,2],
[-2,8,4],
];

var ls3D = d3._3d()
.scale(30)
.origin([220,340])
.shape('LINE_STRIP');

test.deepEqual(ls3D([data])[0].centroid, {x: 0, y: 9, z: 3});
test.deepEqual(ls3D([data2])[0].centroid, { x: 0.5, y: 5, z: 2.5 });

test.end();
});
44 changes: 0 additions & 44 deletions test/polygons-test.js

This file was deleted.

0 comments on commit c64e8eb

Please sign in to comment.