in src/core/prototypes/plot_segments/region_2d/utils.ts [22:196]
export function getCenterByAngle(
properties: PolarProperties,
attrs: PolarAttributes
): CenterType {
const isAutoMargin = properties.autoAlignment ?? false;
const { angle1, angle2, x1, y1, x2, y2 } = attrs;
let cx;
let cy;
let isHalf = false;
let side = SIDE.NONE;
let isRightHalf = false;
let isCorner = false;
if (isAutoMargin) {
//pos case
const angleDelta = Math.abs(angle1 - angle2);
const startAngle = angle1 % 360;
if (startAngle >= 0 && startAngle < 90) {
//startAngle - 1 quadrant
if (angleDelta <= 90 - startAngle) {
//endAngle - 1 quadrant => move left bottom corner
cx = x1;
cy = y1;
isCorner = true;
} else if (angleDelta <= 180 - startAngle) {
//endAngle - 4 quadrant => move left
cx = x1;
cy = (y2 + y1) / 2;
isHalf = true;
side = SIDE.VERTICAL;
} else if (angleDelta + startAngle > 180) {
//endAngle - 3 and 4 quadrants
cx = (x2 + x1) / 2;
cy = (y2 + y1) / 2;
}
} else if (startAngle >= 90 && startAngle < 180) {
//startAngle - 4 quadrant
if (angleDelta <= 180 - startAngle) {
//endAngle - 4 quadrant => move left top corner
cx = x1;
cy = y2;
isCorner = true;
} else if (angleDelta <= 270 - startAngle) {
//endAngle - 3 quadrant => move top
cx = (x2 + x1) / 2;
cy = y2;
isHalf = true;
side = SIDE.VERTICAL;
isRightHalf = true;
} else if (angleDelta + startAngle > 270) {
//endAngle - 2 and 1 quadrants
cx = (x2 + x1) / 2;
cy = (y2 + y1) / 2;
}
} else if (startAngle >= 180 && startAngle < 270) {
//startAngle - 3 quadrant
if (angleDelta <= 270 - startAngle) {
//endAngle - 3 quadrant => move right top corner
cx = x2;
cy = y2;
isCorner = true;
} else if (angleDelta <= 360 - startAngle) {
//endAngle - 1 quadrant => move right
cx = x2;
cy = (y2 + y1) / 2;
isHalf = true;
side = SIDE.VERTICAL;
isRightHalf = true;
} else if (angleDelta + startAngle > 360) {
//endAngle - 2 and 1 quadrants
cx = (x2 + x1) / 2;
cy = (y2 + y1) / 2;
}
} else if (startAngle >= 270 && startAngle < 360) {
//startAngle - 2 quadrant
if (angleDelta <= 360 - startAngle) {
//endAngle - 2 quadrant => move right bottom corner
cx = x2;
cy = y1;
isCorner = true;
} else if (angleDelta <= 450 - startAngle) {
//endAngle - 1 quadrant => move bottom
cx = (x2 + x1) / 2;
cy = y1;
isHalf = true;
side = SIDE.HORIZONTAL;
} else if (angleDelta + startAngle > 450) {
//endAngle - 2 and 1 quadrants
cx = (x2 + x1) / 2;
cy = (y2 + y1) / 2;
}
}
//neg case
if (startAngle < 0 && startAngle >= -90) {
//startAngle - 3 quadrant
if (angleDelta <= 90 - (90 + startAngle)) {
//endAngle - 3 quadrant => move right bottom corner
cx = x2;
cy = y1;
isCorner = true;
} else if (angleDelta <= 180 - (90 + startAngle)) {
//endAngle - 1 quadrant => move bottom
cx = (x1 + x2) / 2;
cy = y1;
isHalf = true;
side = SIDE.HORIZONTAL;
} else if (angleDelta - startAngle >= 180) {
//endAngle - 2 and 3 quadrants
cx = (x2 + x1) / 2;
cy = (y2 + y1) / 2;
}
} else if (startAngle <= -90 && startAngle >= -180) {
//startAngle - 3 quadrant
if (angleDelta <= 90 - (180 + startAngle)) {
//endAngle - 3 quadrant => move right
cx = x2;
cy = y2;
isCorner = true;
} else if (angleDelta <= 180 - (180 + startAngle)) {
//endAngle - 2 quadrant => move right
cx = x2;
cy = (y2 + y1) / 2;
isHalf = true;
side = SIDE.VERTICAL;
isRightHalf = true;
} else if (angleDelta - startAngle >= -270) {
//endAngle - 1 and 4 quadrants
cx = (x2 + x1) / 2;
cy = (y2 + y1) / 2;
}
} else if (startAngle <= -180 && startAngle >= -270) {
//startAngle - 4 quadrant
if (angleDelta <= 90 - (270 + startAngle)) {
//endAngle - 4 quadrant => move left top corner
cx = x1;
cy = y2;
isCorner = true;
} else if (angleDelta <= 180 - (270 + startAngle)) {
//endAngle - 3 quadrant => move top
cx = (x2 + x1) / 2;
cy = y2;
isHalf = true;
side = SIDE.HORIZONTAL;
} else if (angleDelta - startAngle >= -360) {
//endAngle - 2 and 1 quadrants
cx = (x2 + x1) / 2;
cy = (y2 + y1) / 2;
}
} else if (startAngle <= -270 && startAngle > -360) {
//startAngle - 1 quadrant
if (angleDelta <= 90 - (360 + startAngle)) {
//endAngle - 1 quadrant => move left bottom corner
cx = x1;
cy = y1;
isCorner = true;
} else if (angleDelta <= 180 - (360 + startAngle)) {
//endAngle - 4 quadrant => move left
cx = x1;
cy = (y2 + y1) / 2;
isHalf = true;
side = SIDE.VERTICAL;
} else if (angleDelta - startAngle >= -450) {
//endAngle - 2 and 3 quadrants
cx = (x2 + x1) / 2;
cy = (y2 + y1) / 2;
}
}
} else {
cx = (x2 + x1) / 2;
cy = (y2 + y1) / 2;
}
return { cx, cy, isHalf, side, isRightHalf, isCorner };
}