Libraryless. Click here for Pure Java version (15428L/89K).
1 | // VectorSSI - SSI with straight line segments |
2 | |
3 | persistable sclass VectorSSI extends AbstractSSI { |
4 | replace X with short. |
5 | replace Y with short. |
6 | replace toX with toShort_enforce. |
7 | replace toY with toShort_enforce. |
8 | replace newXArray with newShortArrayOrNull. |
9 | |
10 | // core values (mandatory): first column and row occupied |
11 | settable X x1; |
12 | settable Y y1; |
13 | |
14 | // Curves of x start and x end, relative to (x1, y1) |
15 | // Both have same length |
16 | settable InterpolatedDoubleArray leftCurve; |
17 | settable InterpolatedDoubleArray rightCurve; |
18 | |
19 | *(SSI ssi) { |
20 | ssi.copyAbstractSSI(this); |
21 | Rect r = ssi.bounds(); |
22 | x1(toX(r.x1())); |
23 | y1(toY(r.y1())); |
24 | int h = r.h(); |
25 | int[] left = new int[h], right = new int[h]; |
26 | for y to h: { |
27 | left[y] = ssi.getLeft(y1+y)-x1; |
28 | right[y] = ssi.getRight(y1+y)-x1; |
29 | } |
30 | leftCurve(CompressToInterpolatedDoubleArray(left)!); |
31 | rightCurve(CompressToInterpolatedDoubleArray(right)!); |
32 | } |
33 | |
34 | public int height aka h() { |
35 | ret leftCurve.length(); |
36 | } |
37 | |
38 | int y2() { |
39 | ret y1+h(); |
40 | } |
41 | |
42 | SSI toSSI aka get() { |
43 | int h = h(); |
44 | var ssi = new SSI(y1, y2()); |
45 | copyAbstractSSI(ssi); |
46 | int[] left = leftCurve.rounded(); |
47 | int[] right = rightCurve.rounded(); |
48 | for y to h: |
49 | ssi.set(y1+y, x1+left[y], x1+right[y]); |
50 | ret ssi; |
51 | } |
52 | |
53 | public void drawOn(Graphics2D g) { |
54 | toSSI().drawOn(g); |
55 | } |
56 | |
57 | // How many points define the shape of this vector SSI |
58 | // (left + right border) |
59 | int nPoints() { |
60 | ret leftCurve.nPillars() + rightCurve.nPillars(); |
61 | } |
62 | |
63 | public long sizeInInts() { |
64 | // "v", color, x1, y1, height(), leftCurve, rightCurve |
65 | ret 5+leftCurve.nInts/*_withoutFirstAndLastIndex*/()+rightCurve.nInts/*_withoutFirstAndLastIndex*/(); |
66 | } |
67 | |
68 | // TODO |
69 | /*VectorSSI reduceToInts(int ints) { |
70 | ints -= 5; // constant part |
71 | int nPillars = ints/2; // max pillars we can afford (left+right) |
72 | }*/ |
73 | |
74 | // optimizable |
75 | public simplyCached Rect bounds() { |
76 | ret toSSI().bounds(); |
77 | } |
78 | |
79 | public simplyCached int numberOfPixels() { |
80 | ret toSSI().numberOfPixels(); |
81 | } |
82 | |
83 | public void readWrite(StringHead head) { |
84 | head.exchangeLine(l0 toLine, l1 fromLine); |
85 | } |
86 | |
87 | S toLine() { |
88 | L elements = ll("v", colorToString(), x1, y1, height()); |
89 | addAll(elements, asList(iroundAll(leftCurve.indicesAndValues/*_withoutFirstAndLastIndex*/()))); |
90 | addAll(elements, asList(iroundAll(rightCurve.indicesAndValues/*_withoutFirstAndLastIndex*/()))); |
91 | ret spaceCombine(elements); |
92 | } |
93 | |
94 | void fromLine(S line) { |
95 | Iterator<S> it = splitAtSpaceIterator(line); |
96 | assertEquals("v", nextFromIterator(it)); |
97 | x1 = toX(parseInt(nextFromIterator(it))); |
98 | y1 = toY(parseInt(nextFromIterator(it))); |
99 | // TODO |
100 | /*int h = parseInt(nextFromIterator(it)); |
101 | init(y1, y1+h); |
102 | for i over data: |
103 | data[i] = toX(parseInt(nextFromIterator(it)));*/ |
104 | } |
105 | } |
Began life as a copy of #1035561
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035709 |
Snippet name: | VectorSSI |
Eternal ID of this version: | #1035709/34 |
Text MD5: | 4ff44a92e94995758951e00fbace2aa4 |
Transpilation MD5: | d6a12154ab80c86366ff759fa7c5ccc5 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-07-25 14:41:17 |
Source code size: | 2964 bytes / 105 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 222 / 427 |
Version history: | 33 change(s) |
Referenced in: | [show references] |