#374 star Polygon, number-of-point update after not reflect issue fixed
This commit is contained in:
@@ -136,6 +136,61 @@ export default {
|
||||
showPanel(false, "polygon");
|
||||
$id("starNumPoints").addEventListener("change", (event) => {
|
||||
setAttr("point", event.target.value);
|
||||
const orient = 'point';
|
||||
const point = event.target.value;
|
||||
let i = selElems.length;
|
||||
while (i--) {
|
||||
const elem = selElems[i];
|
||||
if (elem.hasAttribute('r')) {
|
||||
const radialshift = elem.getAttribute('radialshift');
|
||||
let xpos = 0;
|
||||
let ypos = 0;
|
||||
if (elem.points) {
|
||||
const list = elem.points;
|
||||
const len = list.numberOfItems;
|
||||
for (let i = 0; i < len; ++i) {
|
||||
const pt = list.getItem(i);
|
||||
xpos += parseFloat(pt.x);
|
||||
ypos += parseFloat(pt.y);
|
||||
}
|
||||
const cx = xpos / len;
|
||||
const cy = ypos / len;
|
||||
const circumradius = elem.getAttribute('r');
|
||||
const inradius = circumradius / elem.getAttribute('starRadiusMultiplier');
|
||||
|
||||
let polyPoints = "";
|
||||
for (let s = 0; point >= s; s++) {
|
||||
let angle = 2.0 * Math.PI * (s / point);
|
||||
if (orient === "point") {
|
||||
angle -= Math.PI / 2;
|
||||
} else if (orient === "edge") {
|
||||
angle = angle + Math.PI / point - Math.PI / 2;
|
||||
}
|
||||
|
||||
let x = circumradius * Math.cos(angle) + cx;
|
||||
let y = circumradius * Math.sin(angle) + cy;
|
||||
|
||||
polyPoints += x + "," + y + " ";
|
||||
|
||||
if (!isNaN(inradius)) {
|
||||
angle = 2.0 * Math.PI * (s / point) + Math.PI / point;
|
||||
if (orient === "point") {
|
||||
angle -= Math.PI / 2;
|
||||
} else if (orient === "edge") {
|
||||
angle = angle + Math.PI / point - Math.PI / 2;
|
||||
}
|
||||
angle += radialshift;
|
||||
|
||||
x = inradius * Math.cos(angle) + cx;
|
||||
y = inradius * Math.sin(angle) + cy;
|
||||
|
||||
polyPoints += x + "," + y + " ";
|
||||
}
|
||||
}
|
||||
elem.setAttribute("points", polyPoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
$id("RadiusMultiplier").addEventListener("change", (event) => {
|
||||
setAttr("starRadiusMultiplier", event.target.value);
|
||||
@@ -254,10 +309,11 @@ export default {
|
||||
|
||||
const circumradius =
|
||||
Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy)) / 1.5;
|
||||
const RadiusMultiplier = document.getElementById("RadiusMultiplier").value;
|
||||
const inradius =
|
||||
circumradius / document.getElementById("RadiusMultiplier").value;
|
||||
circumradius / RadiusMultiplier;
|
||||
newFO.setAttribute("r", circumradius);
|
||||
newFO.setAttribute("r2", inradius);
|
||||
newFO.setAttribute('starRadiusMultiplier', RadiusMultiplier);
|
||||
|
||||
let polyPoints = "";
|
||||
for (let s = 0; point >= s; s++) {
|
||||
|
||||
Reference in New Issue
Block a user