Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lampese committed Jul 23, 2023
1 parent cf077fc commit 4b68952
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 56 deletions.
48 changes: 24 additions & 24 deletions .github/workflows/core-release.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
name: core-release

on:
push:
branches: ["core"]
paths:
- "package.json"
push:
branches: ['core']
paths:
- 'package.json'

jobs:
build:
runs-on: ubuntu-latest
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [19.x]
strategy:
matrix:
node-version: [19.x]

steps:
- uses: actions/checkout@v3
with:
ref: core
steps:
- uses: actions/checkout@v3
with:
ref: core

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org

- name: Build
run: tsc
- name: Build
run: tsc

- name: Publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.LAMPESE_PUSSY}}
- name: Publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.LAMPESE_PUSSY}}
27 changes: 27 additions & 0 deletions .github/workflows/core-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: core-release

on:
push:
branches: ['core']

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [19.x]

steps:
- uses: actions/checkout@v3
with:
ref: core

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org

- name: Build
run: tsc
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules
build
package-lock.json
.directory
scripts/src/pureeval
test/node_modules
test/*
Expand Down
43 changes: 13 additions & 30 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,18 @@ function torus(radius: number, ringRadius: number): Vec3[] {
function voxelLine(p1: Vec3, p2: Vec3): Vec3[] {
const [x1, y1, z1] = [p1.x, p1.y, p1.z];
const [x2, y2, z2] = [p2.x, p2.y, p2.z];
let dy = y2 - y1;
let dx = x2 - x1;
let dz = z2 - z1;
const qChange = [dx < 0 ? -1 : 1, dy < 0 ? -1 : 1, dz < 0 ? -1 : 1];
dx = Math.abs(dx);
dy = Math.abs(dy);
dz = Math.abs(dz);
let largestChange;
if (dy >= dz && dy >= dx) {
largestChange = 1;
} else if (dx >= dy && dx >= dz) {
largestChange = 0;
} else {
largestChange = 2;
}
let [dx, dy, dz] = [x2 - x1, y2 - y1, z2 - z1];
const qChange = [dx, dy, dz].map(Math.sign);
[dx, dy, dz] = [dx, dy, dz].map(Math.abs);

const largestChange = [dy, dx, dz].indexOf(Math.max(dy, dx, dz));
const largestTarget = Math.max(dy, dx, dz);
const startAxis = largestChange === 1 ? y1 : largestChange === 0 ? x1 : z1;
let x = x1;
let y = y1;
let z = z1;
const startAxis = [x1, y1, z1][largestChange];

let [x, y, z] = [x1, y1, z1];
const points: Vec3[] = [];
let rx = 0;
let ry = 0;
let rz = 0;
let [rx, ry, rz] = [0, 0, 0];

const endCoord =
qChange[largestChange] === 1 ? startAxis + largestTarget : startAxis - largestTarget;
for (
Expand All @@ -100,9 +88,7 @@ function voxelLine(p1: Vec3, p2: Vec3): Vec3[] {
ry += dy;
rz += dz;
points.push(put([i, y, z]));
continue;
}
if (largestChange === 1) {
} else if (largestChange === 1) {
if (rx >= dy) {
rx -= dy;
x += qChange[0];
Expand All @@ -114,9 +100,7 @@ function voxelLine(p1: Vec3, p2: Vec3): Vec3[] {
rx += dx;
rz += dz;
points.push(put([x, i, z]));
continue;
}
if (largestChange === 2) {
} else if (largestChange === 2) {
if (rx >= dz) {
rx -= dz;
x += qChange[2];
Expand All @@ -125,10 +109,9 @@ function voxelLine(p1: Vec3, p2: Vec3): Vec3[] {
ry -= dz;
y += qChange[1];
}
ry += dy;
rx += dx;
ry += dy;
points.push(put([x, y, i]));
continue;
}
}
return points;
Expand Down
4 changes: 2 additions & 2 deletions src/turtle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ class Turtle3D {

pop() {
const state = this.stack.pop();
this.pos = state!.pos;
this.mat = state!.mat;
this.pos = state.pos;
this.mat = state.mat;
}

push() {
Expand Down

0 comments on commit 4b68952

Please sign in to comment.