Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update p5.Camera.js
  • Loading branch information
Forchapeatl authored Apr 6, 2025
commit f7c9c8c3b80451689bc6844a03f2586f9ee18126
54 changes: 35 additions & 19 deletions test/unit/webgl/p5.Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,48 @@
};

// Initialize the camera and set up the p5 instance
setup(function() {
myp5 = new p5();
myCam = myp5.camera;
myp5._renderer = { _pInst: myp5 }; // Simulate the renderer
beforeAll(function() {
myp5 = new p5(function(p) {
p.setup = function() {
p.createCanvas(100, 100, p.WEBGL);
myCam = p.createCamera();
};
});
});

afterAll(function() {
myp5.remove();
});

beforeEach(function() {
myp5.angleMode(myp5.RADIANS);

// Set camera defaults
myCam.camera(
0,
0,
100 / 2.0 / Math.tan(Math.PI * 30.0 / 180.0),
0,
0,
0,
0,
1,
0
);
myCam.perspective(
Math.PI / 3.0,
1,
myCam.eyeZ / 10.0,
myCam.eyeZ * 10.0
);
myp5.setCamera(myCam);
});

// Test: Camera starts with correct initial values
test('Camera initial values', function() {
var vals = getVals(myCam);
assert.closeTo(vals.ex, 0, delta);
assert.closeTo(vals.ey, 0, delta);
assert.closeTo(vals.ez, 500, delta);

Check failure on line 354 in test/unit/webgl/p5.Camera.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera Tilt and Up Vector > Camera initial values

AssertionError: expected 86.60254037844388 to be close to 500 +/- 0.001 ❯ test/unit/webgl/p5.Camera.js:354:14
assert.closeTo(vals.cx, 0, delta);
assert.closeTo(vals.cy, 0, delta);
assert.closeTo(vals.cz, 0, delta);
Expand All @@ -330,69 +360,55 @@
assert.closeTo(vals.uz, 0, delta);
});

// Test: Camera rotation around a given axis (e.g., X-axis) while maintaining the up vector orientation
test('Camera rotation around X-axis', function() {
myCam._rotateView(90, 1, 0, 0); // Rotate by 90 degrees around X-axis

var vals = getVals(myCam);
// Check that the center's Y value changes but the up vector remains consistent
assert.notCloseTo(vals.cy, 0, delta); // Y center should change

Check failure on line 367 in test/unit/webgl/p5.Camera.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera Tilt and Up Vector > Camera rotation around X-axis

TypeError: assert.notCloseTo is not a function ❯ test/unit/webgl/p5.Camera.js:367:14
assert.closeTo(vals.ux, 0, delta); // X up vector should stay the same
assert.closeTo(vals.uy, 0, delta); // Y up vector should change
assert.closeTo(vals.uz, 1, delta); // Z up vector should stay the same
});

// Test: Camera rotation around Y-axis, checking up vector normalization
test('Camera rotation around Y-axis', function() {
myCam._rotateView(90, 0, 1, 0); // Rotate by 90 degrees around Y-axis

var vals = getVals(myCam);
// Ensure the up vector is normalized
var upLength = Math.sqrt(vals.ux * vals.ux + vals.uy * vals.uy + vals.uz * vals.uz);
assert.closeTo(upLength, 1, delta); // Check if up vector is normalized to 1
});

// Test: Rotation around the eye position
test('Camera rotation around eye position', function() {
myCam.eyeX = 100;
myCam.eyeY = 100;
myCam.eyeZ = 100;

// Rotate by 90 degrees around Z-axis
myCam._rotateView(90, 0, 0, 1);

var vals = getVals(myCam);
assert.notCloseTo(vals.cx, 0, delta); // The center should have changed after rotation

Check failure on line 389 in test/unit/webgl/p5.Camera.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera Tilt and Up Vector > Camera rotation around eye position

TypeError: assert.notCloseTo is not a function ❯ test/unit/webgl/p5.Camera.js:389:14
assert.notCloseTo(vals.cy, 0, delta);
assert.notCloseTo(vals.cz, 0, delta);
});

// Edge case: No rotation
test('No rotation results in no change', function() {
var initialVals = getVals(myCam);

myCam._rotateView(0, 0, 0, 0); // No rotation

var finalVals = getVals(myCam);
assert.deepEqual(initialVals, finalVals); // Values should remain the same

Check failure on line 398 in test/unit/webgl/p5.Camera.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera Tilt and Up Vector > No rotation results in no change

AssertionError: expected { ex: +0, ey: +0, …(7) } to deeply equal { ex: +0, ey: +0, …(7) } - Expected + Received Object { - "cx": NaN, - "cy": NaN, - "cz": NaN, + "cx": 0, + "cy": 0, + "cz": 0, "ex": 0, "ey": 0, "ez": 86.60254037844388, - "ux": NaN, - "uy": NaN, - "uz": NaN, + "ux": 0, + "uy": 1, + "uz": 0, } ❯ test/unit/webgl/p5.Camera.js:398:14
});

// Edge case: Very small rotation
test('Very small rotation', function() {
myCam._rotateView(0.001, 0, 1, 0); // Small rotation around Y-axis

var vals = getVals(myCam);
assert.closeTo(vals.cy, 0, delta); // Y center should remain almost the same
});

// Edge case: Extreme rotation (e.g., 360 degrees)
test('Extreme rotation (360 degrees)', function() {
var initialVals = getVals(myCam);

myCam._rotateView(360, 0, 1, 0); // 360-degree rotation around Y-axis

var finalVals = getVals(myCam);
assert.deepEqual(initialVals, finalVals); // Values should be almost identical after a full rotation

Check failure on line 411 in test/unit/webgl/p5.Camera.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera Tilt and Up Vector > Extreme rotation (360 degrees)

AssertionError: expected { ex: +0, ey: +0, …(7) } to deeply equal { ex: +0, ey: +0, …(7) } - Expected + Received Object { - "cx": -83.04453653370267, + "cx": 0, "cy": 0, - "cz": 111.17090845270192, + "cz": 0, "ex": 0, "ey": 0, "ez": 86.60254037844388, "ux": 0, "uy": 1, "uz": 0, } ❯ test/unit/webgl/p5.Camera.js:411:14
});
});

Expand Down
Loading