Skip to content

Commit bf30801

Browse files
authored
Merge pull request #754 from hackclub/revert-717-assertions
Revert "Significantly improve error messages"
2 parents da61aa5 + 42a544f commit bf30801

21 files changed

+23
-348
lines changed

src/drawingToolkit/Turtle.js

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { translatePt, rotatePt } from "./affineTransformations.js";
2-
import { assertArgs } from './assert.js'
32

43
const copy = obj => JSON.parse(JSON.stringify(obj))
54

65
export class Turtle {
76

87
constructor() {
9-
assertArgs(arguments, [], 'new bt.Turtle')
10-
118
this.drawing = true
129
this.position = [ 0, 0 ]
1310
this.angle = 0
@@ -18,24 +15,18 @@ export class Turtle {
1815
}
1916

2017
up() {
21-
assertArgs(arguments, [], 'turtle.up')
22-
2318
if (!this.drawing) return this
2419
this.drawing = false
2520
this.path.push([[...this.position]])
2621
return this
2722
}
2823

2924
down() {
30-
assertArgs(arguments, [], 'turtle.down')
31-
3225
this.drawing = true
3326
return this
3427
}
3528

3629
goTo([x, y]) {
37-
assertArgs(arguments, ['point'], 'turtle.goTo')
38-
3930
const lastPath = this.path.at(-1)
4031
if (this.drawing) {
4132
const [lastX, lastY] = this.position
@@ -51,9 +42,7 @@ export class Turtle {
5142
return this
5243
}
5344

54-
step([dx, dy]) {
55-
assertArgs(arguments, ['point'], 'turtle.step')
56-
45+
step([dx, dy]) { // document this
5746
const [x, y] = this.position;
5847

5948
this.goTo([
@@ -65,8 +54,6 @@ export class Turtle {
6554
}
6655

6756
jump(pt) {
68-
assertArgs(arguments, ['point'], 'turtle.jump')
69-
7057
const [x, y] = pt;
7158
const lastPath = this.path.at(-1);
7259
if (lastPath.length === 1) {
@@ -82,8 +69,6 @@ export class Turtle {
8269
}
8370

8471
forward(distance) {
85-
assertArgs(arguments, ['number'], 'turtle.forward')
86-
8772
const last = this.position
8873
const a = (this.angle / 180) * Math.PI
8974
const x = last[0] + distance * Math.cos(a)
@@ -95,8 +80,6 @@ export class Turtle {
9580
}
9681

9782
arc(angle, radius) {
98-
assertArgs(arguments, ['number', 'number'], 'turtle.arc')
99-
10083
if (angle === 0 || radius === 0) return this;
10184

10285
const n = 64;
@@ -135,8 +118,6 @@ export class Turtle {
135118

136119
// setHeading?
137120
setAngle(theta) {
138-
assertArgs(arguments, ['number'], 'turtle.setAngle')
139-
140121
this.angle = theta
141122

142123
return this
@@ -147,33 +128,25 @@ export class Turtle {
147128
// }
148129

149130
right(theta) {
150-
assertArgs(arguments, ['number'], 'turtle.right')
151-
152131
this.angle -= theta
153132

154133
return this
155134
}
156135

157136
left(theta) {
158-
assertArgs(arguments, ['number'], 'turtle.left')
159-
160137
this.angle += theta
161138

162139
return this
163140
}
164141

165142
lines() { // could be called polylines
166-
assertArgs(arguments, [], 'turtle.lines')
167-
168143
const pls = copy(this.path);
169144

170145
return pls.filter(pl => pl.length > 1);
171146
}
172147

173148

174149
copy() {
175-
assertArgs(arguments, [], 'turtle.copy')
176-
177150
const t = new Turtle()
178151

179152
t.path = copy(this.path)
@@ -185,16 +158,12 @@ export class Turtle {
185158
}
186159

187160
applyToPath(fn) {
188-
assertArgs(arguments, ['function'], 'turtle.applyToPath')
189-
190161
fn(this.path);
191162
return this;
192163
}
193164

194165
// undoced
195166
apply(fn) {
196-
assertArgs(arguments, ['function'], 'turtle.apply')
197-
198167
fn(this);
199168
return this;
200169
}

src/drawingToolkit/affineTransformations.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import { assertArgs } from "./assert.js";
21
import { bounds } from "./bounds.js";
32

4-
export function translate(polylines, to, origin = [0, 0]) {
5-
assertArgs(arguments, ['polylines', 'point', 'point?'], 'bt.translate')
6-
3+
export const translate = (polylines, to, origin = [0, 0]) => {
74
polylines.flat().forEach(pt => {
85
const [x, y] = translatePt(pt, to, origin);
96
pt[0] = x;
@@ -13,9 +10,7 @@ export function translate(polylines, to, origin = [0, 0]) {
1310
return polylines;
1411
}
1512

16-
export function rotate(polylines, angle, origin) {
17-
assertArgs(arguments, ['polylines', 'number', 'point?'], 'bt.rotate')
18-
13+
export const rotate = (polylines, angle, origin) => {
1914
if (!origin) origin = bounds(polylines).cc
2015

2116
polylines.flat().forEach(pt => {
@@ -27,9 +22,7 @@ export function rotate(polylines, angle, origin) {
2722
return polylines
2823
}
2924

30-
export function scale(polylines, factor, origin) {
31-
assertArgs(arguments, ['polylines', ['number', 'point'], 'point?'], 'bt.scale')
32-
25+
export const scale = (polylines, factor, origin) => {
3326
if (!origin) origin = bounds(polylines).cc
3427

3528
polylines.flat().forEach(pt => {

src/drawingToolkit/assert.js

Lines changed: 0 additions & 113 deletions
This file was deleted.

src/drawingToolkit/bounds.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { assertArgs } from './assert'
21

32
export function bounds(polylines) {
4-
assertArgs(arguments, ['polylines'], 'bt.bounds');
5-
63
const { xMin, xMax, yMin, yMax } = extrema(polylines.flat());
74

85
const width = xMax - xMin;

src/drawingToolkit/catmullRom.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { assertArgs } from './assert'
2-
31
export function catmullRom(controlPoints, segments = 100) {
4-
assertArgs(arguments, ['polyline', 'number?'], 'bt.catmullRom');
5-
62
const isClosed = (points) => {
73
const start = points[0];
84
const end = points[points.length - 1];

src/drawingToolkit/cutCover.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { bounds } from "./bounds.js";
22
import { pointInPolylines } from "./pointInPolylines.js"
33
import { mergePolylines } from "./mergePolylines.js";
4-
import { assertArgs } from "./assert.js";
5-
6-
export function cut(polylines0, polylines1, assumeClosed = true) {
7-
assertArgs(arguments, ['polylines', 'polylines', 'boolean?'], 'bt.cut');
84

5+
export const cut = (polylines0, polylines1, assumeClosed = true) => {
96
if (assumeClosed) polylines1.forEach(poly => {
107
const [x, y] = poly.at(0);
118
poly.push([x, y]);
@@ -28,9 +25,7 @@ export function cut(polylines0, polylines1, assumeClosed = true) {
2825
return polylines0;
2926
};
3027

31-
export function cover(polylines0, polylines1, assumeClosed = true) {
32-
assertArgs(arguments, ['polylines', 'polylines', 'boolean?'], 'bt.cover');
33-
28+
export const cover = (polylines0, polylines1, assumeClosed = true) => {
3429
if (assumeClosed) polylines1.forEach(poly => {
3530
const [x, y] = poly.at(0);
3631
poly.push([x, y]);

src/drawingToolkit/getAngleAtT.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { assertArgs } from './assert'
2-
31
export function getAngleAtT(polylines, t) {
4-
assertArgs(arguments, ['polylines', 'number'], 'bt.getAngle')
5-
62
// Calculate the total length of all polylines
73
let totalLength = 0
84
let lengths = polylines.map(polyline => {

src/drawingToolkit/getNormalAtT.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { assertArgs } from './assert'
2-
31
export function getNormalAtT(polylines, t) {
4-
assertArgs(arguments, ['polylines', 'number'], 'bt.getNormal')
5-
62
// Calculate the total length of all polylines
73
let totalLength = 0
84
let lengths = polylines.map(polyline => {

src/drawingToolkit/getPointAtT.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { assertArgs } from './assert'
2-
31
export function getPointAtT(polylines, t) {
4-
assertArgs(arguments, ['polylines', 'number'], 'bt.getPoint')
5-
62
t = Math.max(t, 0)
73
t = Math.min(t, 1)
84

src/drawingToolkit/iteratePolylines.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { assertArgs } from './assert'
2-
31
export function iteratePolylines(polylines, fn) {
4-
assertArgs(arguments, ['polylines', 'function'], 'bt.iteratePoints')
5-
62
const toRemove = new Set()
73
const toBreak = new Set()
84

0 commit comments

Comments
 (0)