Skip to content

Commit d65d90e

Browse files
authored
Merge branch 'main' into feature/make-critvol-settable
2 parents 306c816 + cbfe37e commit d65d90e

File tree

15 files changed

+663
-276
lines changed

15 files changed

+663
-276
lines changed

.github/config/checks.xml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@
2828
<module name="Translation" />
2929

3030
<!-- Checks for size violations -->
31-
<module name="FileLength" />
32-
<module name="LineLength">
33-
<property name="id" value="LineLength"/>
34-
<property name="fileExtensions" value="java" />
35-
<property name="max" value="100"/>
31+
<!-- Error-level FileLength (for src files) -->
32+
<module name="FileLength">
33+
<property name="id" value="FileLengthError"/>
34+
<property name="max" value="2000"/>
35+
<property name="severity" value="error"/>
36+
</module>
37+
<!-- Warning-level FileLength (for test files) -->
38+
<module name="FileLength">
39+
<property name="id" value="FileLengthWarn"/>
40+
<property name="max" value="2000"/>
41+
<property name="severity" value="warning"/>
3642
</module>
3743
<module name="LineLength">
3844
<property name="id" value="LineLengthTest"/>
@@ -183,7 +189,11 @@
183189
<!-- Miscellaneous other checks -->
184190
<module name="ArrayTypeStyle" />
185191
<module name="CommentsIndentation" />
186-
<module name="TodoComment" />
187192
<module name="UpperEll" />
193+
194+
<!-- TODO comments raise warnings but don't throw errors -->
195+
<module name="TodoComment">
196+
<property name="severity" value="warning" />
197+
</module>
188198
</module>
189199
</module>

.github/config/suppressions.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<!-- Checks for size violations -->
1212
<suppress checks="LineLength" files="test/*" id="LineLength" />
13+
<suppress checks="LineLengthTest" files="src/*" id="LineLength" />
1314

1415
<!-- Checks for Javadoc comments -->
1516
<suppress checks="JavadocVariable" files="test/*" />
@@ -21,4 +22,14 @@
2122

2223
<!-- Checks for class design-->
2324
<suppress checks="VisibilityModifier" files="/sim/*" />
25+
26+
27+
<!-- Checks for filelengths -->
28+
<suppress checks="FileLength"
29+
id="FileLengthError"
30+
files="test/*" />
31+
<!-- Suppress warning-level FileLength in non-test files -->
32+
<suppress checks="FileLength"
33+
id="FileLengthWarn"
34+
files="src/*" />
2435
</suppressions>

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515
fetch-depth: 0
1616

1717
- name: Lint code base
18-
uses: dbelyaev/action-checkstyle@v0.9.5
18+
uses: dbelyaev/action-checkstyle@v3.0.0
1919
with:
2020
github_token: ${{ secrets.GITHUB_TOKEN }}
2121
reporter: github-check
2222
checkstyle_config: .github/config/checks.xml
23-
fail_on_error: true
23+
fail_level: error
2424

2525
update-lint-badges:
2626
if: ${{ always() && github.ref == 'refs/heads/main' }}

src/arcade/core/gui/GUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public File getPath() {
371371
}
372372

373373
/** Custom file filter for XML files. */
374-
private static class XMLFileFilter extends FileFilter {
374+
private static final class XMLFileFilter extends FileFilter {
375375
/**
376376
* Determines if the file is an XML file.
377377
*

src/arcade/potts/env/location/PottsLocation.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import arcade.core.env.location.LocationContainer;
1111
import arcade.core.util.Plane;
1212
import arcade.core.util.Utilities;
13+
import arcade.core.util.Vector;
14+
import arcade.potts.util.PottsEnums.Direction;
15+
import arcade.potts.util.PottsEnums.Region;
1316
import static arcade.potts.util.PottsEnums.Direction;
1417
import static arcade.potts.util.PottsEnums.Region;
1518

@@ -605,6 +608,16 @@ void updateCenter(int x, int y, int z, int change) {
605608
*/
606609
abstract ArrayList<Voxel> getSelected(Voxel focus, double n);
607610

611+
/**
612+
* Gets the voxel at specified percentage offsets along the location's axes with the provided
613+
* ApicalAxis considered to be pointing up the Y axis.
614+
*
615+
* @param offsets the percent offsets along the location's axes
616+
* @param apicalAxis the axis considered to be pointing up along the Y axis
617+
* @return the voxel at the specified offset in the frame of the apical axis
618+
*/
619+
abstract Voxel getOffsetInApicalFrame(ArrayList<Integer> offsets, Vector apicalAxis);
620+
608621
/**
609622
* Gets the direction of the slice orthagonal to the direction with the smallest diameter.
610623
*

src/arcade/potts/env/location/PottsLocation2D.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package arcade.potts.env.location;
22

33
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.Comparator;
46
import java.util.HashMap;
7+
import arcade.core.util.Vector;
58
import static arcade.potts.util.PottsEnums.Direction;
69

710
/** Concrete implementation of {@link PottsLocation} for 2D. */
@@ -64,4 +67,57 @@ Direction getSlice(Direction direction, HashMap<Direction, Integer> diameters) {
6467
ArrayList<Voxel> getSelected(Voxel focus, double n) {
6568
return Location2D.getSelected(voxels, focus, n);
6669
}
70+
71+
/**
72+
* Gets the voxel at specified percentage offsets along the location's X and Y axes with the
73+
* provided apicalAxis considered to be pointing up the Y axis. Returns null if this
74+
* PottsLocation2D contains no voxels.
75+
*
76+
* @param offsets the percent offsets along the location's X and Y axes
77+
* @param apicalAxis the axis considered to be pointing up along the Y axis
78+
* @return the voxel through which the plane of division will pass
79+
*/
80+
@Override
81+
public Voxel getOffsetInApicalFrame(ArrayList<Integer> offsets, Vector apicalAxis) {
82+
if (voxels.isEmpty()) {
83+
return null;
84+
}
85+
if (offsets == null || offsets.size() != 2) {
86+
throw new IllegalArgumentException("Offsets must be 2 integers.");
87+
}
88+
89+
// Normalize axes
90+
Vector yAxis = Vector.normalizeVector(apicalAxis);
91+
Vector xAxis = Vector.normalizeVector(new Vector(apicalAxis.getY(), -apicalAxis.getX(), 0));
92+
93+
// Project voxels onto apical axis and group by rounded projection
94+
HashMap<Integer, ArrayList<Voxel>> apicalBands = new HashMap<>();
95+
ArrayList<Integer> apicalKeys = new ArrayList<>();
96+
97+
for (Voxel v : voxels) {
98+
Vector pos = new Vector(v.x, v.y, 0);
99+
double apicalProj = Vector.dotProduct(pos, yAxis);
100+
int roundedProj = (int) Math.round(apicalProj);
101+
apicalBands.computeIfAbsent(roundedProj, k -> new ArrayList<>()).add(v);
102+
apicalKeys.add(roundedProj);
103+
}
104+
105+
// Sort apical keys and choose percentile
106+
Collections.sort(apicalKeys);
107+
int yIndex =
108+
Math.min(
109+
apicalKeys.size() - 1,
110+
(int) ((offsets.get(1) / 100.0) * apicalKeys.size()));
111+
int targetApicalKey = apicalKeys.get(yIndex);
112+
113+
ArrayList<Voxel> band = apicalBands.get(targetApicalKey);
114+
if (band == null || band.isEmpty()) {
115+
return null;
116+
}
117+
// Project to orthogonal axis within the band and sort
118+
band.sort(
119+
Comparator.comparingDouble(v -> Vector.dotProduct(new Vector(v.x, v.y, 0), xAxis)));
120+
int xIndex = Math.min(band.size() - 1, (int) ((offsets.get(0) / 100.0) * band.size()));
121+
return band.get(xIndex);
122+
}
67123
}

src/arcade/potts/env/location/PottsLocation3D.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.ArrayList;
44
import java.util.HashMap;
5+
import arcade.core.util.Vector;
6+
import arcade.potts.util.PottsEnums.Direction;
57
import static arcade.potts.util.PottsEnums.Direction;
68

79
/** Concrete implementation of {@link PottsLocation} for 3D. */
@@ -64,4 +66,10 @@ Direction getSlice(Direction direction, HashMap<Direction, Integer> diameters) {
6466
ArrayList<Voxel> getSelected(Voxel focus, double n) {
6567
return Location3D.getSelected(voxels, focus, n);
6668
}
69+
70+
@Override
71+
Voxel getOffsetInApicalFrame(ArrayList<Integer> offsets, Vector apicalAxis) {
72+
throw new UnsupportedOperationException(
73+
"getOffsetInApicalFrame is not implemented for PottsLocation3D");
74+
}
6775
}

src/arcade/potts/env/location/PottsLocations.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import ec.util.MersenneTwisterFast;
77
import arcade.core.env.location.Location;
88
import arcade.core.env.location.LocationContainer;
9+
import arcade.core.util.Vector;
10+
import arcade.potts.util.PottsEnums.Region;
911
import static arcade.potts.util.PottsEnums.Region;
1012

1113
/**
@@ -286,4 +288,10 @@ Location separateVoxels(
286288

287289
return splitLocation;
288290
}
291+
292+
@Override
293+
Voxel getOffsetInApicalFrame(ArrayList<Integer> offsets, Vector apicalAxis) {
294+
throw new UnsupportedOperationException(
295+
"getOffsetInApicalFrame is not implemented for PottsLocations");
296+
}
289297
}

src/arcade/potts/env/location/PottsLocations2D.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.ArrayList;
44
import java.util.HashMap;
5+
import arcade.core.util.Vector;
6+
import arcade.potts.util.PottsEnums.Direction;
7+
import arcade.potts.util.PottsEnums.Region;
58
import static arcade.potts.util.PottsEnums.Direction;
69
import static arcade.potts.util.PottsEnums.Region;
710

@@ -70,4 +73,10 @@ Direction getSlice(Direction direction, HashMap<Direction, Integer> diameters) {
7073
ArrayList<Voxel> getSelected(Voxel focus, double n) {
7174
return Location2D.getSelected(locations.get(Region.DEFAULT).voxels, focus, n);
7275
}
76+
77+
@Override
78+
Voxel getOffsetInApicalFrame(ArrayList<Integer> offsets, Vector apicalAxis) {
79+
throw new UnsupportedOperationException(
80+
"getOffsetInApicalFrame is not implemented for PottsLocations2D");
81+
}
7382
}

0 commit comments

Comments
 (0)