1 | scope regionBorder_innerPoints. |
2 | |
3 | static Pt[] #directions = { |
4 | pt(1, 0), pt(0, 1), pt(-1, 0), pt(0, -1) // r, d, l, u |
5 | }; |
6 | |
7 | static L<Pt> regionBorder_innerPoints(BWImage_FastRegions regions, int iRegion) { |
8 | new PtBuffer out; |
9 | Pt p = regions.samplePixel(iRegion); |
10 | int x = p.x, y = p.y; |
11 | |
12 | // move up until we're at the edge of the region |
13 | // probably we don't actually need to do this because of the way |
14 | // the image was scanned, but we'll do it anyway |
15 | while (y > 0 && regions.inRegion(iRegion, x, y-1)) |
16 | y--; |
17 | |
18 | // found our first border pixel with background above |
19 | int dir = 3; // direction up |
20 | |
21 | // remember first point |
22 | int firstX = x, firstY = y; |
23 | |
24 | int safety = regions.size(); |
25 | loop: do { |
26 | out.add(x, y); |
27 | for (int turn = 3; turn <= 6; turn++) { // try left, straight, right, back |
28 | int newDir = (dir+turn) & 3; |
29 | Pt d = directions[newDir]; |
30 | int x2 = x+d.x, y2 = y+d.y; |
31 | if (regions.inRegion(x2, y2, iRegion)) { |
32 | x = x2; y = y2; dir = newDir; |
33 | continue loop; |
34 | } |
35 | } |
36 | |
37 | // if we get here, the region is just 1 pixel (so we're done) |
38 | break; |
39 | } while ((x != firstX || y != firstY) && --safety >= 0); |
40 | |
41 | ret out; |
42 | } |
Began life as a copy of #1033758
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033763 |
Snippet name: | regionBorder_innerPoints backup |
Eternal ID of this version: | #1033763/1 |
Text MD5: | 4cf94f6efdb69afa39d3ce19760ca768 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-02 05:01:58 |
Source code size: | 1236 bytes / 42 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 125 / 140 |
Referenced in: | [show references] |