Libraryless. Click here for Pure Java version (9921L/55K).
1 | persistable sclass GSI extends AbstractHasHi15Color is G2Drawable, IPixelSet {
|
2 | int y1; // starting y coordinate |
3 | int[] rowStarts; // where in xData each row starts |
4 | int[] xData; // all x coordinates in a long list (x1, x2, x1, x2, ...) |
5 | |
6 | *(int *y1, int[] *rowStarts, int[] *xData) {}
|
7 | |
8 | public int getHeight() { ret rowStarts.length; }
|
9 | int y2() { ret y1+rowStarts.length; }
|
10 | |
11 | // bounds are calculated & cached transiently |
12 | public simplyCached Rect bounds() {
|
13 | int x1 = Int.MAX_VALUE, x2 = 0; |
14 | for (int i = 0; i < xData.length; i += 2) {
|
15 | x1 = min(x1, xData[i]); |
16 | x2 = max(x2, xData[i+1]); |
17 | } |
18 | ret rectFromPoints(x1, y1, x2, y2()); |
19 | } |
20 | |
21 | public bool contains(Pt p) { ret contains(p.x, p.y); }
|
22 | public bool contains(int x, int y) {
|
23 | if (y < y1 || y >= y2()) false; |
24 | int i1 = rowStart(y), i2 = rowEnd(y); |
25 | for (int i = i1; i < i2; i += 2) |
26 | if (x < xData[i+1]) |
27 | // found the right entry to check |
28 | ret x >= xData[i]; |
29 | false; |
30 | } |
31 | |
32 | int rowStart(int y) { ret rowStarts[y-y1]; }
|
33 | int rowEnd(int y) {
|
34 | ret y == y2()-1 ? rowStarts.length : rowStarts[y-y1+1]; |
35 | } |
36 | |
37 | public void drawOn(Graphics2D g) {
|
38 | g.setColor(color()); |
39 | int h = height(); |
40 | for y to h: {
|
41 | int i1 = rowStart(y-y1), i2 = rowEnd(y-y1); |
42 | for (int i = i1; i < i2; i += 2) {
|
43 | int x1 = xData[i], x2 = xData[i+1]; |
44 | if (x1 < x2) |
45 | g.drawLine(x1, y1+y, x2-1, y1+y); |
46 | } |
47 | } |
48 | } |
49 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): mowyntqkapby, mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
| Snippet ID: | #1035816 |
| Snippet name: | GSI [General Scanline Image, multiple horizontal lines per row] |
| Eternal ID of this version: | #1035816/13 |
| Text MD5: | 3a89beba9a579207ef407f269ff7788d |
| Transpilation MD5: | a63a4301d8e399cddc1ae0f8c0b6bfcc |
| Author: | stefan |
| Category: | javax / gazelle 22 |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-09-12 16:50:42 |
| Source code size: | 1504 bytes / 49 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 582 / 736 |
| Version history: | 12 change(s) |
| Referenced in: | [show references] |