Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trimPolylines function #622

Open
qcoral opened this issue Jul 1, 2024 · 0 comments
Open

Fix trimPolylines function #622

qcoral opened this issue Jul 1, 2024 · 0 comments

Comments

@qcoral
Copy link
Member

qcoral commented Jul 1, 2024

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.

/*
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant