commit 23a4d1465dc521b5c6112ad0e35ba3502af8f8f5
parent 0165fecf0310dbaf3c2a06897a1e4d708e398e04
Author: mjkloeckner <martinjkloeckner@gmail.com>
Date: Thu, 14 Mar 2024 12:16:34 -0300
Replace switch case
Diffstat:
M | main.js | | | 57 | +++++++++++++-------------------------------------------- |
1 file changed, 13 insertions(+), 44 deletions(-)
diff --git a/main.js b/main.js
@@ -66,50 +66,19 @@ function addGeometries() {
towersGeometry[i] = new t.CylinderGeometry(towerR, towerR, towerH, 40, 40);
towersSpireGeometry[i] = new t.ConeGeometry(towerSpireR, towerSpireH, 40);
- switch(i) {
- case 0:
- towersGeometry[i].translate(
- houseW/2-(towerR*2/3),
- towerH/2,
- houseD/2-(towerR*2/3));
- towersSpireGeometry[i].translate(
- houseW/2-(towerR*2/3),
- towerH + (towerSpireH/2),
- houseD/2-(towerR*2/3));
- break;
- case 1:
- towersGeometry[i].translate(
- -(houseW/2-(towerR*2/3)),
- towerH/2,
- houseD/2-(towerR*2/3));
- towersSpireGeometry[i].translate(
- -(houseW/2-(towerR*2/3)),
- towerH + (towerSpireH/2),
- houseD/2-(towerR*2/3));
- break;
- case 2:
- towersGeometry[i].translate(
- -(houseW/2-(towerR*2/3)),
- towerH/2,
- -(houseD/2-(towerR*2/3)));
- towersSpireGeometry[i].translate(
- -(houseW/2-(towerR*2/3)),
- towerH + (towerSpireH/2),
- -(houseD/2-(towerR*2/3)));
- break;
- case 3:
- towersGeometry[i].translate(
- houseW/2-(towerR*2/3),
- towerH/2,
- -(houseD/2-(towerR*2/3)));
- towersSpireGeometry[i].translate(
- houseW/2-(towerR*2/3),
- towerH + (towerSpireH/2),
- -(houseD/2-(towerR*2/3)));
- break;
- default:
- console.log(`Out of bounds: towersGeometry[${expr}]`);
- }
+ // 0 -> 00
+ // 1 -> 01
+ // 2 -> 10
+ // 3 -> 11
+ towersGeometry[i].translate(
+ ((-1)**(i>>1))*(houseW/2-(towerR*2/3)),
+ towerH/2,
+ ((-1)**(i&1))*(houseD/2-towerR*2/3));
+
+ towersSpireGeometry[i].translate(
+ ((-1)**(i>>1))*(houseW/2-towerR*2/3),
+ towerH + (towerSpireH/2),
+ ((-1)**(i&1))*(houseD/2-towerR*2/3));
}
const towerMaterial = new t.MeshPhongMaterial();