in src/component/tag/geometry/RectGeometry.ts [127:299]
public setOppositeVertex2d(opposite: number[], transform: Transform): void {
if (this._anchorIndex === undefined) {
throw new GeometryTagError("Anchor indexing needs to be initialized.");
}
const changed: number[] = [
Math.max(0, Math.min(1, opposite[0])),
Math.max(0, Math.min(1, opposite[1])),
];
const original: number[] = this._rect.slice();
const anchor: number[] = this._anchorIndex === 0 ? [original[0], original[3]] :
this._anchorIndex === 1 ? [original[0], original[1]] :
this._anchorIndex === 2 ? [original[2], original[1]] :
[original[2], original[3]];
if (isSpherical(transform.cameraType)) {
const deltaX: number = this._anchorIndex < 2 ?
changed[0] - original[2] :
changed[0] - original[0];
if (!this._inverted && this._anchorIndex < 2 && changed[0] < 0.25 && original[2] > 0.75 && deltaX < -0.5) {
// right side passes boundary rightward
this._inverted = true;
this._anchorIndex = anchor[1] > changed[1] ? 0 : 1;
} else if (!this._inverted && this._anchorIndex >= 2 && changed[0] < 0.25 && original[2] > 0.75 && deltaX < -0.5) {
// left side passes right side and boundary rightward
this._inverted = true;
this._anchorIndex = anchor[1] > changed[1] ? 0 : 1;
} else if (this._inverted && this._anchorIndex >= 2 && changed[0] < 0.25 && original[0] > 0.75 && deltaX < -0.5) {
this._inverted = false;
if (anchor[0] > changed[0]) {
// left side passes boundary rightward
this._anchorIndex = anchor[1] > changed[1] ? 3 : 2;
} else {
// left side passes right side and boundary rightward
this._anchorIndex = anchor[1] > changed[1] ? 0 : 1;
}
} else if (!this._inverted && this._anchorIndex >= 2 && changed[0] > 0.75 && original[0] < 0.25 && deltaX > 0.5) {
// left side passes boundary leftward
this._inverted = true;
this._anchorIndex = anchor[1] > changed[1] ? 3 : 2;
} else if (!this._inverted && this._anchorIndex < 2 && changed[0] > 0.75 && original[0] < 0.25 && deltaX > 0.5) {
// right side passes left side and boundary leftward
this._inverted = true;
this._anchorIndex = anchor[1] > changed[1] ? 3 : 2;
} else if (this._inverted && this._anchorIndex < 2 && changed[0] > 0.75 && original[2] < 0.25 && deltaX > 0.5) {
this._inverted = false;
if (anchor[0] > changed[0]) {
// right side passes boundary leftward
this._anchorIndex = anchor[1] > changed[1] ? 3 : 2;
} else {
// right side passes left side and boundary leftward
this._anchorIndex = anchor[1] > changed[1] ? 0 : 1;
}
} else if (this._inverted && this._anchorIndex < 2 && changed[0] > original[0]) {
// inverted and right side passes left side completing a loop
this._inverted = false;
this._anchorIndex = anchor[1] > changed[1] ? 0 : 1;
} else if (this._inverted && this._anchorIndex >= 2 && changed[0] < original[2]) {
// inverted and left side passes right side completing a loop
this._inverted = false;
this._anchorIndex = anchor[1] > changed[1] ? 3 : 2;
} else if (this._inverted) {
// if still inverted only top and bottom can switch
if (this._anchorIndex < 2) {
this._anchorIndex = anchor[1] > changed[1] ? 0 : 1;
} else {
this._anchorIndex = anchor[1] > changed[1] ? 3 : 2;
}
} else {
// if still not inverted treat as non spherical
if (anchor[0] <= changed[0] && anchor[1] > changed[1]) {
this._anchorIndex = 0;
} else if (anchor[0] <= changed[0] && anchor[1] <= changed[1]) {
this._anchorIndex = 1;
} else if (anchor[0] > changed[0] && anchor[1] <= changed[1]) {
this._anchorIndex = 2;
} else {
this._anchorIndex = 3;
}
}
const rect: number[] = [];
if (this._anchorIndex === 0) {
rect[0] = anchor[0];
rect[1] = changed[1];
rect[2] = changed[0];
rect[3] = anchor[1];
} else if (this._anchorIndex === 1) {
rect[0] = anchor[0];
rect[1] = anchor[1];
rect[2] = changed[0];
rect[3] = changed[1];
} else if (this._anchorIndex === 2) {
rect[0] = changed[0];
rect[1] = anchor[1];
rect[2] = anchor[0];
rect[3] = changed[1];
} else {
rect[0] = changed[0];
rect[1] = changed[1];
rect[2] = anchor[0];
rect[3] = anchor[1];
}
if (!this._inverted && rect[0] > rect[2] ||
this._inverted && rect[0] < rect[2]) {
rect[0] = original[0];
rect[2] = original[2];
}
if (rect[1] > rect[3]) {
rect[1] = original[1];
rect[3] = original[3];
}
this._rect[0] = rect[0];
this._rect[1] = rect[1];
this._rect[2] = rect[2];
this._rect[3] = rect[3];
} else {
if (anchor[0] <= changed[0] && anchor[1] > changed[1]) {
this._anchorIndex = 0;
} else if (anchor[0] <= changed[0] && anchor[1] <= changed[1]) {
this._anchorIndex = 1;
} else if (anchor[0] > changed[0] && anchor[1] <= changed[1]) {
this._anchorIndex = 2;
} else {
this._anchorIndex = 3;
}
const rect: number[] = [];
if (this._anchorIndex === 0) {
rect[0] = anchor[0];
rect[1] = changed[1];
rect[2] = changed[0];
rect[3] = anchor[1];
} else if (this._anchorIndex === 1) {
rect[0] = anchor[0];
rect[1] = anchor[1];
rect[2] = changed[0];
rect[3] = changed[1];
} else if (this._anchorIndex === 2) {
rect[0] = changed[0];
rect[1] = anchor[1];
rect[2] = anchor[0];
rect[3] = changed[1];
} else {
rect[0] = changed[0];
rect[1] = changed[1];
rect[2] = anchor[0];
rect[3] = anchor[1];
}
if (rect[0] > rect[2]) {
rect[0] = original[0];
rect[2] = original[2];
}
if (rect[1] > rect[3]) {
rect[1] = original[1];
rect[3] = original[3];
}
this._rect[0] = rect[0];
this._rect[1] = rect[1];
this._rect[2] = rect[2];
this._rect[3] = rect[3];
}
this._notifyChanged$.next(this);
}