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

Error on subdivide function #756

Open
2 tasks
zcaotica opened this issue Jan 21, 2025 · 0 comments
Open
2 tasks

Error on subdivide function #756

zcaotica opened this issue Jan 21, 2025 · 0 comments
Labels

Comments

@zcaotica
Copy link

Hi, I found a problem with the subdivide function. It makes a Shape shorter if it is not closed, or it fails on the last segment if it is.
Is it a problem in my code?

Image

Line:13 versione = v0.8.16
Line:26 Line:
Line:27 Vertices base: 2 vs sub2: 3 vs sub16: 17
Line:28 Length base: = 800 vs sub2: 592.5925925925926 vs sub16: 792.0211683289233
Line:48 Left path:
Line:49 Vertices base: 4 vs sub: 11
Line:50 Length base: = 1200 vs sub: 1200
Line:69 Right path:
Line:70 Vertices base: 4 vs sub: 9
Line:71 Length base: = 1200 vs sub: 1096.2962962962963
Line:79 END

To Reproduce
I am not using Module, this is the code for the above image:
`
let two = new Two({
type: Two.Types.svg,
fullscreen: true,
autostart: true
});

two.appendTo(document.body);

console.log(`Version = ${Two.Version}`);

let baseLine = two.makeLine(100, 30, 900, 30);
let subLine2 = baseLine.clone(); //it is the same if I use makeLine again
subLine2.position.y += 10
subLine2.stroke = "#ff0000";
subLine2.subdivide(2);
two.add(subLine2);
let subLine16 = baseLine.clone(); //it is the same if I use makeLine again
subLine16.position.y += 20
subLine16.stroke = "#ff0000";
subLine16.subdivide(16);
two.add(subLine16);
console.log("Line:");
console.log(`Vertices base: ${baseLine.vertices.length} vs sub2: ${subLine2.vertices.length} vs sub16: ${subLine16.vertices.length}`);
console.log(`Length  base: = ${baseLine.length} vs sub2: ${subLine2.length} vs sub16: ${subLine16.length}`);
var pos = subLine2.position;
for (let i = 0; i < subLine2.vertices.length; i++) {
	let p = subLine2.vertices[i];
	two.makeCircle(p.x + pos.x, p.y + pos.y, 2).fill = "#00ff00";
}
pos = subLine16.position;
for (let i = 0; i < subLine16.vertices.length; i++) {
	let p = subLine16.vertices[i];
	two.makeCircle(p.x + pos.x, p.y + pos.y, 2).fill = "#00ff00";
}

let basePath = two.makePath(100, 100, 500, 100, 500, 500, 100, 500);
let subPath = basePath.clone(); //it is the same if I use makePath again
subPath.noFill();
subPath.stroke = "#ff0000";
subPath.position.y += 20
subPath.position.x += 20
two.add(subPath);
subPath.subdivide(2);
console.log("Left path:");
console.log(`Vertices base: ${basePath.vertices.length} vs sub: ${subPath.vertices.length}`);
console.log(`Length  base: = ${basePath.length} vs sub: ${subPath.length}`);
pos = subPath.position;
for (let i = 0; i < subPath.vertices.length; i++) {
	let p = subPath.vertices[i];
	//console.log(`V = ${p.x}`);
	two.makeCircle(p.x + pos.x, p.y + pos.y, 2).fill = "#00ff00";
}

let basePath2 = basePath.clone();
basePath2.closed = false;
two.add(basePath2);
basePath2.position.x += 550;
let subPath2 = basePath2.clone(); //it is the same if I use makePath2 again
subPath2.noFill();
subPath2.stroke = "#ff0000";
subPath2.position.y += 20
subPath2.position.x += 20
two.add(subPath2);
subPath2.subdivide(2);
console.log("Right path:");
console.log(`Vertices base: ${basePath2.vertices.length} vs sub: ${subPath2.vertices.length}`);
console.log(`Length  base: = ${basePath2.length} vs sub: ${subPath2.length}`);
pos = subPath2.position;
for (let i = 0; i < subPath2.vertices.length; i++) {
	let p = subPath2.vertices[i];
	//console.log(`V = ${p.x}`);
	two.makeCircle(p.x + pos.x, p.y + pos.y, 2).fill = "#00ff00";
}
console.log("END");

`

Expected behavior
The subdivided shape is the same of the original

Screenshots
See above

Environment (please select one):

  • [X ] Code executes in browser (e.g: using script tag to load library)
  • Packaged software (e.g: ES6 imports, react, angular, vue.js)
  • Running headless (usually Node.js)

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser chrome 131.0.6778.266 (Build ufficiale) (a 64 bit) , edge Version 130.0.2849.56 (Official build) stable app, extended channel (64-bit)
@zcaotica zcaotica added the bug label Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant