Libraryless. Click here for Pure Java version (12014L/70K).
1 | srecord noeq G22MeshMapper(G22Mesh mesh1, G22Mesh mesh2) > AbstractSteppable { |
2 | // import the important classes |
3 | delegate Anchor, Curve to G22Mesh. |
4 | |
5 | // MAPPING VARS |
6 | |
7 | // keys are the anchors from mesh1, values are the anchors from mesh2 |
8 | new Map<Anchor> anchorMap; |
9 | |
10 | // keys are the curves from mesh1, values are the curves from mesh2 |
11 | new Map<Curve> mappedCurves; |
12 | |
13 | // EXCEPTIONS (e.g. meshes don't match in signature) |
14 | |
15 | // set to the reason why when a mapping is deemed impossible |
16 | settable O rejectedBecause; |
17 | |
18 | bool rejected() { ret rejectedBecause != null; } |
19 | |
20 | // INTERNAL VARS |
21 | |
22 | bool prechecksDone; |
23 | S sig1, sig2; |
24 | |
25 | // Anchors and curves in mesh1 that are not or only partially mapped. |
26 | // This list is not complete at the beginning. Anchors and curves are |
27 | // discovered by searching breadth-first from the visited anchors and |
28 | // curves. |
29 | new L<Anchor> mappableAnchors; |
30 | |
31 | // curves that are half-mapped (one end is mapped) indexed by the |
32 | // unmapped anchor |
33 | new MultiMap<Anchor, Curve> halfMappedCurves; |
34 | |
35 | // anchor lookup mesh 1 |
36 | // MultiMap<Int, Anchor> anchorsByArity1; |
37 | |
38 | // anchor lookup mesh 2 |
39 | MultiMap<Int, Anchor> anchorsByArity2; |
40 | |
41 | // First let's define the search procedure in a "normal" (native) |
42 | // control flow. Then possibly convert to v-stack/coroutine. |
43 | |
44 | void searchForMapping { |
45 | prechecks(); if (rejected()) ret; |
46 | anchorsByArity2 = multiMapIndex(mesh2.anchors(), a -> a.arity()); |
47 | |
48 | Anchor anchor1 = first(mesh1.anchors()); |
49 | for (anchor2 : anchorsByArity2.get(anchor1.arity())) { |
50 | temp tempAssignAnchor(anchor1, anchor2); |
51 | |
52 | //while (nempty(mappableCurves)) |
53 | } |
54 | } |
55 | |
56 | AutoCloseable tempAssignAnchor(Anchor anchor1, Anchor anchor2) { |
57 | var undoAnchorAssignment = tempMapPutStrictlyOrFail(anchorMap, anchor1, anchor2); |
58 | |
59 | // Check all curves connected to anchor1. They will now be at least |
60 | // half mapped. |
61 | for (curve : anchor1.curves()) { |
62 | Curve curve2 = calculateCurveMapping(curve); |
63 | if (curve2 != null) { |
64 | halfMappedCurves.remove(anchor1, curve); |
65 | mappedCurves.put(curve, curve2); |
66 | } else |
67 | halfMappedCurves.put(curve.anchorOpposite(anchor1), curve); |
68 | } |
69 | |
70 | ret -> { |
71 | _close(undoAnchorAssignment); |
72 | |
73 | for (curve : anchor1.curves()) { |
74 | mappedCurves.remove(curve); |
75 | if (nCurveAnchorsAssigned(curve) == 0) { |
76 | halfMappedCurves.remove(anchor1, curve); |
77 | } |
78 | } |
79 | }; |
80 | } |
81 | |
82 | int nCurveAnchorsAssigned(Curve curve1) { |
83 | // count twice if stat+end is same anchor |
84 | ret zeroOrOne(anchorMap.containsKey(curve1.start())) |
85 | + zeroOrOne(anchorMap.containsKey(curve1.end())); |
86 | } |
87 | |
88 | Curve calculateCurveMapping(Curve curve1) { |
89 | fail(); |
90 | // TODO: there are possibly multiple choices here! |
91 | } |
92 | |
93 | public bool step() { |
94 | if (!prechecksDone) { |
95 | prechecks(); |
96 | ret !rejected(); |
97 | } |
98 | |
99 | false; // TODO |
100 | } |
101 | |
102 | protected void prechecks { |
103 | set prechecksDone; |
104 | sig1 = mesh1.signature(); |
105 | sig2 = mesh1.signature(); |
106 | if (!eq(sig1, sig2)) |
107 | ret with rejectedBecause(G22SignatureMismatch(mesh1, mesh2)); |
108 | } |
109 | } |
Began life as a copy of #1035062
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035358 |
Snippet name: | G22MeshMapper - tries to map mesh1 to mesh2 [dev.] |
Eternal ID of this version: | #1035358/8 |
Text MD5: | c8855b77c31c0f32d3b2a44079c60695 |
Transpilation MD5: | 0a755ef84091d6875d74e2de97b91a34 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-02 01:45:30 |
Source code size: | 3271 bytes / 109 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 125 / 250 |
Version history: | 7 change(s) |
Referenced in: | [show references] |