dgeoutils 2.4.34 → 2.4.35
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.
- package/dist/cjs/DLine.d.ts +2 -0
- package/dist/cjs/DLine.js +33 -0
- package/dist/es2015/DLine.js +33 -0
- package/dist/esm/DLine.js +33 -0
- package/dist/umd/dgeoutils.js +1049 -1017
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/DLine.d.ts
CHANGED
|
@@ -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;
|
package/dist/es2015/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
|
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
|
}
|
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 };
|