dgeoutils 2.4.34 → 2.4.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { DPoint } from './DPoint';
2
2
  import { DCircle } from './DCircle';
3
+ import { DPolygon } from './DPolygon';
3
4
  export declare class DLine {
4
5
  a: number;
5
6
  b: number;
@@ -34,4 +35,5 @@ export declare class DLine {
34
35
  movePoint(points: DPoint[], distances: number[]): DPoint[];
35
36
  findFi({ a, b }: DLine, delta?: number): number;
36
37
  vectorProduct({ a, b, c }: DLine): DLine;
38
+ bresenhamsLine(): DPolygon;
37
39
  }
package/dist/cjs/DLine.js CHANGED
@@ -4,6 +4,7 @@ exports.DLine = void 0;
4
4
  var DPoint_1 = require("./DPoint");
5
5
  var utils_1 = require("./utils");
6
6
  var DNumbers_1 = require("./DNumbers");
7
+ var DPolygon_1 = require("./DPolygon");
7
8
  var DLine = (function () {
8
9
  function DLine(a, b, c, begin, end) {
9
10
  if (begin === void 0) { begin = DPoint_1.DPoint.zero(); }
@@ -305,6 +306,38 @@ var DLine = (function () {
305
306
  var _b = this, q = _b.a, w = _b.b, e = _b.c;
306
307
  return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
307
308
  };
309
+ DLine.prototype.bresenhamsLine = function () {
310
+ var _a = this.begin, x0 = _a.x, y0 = _a.y;
311
+ var _b = this.end, x1 = _b.x, y1 = _b.y;
312
+ var dx = Math.abs(x1 - x0);
313
+ var sx = x0 < x1 ? 1 : -1;
314
+ var dy = -Math.abs(y1 - y0);
315
+ var sy = y0 < y1 ? 1 : -1;
316
+ var error = dx + dy;
317
+ var res = new DPolygon_1.DPolygon();
318
+ while (true) {
319
+ res.push(new DPoint_1.DPoint(x0, y0));
320
+ if (x0 === x1 && y0 === y1) {
321
+ break;
322
+ }
323
+ var e2 = 2 * error;
324
+ if (e2 >= dy) {
325
+ if (x0 === x1) {
326
+ break;
327
+ }
328
+ error += dy;
329
+ x0 += sx;
330
+ }
331
+ if (e2 <= dx) {
332
+ if (y0 === y1) {
333
+ break;
334
+ }
335
+ error += dx;
336
+ y0 += sy;
337
+ }
338
+ }
339
+ return res;
340
+ };
308
341
  return DLine;
309
342
  }());
310
343
  exports.DLine = DLine;
@@ -1004,13 +1004,16 @@ var DPolygon = (function () {
1004
1004
  }, []);
1005
1005
  case 'Feature': {
1006
1006
  var t = DPolygon.parse(a.geometry, format);
1007
+ var props_1 = __assign(__assign({}, a.properties), (a.id ? ({
1008
+ id: a.id
1009
+ }) : ({})));
1007
1010
  if (Array.isArray(t)) {
1008
1011
  t.forEach(function (record) {
1009
- record.properties = __assign(__assign({}, a.properties), { id: a.id });
1012
+ record.properties = __assign({}, props_1);
1010
1013
  });
1011
1014
  }
1012
1015
  else {
1013
- t.properties = __assign(__assign({}, a.properties), { id: a.id });
1016
+ t.properties = __assign({}, props_1);
1014
1017
  }
1015
1018
  return t;
1016
1019
  }
@@ -1,6 +1,7 @@
1
1
  import { DPoint } from './DPoint';
2
2
  import { checkFunction } from './utils';
3
3
  import { DNumbers } from './DNumbers';
4
+ import { DPolygon } from './DPolygon';
4
5
  export class DLine {
5
6
  constructor(a, b, c, begin = DPoint.zero(), end = DPoint.zero()) {
6
7
  this.a = a;
@@ -254,4 +255,36 @@ export class DLine {
254
255
  const { a: q, b: w, c: e } = this;
255
256
  return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
256
257
  }
258
+ bresenhamsLine() {
259
+ let { x: x0, y: y0 } = this.begin;
260
+ const { x: x1, y: y1 } = this.end;
261
+ const dx = Math.abs(x1 - x0);
262
+ const sx = x0 < x1 ? 1 : -1;
263
+ const dy = -Math.abs(y1 - y0);
264
+ const sy = y0 < y1 ? 1 : -1;
265
+ let error = dx + dy;
266
+ const res = new DPolygon();
267
+ while (true) {
268
+ res.push(new DPoint(x0, y0));
269
+ if (x0 === x1 && y0 === y1) {
270
+ break;
271
+ }
272
+ const e2 = 2 * error;
273
+ if (e2 >= dy) {
274
+ if (x0 === x1) {
275
+ break;
276
+ }
277
+ error += dy;
278
+ x0 += sx;
279
+ }
280
+ if (e2 <= dx) {
281
+ if (y0 === y1) {
282
+ break;
283
+ }
284
+ error += dx;
285
+ y0 += sy;
286
+ }
287
+ }
288
+ return res;
289
+ }
257
290
  }
@@ -646,13 +646,16 @@ export class DPolygon {
646
646
  }, []);
647
647
  case 'Feature': {
648
648
  const t = DPolygon.parse(a.geometry, format);
649
+ const props = Object.assign(Object.assign({}, a.properties), (a.id ? ({
650
+ id: a.id
651
+ }) : ({})));
649
652
  if (Array.isArray(t)) {
650
653
  t.forEach((record) => {
651
- record.properties = Object.assign(Object.assign({}, a.properties), { id: a.id });
654
+ record.properties = Object.assign({}, props);
652
655
  });
653
656
  }
654
657
  else {
655
- t.properties = Object.assign(Object.assign({}, a.properties), { id: a.id });
658
+ t.properties = Object.assign({}, props);
656
659
  }
657
660
  return t;
658
661
  }
package/dist/esm/DLine.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { DPoint } from './DPoint';
2
2
  import { checkFunction } from './utils';
3
3
  import { DNumbers } from './DNumbers';
4
+ import { DPolygon } from './DPolygon';
4
5
  var DLine = (function () {
5
6
  function DLine(a, b, c, begin, end) {
6
7
  if (begin === void 0) { begin = DPoint.zero(); }
@@ -302,6 +303,38 @@ var DLine = (function () {
302
303
  var _b = this, q = _b.a, w = _b.b, e = _b.c;
303
304
  return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
304
305
  };
306
+ DLine.prototype.bresenhamsLine = function () {
307
+ var _a = this.begin, x0 = _a.x, y0 = _a.y;
308
+ var _b = this.end, x1 = _b.x, y1 = _b.y;
309
+ var dx = Math.abs(x1 - x0);
310
+ var sx = x0 < x1 ? 1 : -1;
311
+ var dy = -Math.abs(y1 - y0);
312
+ var sy = y0 < y1 ? 1 : -1;
313
+ var error = dx + dy;
314
+ var res = new DPolygon();
315
+ while (true) {
316
+ res.push(new DPoint(x0, y0));
317
+ if (x0 === x1 && y0 === y1) {
318
+ break;
319
+ }
320
+ var e2 = 2 * error;
321
+ if (e2 >= dy) {
322
+ if (x0 === x1) {
323
+ break;
324
+ }
325
+ error += dy;
326
+ x0 += sx;
327
+ }
328
+ if (e2 <= dx) {
329
+ if (y0 === y1) {
330
+ break;
331
+ }
332
+ error += dx;
333
+ y0 += sy;
334
+ }
335
+ }
336
+ return res;
337
+ };
305
338
  return DLine;
306
339
  }());
307
340
  export { DLine };
@@ -1001,13 +1001,16 @@ var DPolygon = (function () {
1001
1001
  }, []);
1002
1002
  case 'Feature': {
1003
1003
  var t = DPolygon.parse(a.geometry, format);
1004
+ var props_1 = __assign(__assign({}, a.properties), (a.id ? ({
1005
+ id: a.id
1006
+ }) : ({})));
1004
1007
  if (Array.isArray(t)) {
1005
1008
  t.forEach(function (record) {
1006
- record.properties = __assign(__assign({}, a.properties), { id: a.id });
1009
+ record.properties = __assign({}, props_1);
1007
1010
  });
1008
1011
  }
1009
1012
  else {
1010
- t.properties = __assign(__assign({}, a.properties), { id: a.id });
1013
+ t.properties = __assign({}, props_1);
1011
1014
  }
1012
1015
  return t;
1013
1016
  }