app_mapbuilder/libs/transform.js
2022-04-25 16:19:31 +05:00

33 lines
601 B
JavaScript

class Transfrom {
static fromCoordSystems(cs1, cs2){
let tr = new Transfrom()
tr.cs1 = cs1
tr.cs2 = cs2
let dx1 = cs1.x1 - cs1.x0;
let dy1 = cs1.y1 - cs1.y0;
let dx2 = cs2.x1 - cs2.x0;
let dy2 = cs2.y1 - cs2.y0;
tr.kx12 = dx1 ? dx2 / dx1 : 1;
tr.ky12 = dy1 ? dy2 / dy1 : 1;
return tr
}
trx(x){
return (x - this.cs1.x0) * this.kx12 + this.cs2.x0;
}
try(y){
return (y - this.cs1.y0) * this.ky12 + this.cs2.y0;
}
trp(p){
return {x: this.trx(p.x), y: this.trx(p.y)}
}
}
module.exports = Transfrom
module.exports.default = Transfrom