1 | const CAG = require('./CAG')
|
2 | const Side = require('./math/Side')
|
3 | const Vector2D = require('./math/Vector2')
|
4 | const Vertex = require('./math/Vertex2')
|
5 | const Path2 = require('./math/Path2')
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const fromObject = function (obj) {
|
12 | let sides = obj.sides.map(function (s) {
|
13 | return Side.fromObject(s)
|
14 | })
|
15 | let cag = CAG.fromSides(sides)
|
16 | cag.isCanonicalized = obj.isCanonicalized
|
17 | return cag
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | const fromPointsNoCheck = function (points) {
|
29 | let sides = []
|
30 | let prevpoint = new Vector2D(points[points.length - 1])
|
31 | let prevvertex = new Vertex(prevpoint)
|
32 | points.map(function (p) {
|
33 | let point = new Vector2D(p)
|
34 | let vertex = new Vertex(point)
|
35 | let side = new Side(prevvertex, vertex)
|
36 | sides.push(side)
|
37 | prevvertex = vertex
|
38 | })
|
39 | return CAG.fromSides(sides)
|
40 | }
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | const fromPath2 = function (path) {
|
48 | if (!path.isClosed()) throw new Error('The path should be closed!')
|
49 | return CAG.fromPoints(path.getPoints())
|
50 | }
|
51 |
|
52 |
|
53 | module.exports = {
|
54 | fromObject,
|
55 | fromPointsNoCheck,
|
56 | fromPath2
|
57 |
|
58 | }
|