hackclub / hackclub/blot

Fix trimPolylines function

Open
#622 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
346
Forks
475
PR merge metrics
No merged PRs in 30d

Description

Currently, the bt.trim() function does not handle polylines correctly. In the following example, as you change the values of `t1` and `t2`, the drawing appears to loop the first line of each square until at each corner.
```Javascript
/*
This is a modified version of the following submission:

@title: square disarray
@author: leomcelroy
@snapshot: 0.png
*/

const width = 120;
const height = 120;

const gridsize = 2; //smallest grid array

setDocDimensions(width, height);

const finalLines = []; // we'll put our final lines here

const squareWidth = 10
const squareHeight = 10

for (let i = 0; i < gridsize; i++) {
for (let j = 0; j < gridsize; j++) {
const square = rect(squareWidth, squareHeight);
bt.translate(
square,
[
(squareWidth) * i,
(squareHeight) * j
]
);

bt.join(finalLines, square);
}
}

bt.trim(finalLines, 0.00, 0.04);

drawLines(finalLines);

function rect(w, h) {

// notice how this is an array of arrays
return [
[
[-w/2, h/2],
[w/2, h/2],
[w/2, -h/2],
[-w/2, -h/2],
[-w/2, h/2],
]
]
}
```
Ideally, bt.trim() would not loop between the first elements of each array in the finalLines array.

Contributor guide

Open the contributing guide

Research direction

Start by running the provided square-disarray example and inspecting the implementation of bt.trim(), focusing on how it processes the nested polyline arrays. Done means changing t1 and t2 no longer causes the first line of each square to loop between array elements, while the remaining trim behavior still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.