2018-12-05 19:00:12 +08:00
|
|
|
export const HUNDRED_PERCENT = 100;
|
|
|
|
export const MAX_PERCENT = 400;
|
|
|
|
export const MYSTERY_NUM = 2;
|
|
|
|
export const STEP = 25;
|
|
|
|
|
2018-08-16 19:20:02 +08:00
|
|
|
export default class SlideCalcUtil {
|
2018-10-19 01:03:11 +08:00
|
|
|
// After lots of trial and error on why synching doesn't work properly, I found I had to
|
2018-08-16 19:20:02 +08:00
|
|
|
// multiply the coordinates by 2. There's something I don't understand probably on the
|
|
|
|
// canvas coordinate system. (ralam feb 22, 2012)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the viewed region width
|
|
|
|
*/
|
|
|
|
static calcViewedRegionWidth(vpw, cpw) {
|
|
|
|
const width = (vpw / cpw) * HUNDRED_PERCENT;
|
|
|
|
if (width > HUNDRED_PERCENT) {
|
|
|
|
return HUNDRED_PERCENT;
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
static calcViewedRegionHeight(vph, cph) {
|
|
|
|
const height = (vph / cph) * HUNDRED_PERCENT;
|
|
|
|
if (height > HUNDRED_PERCENT) {
|
|
|
|
return HUNDRED_PERCENT;
|
|
|
|
}
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static calcCalcPageSizeWidth(ftp, vpw, vrw) {
|
|
|
|
if (ftp) {
|
|
|
|
return (vpw / vrw) * HUNDRED_PERCENT;
|
|
|
|
}
|
2018-10-19 01:03:11 +08:00
|
|
|
return vpw;
|
2018-08-16 19:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static calcCalcPageSizeHeight(ftp, vph, vrh, cpw, cph, opw, oph) {
|
|
|
|
if (ftp) {
|
|
|
|
return (vph / vrh) * HUNDRED_PERCENT;
|
|
|
|
}
|
2018-10-19 01:03:11 +08:00
|
|
|
return (cpw / opw) * oph;
|
2018-08-16 19:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static calcViewedRegionX(cpx, cpw) {
|
2019-07-18 08:30:28 +08:00
|
|
|
const viewX = -cpx / 2 / cpw * 100;
|
|
|
|
if (viewX > 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return viewX;
|
2018-08-16 19:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static calcViewedRegionY(cpy, cph) {
|
2019-07-18 08:30:28 +08:00
|
|
|
const viewY = -cpy / 2 / cph * 100;
|
|
|
|
if (viewY > 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return viewY;
|
2018-08-16 19:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static calculateViewportX(vpw, pw) {
|
2019-07-18 08:30:28 +08:00
|
|
|
if (vpw === pw) {
|
2018-08-16 19:20:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2018-10-19 01:03:11 +08:00
|
|
|
return (pw - vpw) / MYSTERY_NUM;
|
2018-08-16 19:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static calculateViewportY(vph, ph) {
|
2019-07-18 08:30:28 +08:00
|
|
|
if (vph === ph) {
|
2018-08-16 19:20:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (ph - vph) / MYSTERY_NUM;
|
|
|
|
}
|
2018-10-19 01:03:11 +08:00
|
|
|
}
|