File size: 1,343 Bytes
2b7aae2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Path } from './Path.js';
import * as MathUtils from '../../math/MathUtils.js';

class Shape extends Path {
	constructor(points) {
		super(points);

		this.uuid = MathUtils.generateUUID();

		this.type = 'Shape';

		this.holes = [];
	}

	getPointsHoles(divisions) {
		const holesPts = [];

		for (let i = 0, l = this.holes.length; i < l; i++) {
			holesPts[i] = this.holes[i].getPoints(divisions);
		}

		return holesPts;
	}

	// get points of shape and holes (keypoints based on segments parameter)

	extractPoints(divisions) {
		return {
			shape: this.getPoints(divisions),
			holes: this.getPointsHoles(divisions),
		};
	}

	copy(source) {
		super.copy(source);

		this.holes = [];

		for (let i = 0, l = source.holes.length; i < l; i++) {
			const hole = source.holes[i];

			this.holes.push(hole.clone());
		}

		return this;
	}

	toJSON() {
		const data = super.toJSON();

		data.uuid = this.uuid;
		data.holes = [];

		for (let i = 0, l = this.holes.length; i < l; i++) {
			const hole = this.holes[i];
			data.holes.push(hole.toJSON());
		}

		return data;
	}

	fromJSON(json) {
		super.fromJSON(json);

		this.uuid = json.uuid;
		this.holes = [];

		for (let i = 0, l = json.holes.length; i < l; i++) {
			const hole = json.holes[i];
			this.holes.push(new Path().fromJSON(hole));
		}

		return this;
	}
}

export { Shape };