123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- var t = require;
- var e = module;
- var i = exports;
- Object.defineProperty(i, "__esModule", {value: !0});
- const a = t("MapType"),
- n = t("Point"),
- r = t("RoadNode");
- i.default = class t {
- static get instance() {
- return null == this._instance && (this._instance = new t()), this._instance;
- }
- updateMapInfo(t, e, i, s, o) {
- switch (
- ((this._mapWidth = t),
- (this._mapHeight = e),
- (this._nodeWidth = i),
- (this._nodeHeight = s),
- (this._halfNodeWidth = Math.floor(this._nodeWidth / 2)),
- (this._halfNodeHeight = Math.floor(this._nodeHeight / 2)),
- (this._col = Math.ceil(t / this._nodeWidth)),
- (this._row = Math.ceil(e / this._nodeHeight)),
- (this._mapType = o),
- this._mapType)
- ) {
- case a.MapType.angle45:
- this._mapRoad = new l(
- this._row,
- this._col,
- this._nodeWidth,
- this._nodeHeight,
- this._halfNodeWidth,
- this._halfNodeHeight
- );
- break;
- case a.MapType.angle90:
- this._mapRoad = new h(
- this._row,
- this._col,
- this._nodeWidth,
- this._nodeHeight,
- this._halfNodeWidth,
- this._halfNodeHeight
- );
- break;
- case a.MapType.honeycomb:
- (this._col = 2 * Math.ceil((this._mapWidth - this._nodeWidth / 4) / ((this._nodeWidth / 4) * 6))),
- (this._row = Math.ceil((this._mapHeight - this._nodeHeight / 2) / this._nodeHeight)),
- (this._mapRoad = new c(
- this._row,
- this._col,
- this._nodeWidth,
- this._nodeHeight,
- this._halfNodeWidth,
- this._halfNodeHeight
- ));
- }
- }
- getNodeByPixel(t, e) {
- return this._mapRoad ? this._mapRoad.getNodeByPixel(t, e) : new r.default();
- }
- getNodeByDerect(t, e) {
- return this._mapRoad ? this._mapRoad.getNodeByDerect(t, e) : new r.default();
- }
- getNodeByWorldPoint(t, e) {
- return this._mapRoad ? this._mapRoad.getNodeByWorldPoint(t, e) : new r.default();
- }
- getWorldPointByPixel(t, e) {
- return this._mapRoad ? this._mapRoad.getWorldPointByPixel(t, e) : new n.default();
- }
- getPixelByWorldPoint(t, e) {
- return this._mapRoad ? this._mapRoad.getPixelByWorldPoint(t, e) : new n.default();
- }
- getDerectByPixel(t, e) {
- return this._mapRoad ? this._mapRoad.getDerectByPixel(t, e) : new n.default();
- }
- getDerectByWorldPoint(t, e) {
- return this._mapRoad ? this._mapRoad.getDerectByWorldPoint(t, e) : new n.default();
- }
- getPixelByDerect(t, e) {
- return this._mapRoad ? this._mapRoad.getPixelByDerect(t, e) : new n.default();
- }
- get mapWidth() {
- return this._mapWidth;
- }
- get mapHeight() {
- return this._mapHeight;
- }
- get nodeWidth() {
- return this._nodeWidth;
- }
- get nodeHeight() {
- return this._nodeHeight;
- }
- get row() {
- return this._row;
- }
- get col() {
- return this._col;
- }
- get halfNodeWidth() {
- return this._halfNodeWidth;
- }
- get halfNodeHeight() {
- return this._halfNodeHeight;
- }
- get mapType() {
- return this._mapType;
- }
- };
- class l {
- constructor(t, e, i, s, o, a) {
- (this._row = t),
- (this._col = e),
- (this._nodeWidth = i),
- (this._nodeHeight = s),
- (this._halfNodeWidth = o),
- (this._halfNodeHeight = a);
- }
- getNodeByPixel(t, e) {
- var i = this.getWorldPointByPixel(t, e),
- s = this.getPixelByWorldPoint(i.x, i.y),
- t = this.getDerectByPixel(t, e),
- e = new r.default();
- return (e.cx = i.x), (e.cy = i.y), (e.px = s.x), (e.py = s.y), (e.dx = t.x), (e.dy = t.y), e;
- }
- getNodeByDerect(t, e) {
- var i = this.getPixelByDerect(t, e),
- s = this.getWorldPointByPixel(i.x, i.y),
- o = new r.default();
- return (o.cx = s.x), (o.cy = s.y), (o.px = i.x), (o.py = i.y), (o.dx = t), (o.dy = e), o;
- }
- getNodeByWorldPoint(t, e) {
- e = this.getPixelByWorldPoint(t, e);
- return this.getNodeByPixel(e.x, e.y);
- }
- getWorldPointByPixel(t, e) {
- var i = Math.ceil(t / this._nodeWidth - 0.5 + e / this._nodeHeight) - 1,
- e = this._col - 1 - Math.ceil(t / this._nodeWidth - 0.5 - e / this._nodeHeight);
- return new n.default(i, e);
- }
- getPixelByWorldPoint(t, e) {
- var i = Math.floor((t + 1 - (e - (this._col - 1))) * this._halfNodeWidth),
- e = Math.floor((t + 1 + (e - (this._col - 1))) * this._halfNodeHeight);
- return new n.default(i, e);
- }
- getDerectByPixel(t, e) {
- (t = this.getWorldPointByPixel(t, e)),
- (e = this.getPixelByWorldPoint(t.x, t.y)),
- (t = Math.floor(e.x / this._nodeWidth) - (e.x % this._nodeWidth == 0 ? 1 : 0)),
- (e = Math.floor(e.y / this._halfNodeHeight) - 1);
- return new n.default(t, e);
- }
- getDerectByWorldPoint(t, e) {
- var i = Math.floor((t - (e - (this._col - 1))) / 2),
- e = t + (e - (this._col - 1));
- return new n.default(i, e);
- }
- getPixelByDerect(t, e) {
- (t = Math.floor((t + (e % 2)) * this._nodeWidth + (1 - (e % 2)) * this._halfNodeWidth)),
- (e = Math.floor((e + 1) * this._halfNodeHeight));
- return new n.default(t, e);
- }
- }
- class h {
- constructor(t, e, i, s, o, a) {
- (this._row = t),
- (this._col = e),
- (this._nodeWidth = i),
- (this._nodeHeight = s),
- (this._halfNodeWidth = o),
- (this._halfNodeHeight = a);
- }
- getNodeByPixel(t, e) {
- var i = this.getWorldPointByPixel(t, e),
- s = this.getPixelByWorldPoint(i.x, i.y),
- t = this.getDerectByPixel(t, e),
- e = new r.default();
- return (e.cx = i.x), (e.cy = i.y), (e.px = s.x), (e.py = s.y), (e.dx = t.x), (e.dy = t.y), e;
- }
- getNodeByDerect(t, e) {
- var i = this.getPixelByDerect(t, e),
- s = this.getWorldPointByPixel(i.x, i.y),
- o = new r.default();
- return (o.cx = s.x), (o.cy = s.y), (o.px = i.x), (o.py = i.y), (o.dx = t), (o.dy = e), o;
- }
- getNodeByWorldPoint(t, e) {
- e = this.getPixelByWorldPoint(t, e);
- return this.getNodeByPixel(e.x, e.y);
- }
- getWorldPointByPixel(t, e) {
- (t = Math.floor(t / this._nodeWidth)), (e = Math.floor(e / this._nodeHeight));
- return new n.default(t, e);
- }
- getPixelByWorldPoint(t, e) {
- (t = Math.floor((t + 1) * this._nodeWidth - this._halfNodeWidth)),
- (e = Math.floor((e + 1) * this._nodeHeight - this._halfNodeHeight));
- return new n.default(t, e);
- }
- getDerectByPixel(t, e) {
- (t = Math.floor(t / this._nodeWidth)), (e = Math.floor(e / this._nodeHeight));
- return new n.default(t, e);
- }
- getDerectByWorldPoint(t, e) {
- return new n.default(t, e);
- }
- getPixelByDerect(t, e) {
- (t = Math.floor((t + 1) * this._nodeWidth - this._halfNodeWidth)),
- (e = Math.floor((e + 1) * this._nodeHeight - this._halfNodeHeight));
- return new n.default(t, e);
- }
- }
- class c {
- constructor(t, e, i, s, o, a) {
- (this._proportion = 1.732),
- (this._row = t),
- (this._col = e),
- (this._nodeWidth = i),
- (this._nodeHeight = s),
- (this._halfNodeWidth = o),
- (this._halfNodeHeight = a),
- (this._nwDiv4 = this._nodeWidth / 4),
- (this._radius = 4 * this._nwDiv4),
- (this._proportion = (2 * this._nodeHeight) / this._nodeWidth);
- }
- getNodeByPixel(t, e) {
- var i = this.getWorldPointByPixel(t, e),
- t = this.getPixelByWorldPoint(i.x, i.y),
- e = new r.default();
- return (e.cx = i.x), (e.cy = i.y), (e.px = t.x), (e.py = t.y), (e.dx = i.x), (e.dy = i.y), e;
- }
- getNodeByDerect(t, e) {
- var i = this.getPixelByDerect(t, e),
- s = new r.default();
- return (s.cx = t), (s.cy = e), (s.px = i.x), (s.py = i.y), (s.dx = t), (s.dy = e), s;
- }
- getNodeByWorldPoint(t, e) {
- e = this.getPixelByWorldPoint(t, e);
- return this.getNodeByPixel(e.x, e.y);
- }
- getWorldPointByPixel(t, e) {
- var i,
- s = Math.floor(t / this._nwDiv4),
- o = Math.floor(s / 3),
- a =
- (s - 1) % 6 == 0 || (s - 2) % 6 == 0
- ? ((i = o), (a = Math.floor(e / this._nodeHeight)))
- : (s - 4) % 6 == 0 || (s - 5) % 6 == 0
- ? ((i = o),
- (a = e < this._nodeHeight / 2 ? -1 : Math.floor((e - this._nodeHeight / 2) / this._nodeHeight)))
- : o % 2 == 0
- ? ((a = Math.floor(e / this._nodeHeight)),
- this.testPointInHoneycomb(o, a, t, e)
- ? ((i = o), a)
- : this.testPointInHoneycomb(o - 1, a - 1, t, e)
- ? ((i = o - 1), a - 1)
- : ((i = o - 1), a))
- : ((a = e < this._nodeHeight / 2 ? -1 : Math.floor((e - this._nodeHeight / 2) / this._nodeHeight)),
- this.testPointInHoneycomb(o, a, t, e)
- ? ((i = o), a)
- : this.testPointInHoneycomb(o - 1, a, t, e)
- ? ((i = o - 1), a)
- : ((i = o - 1), a + 1));
- return new n.default(i, a);
- }
- testPointInHoneycomb(t, e, i, s) {
- var o = 2 * this._nwDiv4,
- e = this.getPixelByWorldPoint(t, e);
- return o - Math.abs(i - e.x) >= Math.abs(s - e.y) / this._proportion;
- }
- getPixelByWorldPoint(t, e) {
- var i = Math.floor(((2 + 3 * t) / 4) * this._nodeWidth),
- t = Math.floor((e + 0.5 * (1 + (t % 2))) * this._nodeHeight);
- return new n.default(i, t);
- }
- getDerectByPixel(t, e) {
- return this.getWorldPointByPixel(t, e);
- }
- getDerectByWorldPoint(t, e) {
- return new n.default(t, e);
- }
- getPixelByDerect(t, e) {
- var i = ((2 + 3 * t) / 4) * this._nodeWidth,
- t = (e + 0.5 * (1 + (t % 2))) * this._nodeHeight;
- return new n.default(i, t);
- }
- }
|