-
Notifications
You must be signed in to change notification settings - Fork 18
/
create-line-uploaded.ts
144 lines (135 loc) · 5.2 KB
/
create-line-uploaded.ts
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright (C) 2019 Toshiba Corporation
* SPDX-License-Identifier: Apache-2.0
*/
import { EShape } from "../e-shape";
import { EShapeBuffer } from "../e-shape-buffer";
import { EShapePointsMarkerType } from "../e-shape-points-marker-type";
import { EShapeUploadedImpl } from "../e-shape-uploaded";
import { toLineIndexCount, toLinePointCount, toLineVertexCount } from "./build-line";
import { TEXT_INDEX_COUNT_SHIFT, TEXT_VERTEX_COUNT_SHIFT, toTextBufferCount } from "./build-text";
import { Builder, BuilderBuffer } from "./builder";
import { BuilderLine } from "./builder-line";
import { BuilderMarkerTriangleHead } from "./builder-marker-triangle-head";
import { BuilderMarkerTriangleTail } from "./builder-marker-triangle-tail";
import { BuilderMarkerCircleHead } from "./builder-marker-circle-head";
import { BuilderMarkerCircleTail } from "./builder-marker-circle-tail";
import { BuilderNull } from "./builder-null";
import { BuilderText } from "./builder-text";
import { EShapeLinePoints } from "./e-shape-line-points";
import { TRIANGLE_INDEX_COUNT, TRIANGLE_VERTEX_COUNT } from "./build-triangle";
import { CIRCLE_INDEX_COUNT, CIRCLE_VERTEX_COUNT } from "./build-circle";
import { BuilderMarkerRectangleTail } from "./builder-marker-rectangle-tail";
import { BuilderMarkerRectangleHead } from "./builder-marker-rectangle-head";
import { RECTANGLE_INDEX_COUNT, RECTANGLE_VERTEX_COUNT } from "./build-rectangle";
const toMarkerVertexCount = (type: EShapePointsMarkerType): number => {
switch (type) {
case EShapePointsMarkerType.NONE:
return 0;
case EShapePointsMarkerType.CIRCLE:
return CIRCLE_VERTEX_COUNT;
case EShapePointsMarkerType.TRIANGLE:
return TRIANGLE_VERTEX_COUNT;
case EShapePointsMarkerType.RECTANGLE:
return RECTANGLE_VERTEX_COUNT;
}
return 0;
};
const toMarkerIndexCount = (type: EShapePointsMarkerType): number => {
switch (type) {
case EShapePointsMarkerType.NONE:
return 0;
case EShapePointsMarkerType.CIRCLE:
return CIRCLE_INDEX_COUNT;
case EShapePointsMarkerType.TRIANGLE:
return TRIANGLE_INDEX_COUNT;
case EShapePointsMarkerType.RECTANGLE:
return RECTANGLE_INDEX_COUNT;
}
return 0;
};
const toBuilderMarkerHead = (
type: EShapePointsMarkerType,
buffer: BuilderBuffer,
vertexOffset: number,
indexOffset: number
): Builder => {
switch (type) {
case EShapePointsMarkerType.NONE:
return new BuilderNull(buffer, vertexOffset, indexOffset);
case EShapePointsMarkerType.CIRCLE:
return new BuilderMarkerCircleHead(buffer, vertexOffset, indexOffset);
case EShapePointsMarkerType.TRIANGLE:
return new BuilderMarkerTriangleHead(buffer, vertexOffset, indexOffset);
case EShapePointsMarkerType.RECTANGLE:
return new BuilderMarkerRectangleHead(buffer, vertexOffset, indexOffset);
}
return new BuilderNull(buffer, vertexOffset, indexOffset);
};
const toBuilderMarkerTail = (
type: EShapePointsMarkerType,
buffer: BuilderBuffer,
vertexOffset: number,
indexOffset: number
): Builder => {
switch (type) {
case EShapePointsMarkerType.NONE:
return new BuilderNull(buffer, vertexOffset, indexOffset);
case EShapePointsMarkerType.CIRCLE:
return new BuilderMarkerCircleTail(buffer, vertexOffset, indexOffset);
case EShapePointsMarkerType.TRIANGLE:
return new BuilderMarkerTriangleTail(buffer, vertexOffset, indexOffset);
case EShapePointsMarkerType.RECTANGLE:
return new BuilderMarkerRectangleTail(buffer, vertexOffset, indexOffset);
}
return new BuilderNull(buffer, vertexOffset, indexOffset);
};
export const createLineUploaded = (
buffer: EShapeBuffer,
shape: EShape,
voffset: number,
ioffset: number,
antialiasWeight: number
): EShapeUploadedImpl | null => {
// Line
const points = shape.points;
const pointCount = toLinePointCount(points);
const lvcount = toLineVertexCount(pointCount, true);
const licount = toLineIndexCount(pointCount, true);
// Markers
let mttype: EShapePointsMarkerType = EShapePointsMarkerType.NONE;
let mhtype: EShapePointsMarkerType = EShapePointsMarkerType.NONE;
if (points && points instanceof EShapeLinePoints) {
const marker = points.getMarker();
if (marker) {
mttype = marker.tail.type;
mhtype = marker.head.type;
}
}
const mtvcount = toMarkerVertexCount(mttype);
const mticount = toMarkerIndexCount(mttype);
const mtvoffset = voffset + lvcount;
const mtioffset = ioffset + licount;
const mhvcount = toMarkerVertexCount(mhtype);
const mhicount = toMarkerIndexCount(mhtype);
const mhvoffset = mtvoffset + mtvcount;
const mhioffset = mtioffset + mticount;
// Text
const tcount = toTextBufferCount(shape);
const tvcount = tcount << TEXT_VERTEX_COUNT_SHIFT;
const ticount = tcount << TEXT_INDEX_COUNT_SHIFT;
const tvoffset = mhvoffset + mhvcount;
const tioffset = mhioffset + mhicount;
// Uploaded
const vcount = lvcount + mhvcount + mtvcount + tvcount;
const icount = licount + mhicount + mticount + ticount;
if (buffer.check(voffset, ioffset, vcount, icount)) {
return new EShapeUploadedImpl(buffer, voffset, ioffset, vcount, icount, [
new BuilderLine(buffer, voffset, ioffset, lvcount, licount),
toBuilderMarkerTail(mttype, buffer, mtvoffset, mtioffset),
toBuilderMarkerHead(mhtype, buffer, mhvoffset, mhioffset),
new BuilderText(buffer, tvoffset, tioffset, tvcount, ticount)
]).init(shape);
}
return null;
};