-
Notifications
You must be signed in to change notification settings - Fork 0
/
HGBBonding.java
177 lines (151 loc) · 5.07 KB
/
HGBBonding.java
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package hgb;
// Bond (link) adjacent cells via cellPack.bondAry
public class HGBBonding
{
protected HGBBonding(HGBProgressions progressions, HGBShared hgbShared)
{
this.progressions = progressions;
this.hgbShared = hgbShared;
}
private HGBShared hgbShared;
private HGBProgressions progressions;
// Bond the cells together per established vectors stored in HGBShared.cellAry
// The return is modified HGBShared.cellAry
protected void bondVectorPetals_main(int[] verticesAry, int[] vectorToRoseAry, int[][] vectorPetalAry, int roseRing)
{
try
{
HGBCellPack roseBondPack = null;
if (roseRing == 0)
{
// no vectors as part of roseRing 0
roseBondPack = hgbShared.cellAry[0];
bondPetalsAboutRose(roseBondPack);
bondPetalsToRose(roseBondPack);
return;
}
int vertices = 0;
int vectorToRose = 0;
int roseIndex = 0;
//------------------------------------------------------
// The first and last rose and allocate the return
int[] range = progressions.roseRingRange(roseRing);
int roseCnt = ((range[1] - range[0]) / 10) + 1;
// There are three vectors per rose in the rose ring,
// except the 6 rose ring vertices, which only contain 2 vectors each.
int vectorCnt = (roseCnt * 3) - 6;
//------------------------------------------------------
int[] roseIndices = progressions.rosesPerRing(range);
if (roseIndices == null) return;
for (int index = 0; index < roseIndices.length; index++)
{
//-----------------------------------
roseIndex = roseIndices[index];
roseBondPack = hgbShared.cellAry[roseIndex];
bondPetalsAboutRose(roseBondPack);
bondPetalsToRose(roseBondPack);
//-----------------------------------
}
//------------------------------------------------------
for (int inx = 0; inx < vectorCnt; inx++)
{
vertices = verticesAry[inx];
vectorToRose = vectorToRoseAry[inx];
int[] vectorPetals = vectorPetalAry[inx];
// pass the vertex origin of the vector, rose pointed to and the bond sides
bondPeltal(vertices, vectorToRose, vectorPetals);
}
}
catch (Exception exc)
{
return;
}
}
// Bond two adjacent petal, 2 sides together for each.
// The output is modified HGBShared.cellAry
private void bondPeltal(int vertex, int toRose, int[] vectorPetals)
{
try
{
int petalIndex = vectorPetals[0];
int[] vectorSideBonds = HGBStatics.vectorSideBonds[vertex];
int[] targetUnits = HGBStatics.targetUnits[vertex];
HGBCellPack outerPetalBondPack = hgbShared.cellAry[petalIndex];
HGBCellPack innerPetalBondPack = null;
// Bond the vector direct petals
for (int inx = 0; inx < 2; inx++)
{
int innerPetalIndex = toRose + targetUnits[inx];
innerPetalBondPack = hgbShared.cellAry[innerPetalIndex];
int oppositeSide = HGBStatics.oppositeSides[vectorSideBonds[inx]];
// Bond these two sides
outerPetalBondPack.bondAry[vectorSideBonds[inx]] = innerPetalIndex;
innerPetalBondPack.bondAry[oppositeSide] = petalIndex;
}
// Bond the vector indirect petals
petalIndex = vectorPetals[1];
outerPetalBondPack = hgbShared.cellAry[petalIndex];
int innerPetalIndex = toRose + targetUnits[1];
innerPetalBondPack = hgbShared.cellAry[innerPetalIndex];
int oppositeSide = HGBStatics.oppositeSides[vectorSideBonds[0]];
// Bond these two sides
outerPetalBondPack.bondAry[vectorSideBonds[0]] = innerPetalIndex;
innerPetalBondPack.bondAry[oppositeSide] = petalIndex;
}
catch (Exception exc)
{
return;
}
}
// Each rose is bonded to the petals about it (clockwise)
private void bondPetalsToRose(HGBCellPack cellPack)
{
try
{
int roseIndex = cellPack.getIndex();
int petalIndex = roseIndex;
for (int inx = 0; inx < HGBShared.SIDES; inx++)
{
cellPack.bondAry[inx] = ++petalIndex;
HGBCellPack petalPack = hgbShared.cellAry[petalIndex];
int index = HGBStatics.oppositeSides[inx];
petalPack.bondAry[index] = roseIndex;
}
}
catch (Exception exc)
{
return;
}
}
// Each petal about the rose is bonded with petals on either side.
private void bondPetalsAboutRose(HGBCellPack cellPack)
{
int roseIndex = cellPack.getIndex();
int petalIndex = roseIndex;
int firstPetalIndex = roseIndex + 1;
int lastPetalIndex = roseIndex + 6;
int side = 2;
try
{
for (int inx = 0; inx < HGBShared.SIDES; inx++)
{
petalIndex++;
HGBCellPack petalPack = hgbShared.cellAry[petalIndex];
int nextPetalIndex = petalIndex + 1;
if (nextPetalIndex > lastPetalIndex) nextPetalIndex = firstPetalIndex;
HGBCellPack nextPetalPack = hgbShared.cellAry[nextPetalIndex];
petalPack.bondAry[side] = nextPetalIndex;
int index = HGBStatics.oppositeSides[side];
nextPetalPack.bondAry[index] = petalIndex;
side++;
side = (side == 6) ? 0 : side;
//System.out.println("");
}
}
catch (Exception exc)
{
return;
}
}
//------------------------------------------------------------
}