edge:
if ((ay < -eps || az < -eps) &&
eps < abs (p)) {
let dx = -s / p;
const dy = 0;
const dz = 0;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((1 + eps < ax || az < -eps) &&
eps < abs (q)) {
const dx = 1;
let dy = -(p + s) / q;
const dz = 0;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((1 + eps < ay || az < -eps) &&
eps < abs (p)) {
let dx = -(q + s) / p;
const dy = 1;
const dz = 0;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((ax < -eps || az < -eps) &&
eps < abs (q)) {
const dx = 0;
let dy = -s / q;
const dz = 0;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((1 + eps < ax || ay < -eps) &&
eps < abs (r)) {
const dx = 1;
const dy = 0;
let dz = -(p + s) / r;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((1 + eps < ax || 1 + eps < ay) &&
eps < abs (r)) {
const dx = 1;
const dy = 1;
let dz = -(p + q + s) / r;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((ax < -eps || 1 + eps < ay) &&
eps < abs (r)) {
const dx = 0;
const dy = 1;
let dz = -(q + s) / r;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((ax < -eps || ay < -eps) &&
eps < abs (r)) {
const dx = 0;
const dy = 0;
let dz = -s / r;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((ay < -eps || 1 + eps < az) &&
eps < abs (p)) {
let dx = -(r + s) / p;
const dy = 0;
const dz = 1;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((1 + eps < ax || 1 + eps < az) &&
eps < abs (q)) {
const dx = 1;
let dy = -(p + r + s) / q;
const dz = 1;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((1 + eps < ay || 1 + eps < az) &&
eps < abs (p)) {
let dx = -(q + r + s) / p;
const dy = 1;
const dz = 1;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
edge:
if ((ax < -eps || 1 + eps < az) &&
eps < abs (q)) {
const dx = 0;
let dy = -(r + s) / q;
const dz = 1;
if (-eps < dx && dx < 1 + eps &&
-eps < dy && dy < 1 + eps &&
-eps < dz && dz < 1 + eps) {
let adx = dx - ax;
let ady = dy - ay;
let adz = dz - az;
let bcx = cx - bx;
let bcy = cy - by;
let bcz = cz - bz;
let den;
let g;
if (eps < abs (den = adx * bcy - ady * bcx)) {
g = ((ay - by) * adx - (ax - bx) * ady) / den;
} else if (eps < abs (den = ady * bcz - adz * bcy)) {
g = ((az - bz) * ady - (ay - by) * adz) / den;
} else if (eps < abs (den = adz * bcx - adx * bcz)) {
g = ((ax - bx) * adz - (az - bz) * adx) / den;
} else {
break edge;
}
if (-eps < g && g < 1 + eps) {
let ex = bx + bcx * g;
let ey = by + bcy * g;
let ez = bz + bcz * g;
let dot = (ax - ex) * (dx - ex) + (ay - ey) * (dy - ey) + (az - ez) * (dz - ez);
if (eps < dot) {
result = sign;
break comparator;
}
if (dot < -eps) {
result = -sign;
break comparator;
}
}
}
}
}
}
let t = ph1;
ph1 = ph2;
ph2 = t;
}
return result;
}
const KEN_MAP = {
KeyA: 35,
65: 35,
KeyZ: 36,
90: 36,
KeyS: 37,
83: 37,
KeyX: 38,
88: 38,
KeyC: 39,
67: 39,
KeyF: 40,
70: 40,
KeyV: 41,
86: 41,
KeyG: 42,
71: 42,
KeyB: 43,
66: 43,
KeyN: 44,
78: 44,
KeyJ: 45,
74: 45,
KeyM: 46,
77: 46,
KeyK: 47,
75: 47,
Comma: 48,
188: 48,
KeyL: 49,
76: 49,
Period: 50,
190: 50,
Slash: 51,
191: 51,
Quote: 52,
186: 52,
58: 52,
IntlRo: 53,
226: 53,
Backslash: 54,
221: 54,
KeyQ: 51,
81: 51,
Digit2: 52,
50: 52,
KeyW: 53,
87: 53,
Digit3: 54,
51: 54,
KeyE: 55,
69: 55,
KeyR: 56,
82: 56,
Digit5: 57,
53: 57,
KeyT: 58,
84: 58,
Digit6: 59,
54: 59,
KeyY: 60,
89: 60,
Digit7: 61,
55: 61,
KeyU: 62,
85: 62,
KeyI: 63,
73: 63,
Digit9: 64,
57: 64,
KeyO: 65,
79: 65,
Digit0: 66,
48: 66,
KeyP: 67,
80: 67,
BracketLeft: 68,
64: 68,
192: 68,
Equal: 69,
160: 69,
222: 69,
BracketRight: 70,
219: 70,
IntlYen: 71
};
let audioAvailable = false;
let kenGeta = 0;
let shiftLeftOn = false;
let shiftRightOn = false;
function moveSoftPedal () {
if (pedalPhaK[0] == 0) {
movePedal (0, 1);
} else {
movePedal (0, 0);
}
}
function moveSostenutoPedal () {
if (pedalPhaK[1] == 0) {
for (let kn = 0; kn < KEN_COUNT; kn++) {
let ki = kenInfoArray[kn];
if (ki && ki.ki$keyOn && ki.ki$pressed) {
ki.ki$sostenuto = true;
}
}
movePedal (1, 1);
} else {
for (let kn = 0; kn < KEN_COUNT; kn++) {
let ki = kenInfoArray[kn];
if (ki && ki.ki$keyOn && !ki.ki$pressed && ki.ki$sostenuto) {
ki.ki$sostenuto = false;
kenKeyOff (ki);
}
}
movePedal (1, 0);
}
}
function moveLoudPedal () {
if (pedalPhaK[2] == 0) {
movePedal (2, 1);
} else {
for (let kn = 0; kn < KEN_COUNT; kn++) {
let ki = kenInfoArray[kn];
if (ki && ki.ki$keyOn && !ki.ki$pressed) {
kenKeyOff (ki);
}
}
movePedal (2, 0);
}
}
function windowOnkeydown (e) {
e = e || window.event;
if (focusedElement != null ||
e.ctrlKey) {
return;
}
let keyCode = e.keyCode || e.which || 0;
let code = e.code || "";
switch (code) {
case "Escape":
if (docWindow.pw$isOpen ()) {
docWindow.pw$close ();
} else if (docWindow.pw$isClosed ()) {
opmWindow.pw$close ();
pcmWindow.pw$close ();
docWindow.pw$open ();
}
break;
case "Insert":
case "Numpad0":
if (opmWindow.pw$isOpen ()) {
opmWindow.pw$close ();
} else if (opmWindow.pw$isClosed ()) {
docWindow.pw$close ();
pcmWindow.pw$close ();
opmWindow.pw$open ();
}
break;
case "Delete":
case "NumpadDecimal":
if (pcmWindow.pw$isOpen ()) {
pcmWindow.pw$close ();
} else if (pcmWindow.pw$isClosed ()) {
docWindow.pw$close ();
opmWindow.pw$close ();
pcmWindow.pw$open ();
}
break;
case "Enter":
case "NumpadEnter":
kenbanfutaOpenClose ();
break;
case "Backspace":
yaneOpenClose ();
break;
case "Tab":
fumendaiOpenClose ();
break;
case "ShiftLeft":
if (shiftRightOn) {
shiftLeftOn = false;
shiftRightOn = false;
kenGeta = 0;
} else if (!shiftLeftOn) {
shiftLeftOn = true;
if (-36 < kenGeta) {
kenGeta -= 12;
}
}
break;
case "ShiftRight":
if (shiftLeftOn) {
shiftLeftOn = false;
shiftRightOn = false;
kenGeta = 0;
} else if (!shiftRightOn) {
shiftRightOn = true;
if (kenGeta < 36) {
kenGeta += 12;
}
}
break;
case "AltLeft":
if (pedalPhaK[0] == 0) {
moveSoftPedal ();
}
break;
case "Space":
if (pedalPhaK[1] == 0) {
moveSostenutoPedal ();
}
break;
case "AltRight":
if (pedalPhaK[2] == 0) {
moveLoudPedal ();
}
break;
case "ArrowUp":
case "Numpad8":
mouseDy += 0.02;
break;
case "ArrowDown":
case "Numpad2":
mouseDy -= 0.02;
break;
case "ArrowLeft":
case "Numpad4":
mouseDx += 0.02;
break;
case "ArrowRight":
case "Numpad6":
mouseDx -= 0.02;
break;
case "PageUp":
case "Numpad9":
mouseDw--;
break;
case "PageDown":
case "Numpad3":
mouseDw++;
break;
case "NumpadSubtract":
toggleFloorFixedMode ();
break;
case "NumpadDivide":
setScreenMode (screenMode < 2 ? screenMode + 1 : 0);
break;
default:
if (kenbanfutaPhaK == kenbanfutaPhaN) {
let kn = KEN_MAP[code] || KEN_MAP[keyCode] || -1;
if (0 <= kn) {
kn += kenGeta;
if (0 <= kn && kn < KEN_COUNT) {
let ki = kenInfoArray[kn];
if (!ki.ki$pressed) {
kenKeyOn (ki);
kenDown (ki);
}
}
}
}
}
consumeEvent (e);
}
function windowOnkeyup (e) {
e = e || window.event;
let keyCode = e.keyCode || e.which || 0;
let code = e.code || "";
switch (code) {
case "ShiftLeft":
shiftLeftOn = false;
break;
case "ShiftRight":
shiftRightOn = false;
break;
case "AltLeft":
if (pedalPhaK[0] == 1) {
moveSoftPedal ();
}
break;
case "Space":
if (pedalPhaK[1] == 1) {
moveSostenutoPedal ();
}
break;
case "AltRight":
if (pedalPhaK[2] == 1) {
moveLoudPedal ();
}
break;
default:
if (kenbanfutaPhaK == kenbanfutaPhaN) {
let kn = KEN_MAP[code] || KEN_MAP[keyCode] || -1;
if (0 <= kn) {
kn += kenGeta;
if (0 <= kn && kn < KEN_COUNT) {
let ki = kenInfoArray[kn];
if (ki.ki$pressed) {
if (pedalPhaK[2] == 0 && !ki.ki$sostenuto) {