From b579bee774bfe496ededa24e2704fe21714af66b Mon Sep 17 00:00:00 2001 From: JimmyBinoculars <91781252+JimmyBinoculars@users.noreply.github.com> Date: Tue, 24 Oct 2023 08:41:55 +0100 Subject: [PATCH] Updates --- example/index.js | 46 +++++++++++----------- example/testing.js | 98 +++++++++++++++++++++++----------------------- sum.test.js | 28 ++++++------- 3 files changed, 86 insertions(+), 86 deletions(-) diff --git a/example/index.js b/example/index.js index 72dd6f5..dd4837f 100644 --- a/example/index.js +++ b/example/index.js @@ -1,40 +1,40 @@ -const lib = require("textvox3d"); +const lib = require('textvox3d'); function caliblrateViewportDimensions(camera, d, cubeSize) { const focalLength = camera.fl; const viewportHeight = 2 * cubeSize; const viewportWidth = (viewportHeight * d) / focalLength; - return { width: viewportWidth, height: viewportHeight }; + return {width: viewportWidth, height: viewportHeight}; } -let f = 0; -let camera = new lib.camera(55, 10, [7,-7,5], [64,0,47]); -let viewport = new lib.viewport(process.stdout.columns, process.stdout.rows-1); +const f = 0; +const camera = new lib.camera(55, 10, [7, -7, 5], [64, 0, 47]); +const viewport = new lib.viewport(process.stdout.columns, process.stdout.rows-1); -let cubeMesh = lib.getMesh("cube"); -let cube = new lib.item(cubeMesh, [0,0,0]/*pos*/, [0,0,0]/*rot*/, [2, 2, 2]/*scale*/); -//console.log(`Cube mesh: points: ${cubeMesh.points}, edges: ${cubeMesh.edges}`); +const cubeMesh = lib.getMesh('cube'); +const cube = new lib.item(cubeMesh, [0, 0, 0]/* pos*/, [0, 0, 0]/* rot*/, [2, 2, 2]/* scale*/); +// console.log(`Cube mesh: points: ${cubeMesh.points}, edges: ${cubeMesh.edges}`); -//console.log(`Columns: ${process.stdout.columns}, Rows: ${process.stdout.rows}`); +// console.log(`Columns: ${process.stdout.columns}, Rows: ${process.stdout.rows}`); function viewportTest() { - let i=0; - while (i= polygon[0][0] && x <= polygon[1][0] && y >= polygon[0][1] && y <= polygon[2][1]) { - return true; - }else { - return false; - } + // I know this only works for the square but if you are working on issue ticket #2 do not try to fix this unless it is what is causing the issue + if (x >= polygon[0][0] && x <= polygon[1][0] && y >= polygon[0][1] && y <= polygon[2][1]) { + return true; + } else { + return false; + } } -//The field of view of the viewport (in degrees) -let fov = 70; -//Square is formatted like this [[point], [point]] -let square = [[-0.25,4], [0.25, 4], [-0.25,6], [0.25,6]]; +// The field of view of the viewport (in degrees) +const fov = 70; +// Square is formatted like this [[point], [point]] +const square = [[-0.25, 4], [0.25, 4], [-0.25, 6], [0.25, 6]]; let y = 0; -//Max distance is set to low so it does not fill up the command prompt -let maxDistance = 10; -//Gets the dimentions of the viewport -let viewport = {"height":process.stdout.rows-1, "width":process.stdout.columns}; +// Max distance is set to low so it does not fill up the command prompt +const maxDistance = 10; +// Gets the dimentions of the viewport +const viewport = {'height': process.stdout.rows-1, 'width': process.stdout.columns}; console.log(viewport); let castAngle = 0; -//The current column that we are on +// The current column that we are on let column = 0; -//Columns where we have hit an object +// Columns where we have hit an object let columnHits = []; -while(castAngle<=degrees) { - //Calculate the exact angle that we need to cast at - castAngle = ((viewport.width/(fov*2))*column)-70; - //Convert the angle to a gradient for y=mx+c - let castTang = Math.tan(castAngle*(Math.PI/180)); - while(y { - expect(new lib.camera(70, 10, [7,-7,5], [64,0,47])).toEqual({"fov":70, "samples":10, "pos": [7,-7,5], "rot":[64,0,47]}); +test('Camera', () => { + expect(new lib.camera(70, 10, [7, -7, 5], [64, 0, 47])).toEqual({'fov': 70, 'samples': 10, 'pos': [7, -7, 5], 'rot': [64, 0, 47]}); }); -test("Mesh", () => { - expect(new lib.mesh([1,1,1], [1,1,1], [1,1,1])).toEqual({"points":[1,1,1], "edges":[1,1,1], "faces":[1,1,1]}) +test('Mesh', () => { + expect(new lib.mesh([1, 1, 1], [1, 1, 1], [1, 1, 1])).toEqual({'points': [1, 1, 1], 'edges': [1, 1, 1], 'faces': [1, 1, 1]}); }); -test("Item", () => { - expect(new lib.item("cube", [1,1,1], [0,0,0])).toEqual({"mesh":"cube", "pos":[1,1,1], "rot":[0,0,0]}) +test('Item', () => { + expect(new lib.item('cube', [1, 1, 1], [0, 0, 0])).toEqual({'mesh': 'cube', 'pos': [1, 1, 1], 'rot': [0, 0, 0]}); }); -test("Viewport", () => { - expect(new lib.viewport(100, 100)).toEqual({"width":100, "height":100}) +test('Viewport', () => { + expect(new lib.viewport(100, 100)).toEqual({'width': 100, 'height': 100}); }); -test("Repeat string func", () => { - expect(lib.repeatStringNumTimes("a", 3)).toEqual("aaa") +test('Repeat string func', () => { + expect(lib.repeatStringNumTimes('a', 3)).toEqual('aaa'); +}); +test('Get Mesh', () => { + expect(lib.getMesh('cube')).toEqual({'points': [[1, 1, 1], [-1, 1, 1], [-1, -1, 1], [1, -1, 1], [1, -1, -1], [1, 1, -1], [-1, -1, -1], [-1, 1, -1]], 'edges': [[0, 1], [0, 5], [0, 3], [1, 2], [1, 7], [2, 3], [2, 6], [3, 4], [4, 5], [4, 6], [5, 7], [7, 6]], 'faces': [[1, 3, 5, 2], [2, 8, 3, 7], [7, 5, 9, 6], [0, 4, 1, 10], [3, 4, 6, 11]]}); }); -test("Get Mesh", () => { - expect(lib.getMesh("cube")).toEqual({"points":[[1,1,1], [-1,1,1], [-1,-1,1], [1,-1,1], [1,-1,-1], [1,1,-1], [-1,-1,-1], [-1,1,-1]], "edges":[[0,1], [0,5], [0,3], [1,2], [1,7], [2,3], [2,6], [3,4], [4,5], [4,6], [5,7], [7,6]], "faces":[[1,3,5,2], [2,8,3,7], [7,5,9,6], [0,4,1,10], [3,4,6,11]]}) -}); \ No newline at end of file