fix centering, poly scaling

This commit is contained in:
Stewart Allen 2024-07-30 16:56:34 -04:00
commit e608091603
4 changed files with 23 additions and 6 deletions

View file

@ -81,6 +81,13 @@ class Point {
return this; return this;
} }
scale(x = 1,y = 1,z = 1) {
this.x *= x;
this.y *= y;
this.z *= z;
return this;
}
round(precision) { round(precision) {
return newPoint( return newPoint(
this.x.round(precision), this.x.round(precision),

View file

@ -615,6 +615,7 @@ class Polygon {
* @returns {Polygon|Point} a new polygon centered on x=0, y=0, z=0 * @returns {Polygon|Point} a new polygon centered on x=0, y=0, z=0
*/ */
center(point) { center(point) {
throw "does not work";
let ap = newPoint(0, 0, 0, null), let ap = newPoint(0, 0, 0, null),
np = newPolygon(), np = newPolygon(),
pa = this.points; pa = this.points;

View file

@ -494,11 +494,13 @@ let sketch = {
sketch.selection.bounded_op((sketch, bounds, recs) => { sketch.selection.bounded_op((sketch, bounds, recs) => {
let center = bounds.center(0); let center = bounds.center(0);
for (let rec of recs) { for (let rec of recs) {
rec.poly.move({ x: -center.x, y: -center.y, z:0 }); let { item } = rec;
Object.assign(rec.item, rec.poly.toObject()); let poly = newPolygon().fromObject(item);
poly.move({ x: -center.x, y: -center.y, z:0 });
Object.assign(rec.item, poly.toObject());
} }
selection.centerXY();
sketch.render(); sketch.render();
selection.centerXY();
}); });
}, },

View file

@ -8,7 +8,7 @@
gapp.register("mesh.build", [], (root, exports) => { gapp.register("mesh.build", [], (root, exports) => {
const { broker } = gapp; const { broker } = gapp;
const { mesh, moto } = root; const { base, mesh, moto } = root;
const { api, util } = mesh; const { api, util } = mesh;
const { space } = moto; const { space } = moto;
const { bind, div, label, input, hr } = h; const { bind, div, label, input, hr } = h;
@ -873,10 +873,17 @@ function ui_build() {
// polygon scaling, circle radius // polygon scaling, circle radius
let el2 = bound[`item_val_${axis.toUpperCase()}_size`]; let el2 = bound[`item_val_${axis.toUpperCase()}_size`];
if (!el2) continue; if (!el2) continue;
sel_item.type !== 'polygon' && el2.classList.add('editable'); el2.classList.add('editable');
el2.onclick = field_edit(`${axis} size`, (nval, oval) => { el2.onclick = field_edit(`${axis} size`, (nval, oval) => {
if (sel_item.type === 'polygon') { if (sel_item.type === 'polygon') {
// todo let scale = {x:1,y:1,z:1};
let poly = base.newPolygon().fromObject(sel_item);
let bounds = poly.bounds;
scale[axis] = nval/oval;
poly.move(bounds.center().scale(-1,-1,-1));
poly.scale(scale);
poly.move(bounds.center());
Object.assign(sel_item, poly.toObject());
} else if (sel_item.type === 'circle') { } else if (sel_item.type === 'circle') {
sel_item.radius = nval / 2; sel_item.radius = nval / 2;
} }