Skip to content

Commit 11287cd

Browse files
committed
spotless apply + splitBagDupesRandomly
1 parent 79930c5 commit 11287cd

4 files changed

Lines changed: 115 additions & 52 deletions

File tree

src/arcade/potts/agent/module/PottsModuleFlyStemProliferation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import arcade.potts.util.PottsEnums.Phase;
2929
import arcade.potts.util.PottsEnums.Side;
3030
import arcade.potts.util.PottsEnums.State;
31+
import arcade.potts.util.PottsUtilities;
3132
import static arcade.potts.util.PottsEnums.Direction;
3233
import static arcade.potts.util.PottsEnums.Phase;
3334
import static arcade.potts.util.PottsEnums.State;
@@ -207,6 +208,8 @@ public void addCell(MersenneTwisterFast random, Simulation sim) {
207208
PottsLocation.getDirectionalVoxelSubset(
208209
Side.BASAL, 0.33, voxels, centroid, apicalAxis);
209210

211+
PottsUtilities.splitBagDupesRandomly(apicalVoxels, basalVoxels, random);
212+
210213
PottsLocation daughterLoc = (PottsLocation) parentLoc.split(random, divisionPlane);
211214

212215
double basalFrac = voxelFraction(basalVoxels, daughterLoc);

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,8 @@ Direction getDirection(MersenneTwisterFast random) {
659659
* Gets the voxels up to a threshold from a side of the cell.
660660
*
661661
* @param side the side of the cell, must be APICAL or BASAL
662-
* @param thresholdPercent the threshold percent of voxels to get,
663-
* must be between 0 and 1 (inclusive)
662+
* @param thresholdPercent the threshold percent of voxels to get, must be between 0 and 1
663+
* (inclusive)
664664
* @param voxels the list of voxels in the cell to check
665665
* @param centroid the centroid of the cell
666666
* @param apicalAxis the apical axis of the cell
@@ -674,11 +674,10 @@ public static Bag getDirectionalVoxelSubset(
674674
Vector apicalAxis) {
675675

676676
if (thresholdPercent < 0 || thresholdPercent > 1) {
677-
throw new IllegalArgumentException("The threshold perfect of voxels to get is not " +
678-
"between 0 and 1.");
677+
throw new IllegalArgumentException(
678+
"The threshold perfect of voxels to get is not " + "between 0 and 1.");
679679
}
680680

681-
682681
double minProj = Double.MAX_VALUE;
683682
double maxProj = -Double.MAX_VALUE;
684683
double[] projections = new double[voxels.size()];
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package arcade.potts.util;
2+
3+
import sim.util.Bag;
4+
import ec.util.MersenneTwisterFast;
5+
6+
/** Utility class providing static helper methods for Potts simulations. */
7+
public final class PottsUtilities {
8+
9+
/** Hidden utility class constructor. */
10+
protected PottsUtilities() {
11+
throw new UnsupportedOperationException();
12+
}
13+
14+
public static void splitBagDupesRandomly(
15+
Bag firstBag, Bag secondBag, MersenneTwisterFast random) {
16+
for (int i = firstBag.numObjs - 1; i >= 0; i--) {
17+
Object obj = firstBag.objs[i];
18+
if (secondBag.contains(obj)) {
19+
if (random.nextBoolean()) {
20+
secondBag.remove(obj);
21+
} else {
22+
firstBag.remove(i);
23+
}
24+
}
25+
}
26+
}
27+
}

test/arcade/potts/env/location/PottsLocationTest.java

Lines changed: 81 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,6 @@ public void getDirectionalVoxelSubset_allApical_returnsCorrectBag() {
17571757
for (int i = 0; i < 5; i++) {
17581758
voxels.add(new Voxel(0, 0, i));
17591759
expected.add(new Voxel(0, 0, i));
1760-
17611760
}
17621761
Bag result =
17631762
PottsLocation.getDirectionalVoxelSubset(
@@ -1793,9 +1792,13 @@ public void getDirectionalVoxelSubset_noApical_returnsCorrectBag() {
17931792
public void getDirectionalVoxelSubset_singleVoxelBasal_returnsIt() {
17941793
ArrayList<Voxel> voxels = new ArrayList<>();
17951794
voxels.add(new Voxel(3, 4, 5));
1796-
Bag result = PottsLocation.getDirectionalVoxelSubset(
1797-
PottsEnums.Side.BASAL, 0.5, voxels,
1798-
new double[]{0, 0, 0}, new Vector(0, 0, 1));
1795+
Bag result =
1796+
PottsLocation.getDirectionalVoxelSubset(
1797+
PottsEnums.Side.BASAL,
1798+
0.5,
1799+
voxels,
1800+
new double[] {0, 0, 0},
1801+
new Vector(0, 0, 1));
17991802
assertEquals(1, result.size());
18001803
assertTrue(result.contains(new Voxel(3, 4, 5)));
18011804
}
@@ -1804,9 +1807,13 @@ public void getDirectionalVoxelSubset_singleVoxelBasal_returnsIt() {
18041807
public void getDirectionalVoxelSubset_singleVoxelApical_returnsIt() {
18051808
ArrayList<Voxel> voxels = new ArrayList<>();
18061809
voxels.add(new Voxel(3, 4, 5));
1807-
Bag result = PottsLocation.getDirectionalVoxelSubset(
1808-
PottsEnums.Side.APICAL, 0.5, voxels,
1809-
new double[]{0, 0, 0}, new Vector(0, 0, 1));
1810+
Bag result =
1811+
PottsLocation.getDirectionalVoxelSubset(
1812+
PottsEnums.Side.APICAL,
1813+
0.5,
1814+
voxels,
1815+
new double[] {0, 0, 0},
1816+
new Vector(0, 0, 1));
18101817
assertEquals(1, result.size());
18111818
assertTrue(result.contains(new Voxel(3, 4, 5)));
18121819
}
@@ -1815,37 +1822,45 @@ public void getDirectionalVoxelSubset_singleVoxelApical_returnsIt() {
18151822
public void getDirectionalVoxelSubset_negativeThreshold_throwsIllegalArgument() {
18161823
ArrayList<Voxel> voxels = new ArrayList<>();
18171824
voxels.add(new Voxel(0, 0, 0));
1818-
assertThrows(IllegalArgumentException.class, () ->
1819-
PottsLocation.getDirectionalVoxelSubset(
1820-
PottsEnums.Side.BASAL,
1821-
-0.5,
1822-
voxels,
1823-
new double[]{0, 0, 0},
1824-
new Vector(0, 0, 1)));
1825+
assertThrows(
1826+
IllegalArgumentException.class,
1827+
() ->
1828+
PottsLocation.getDirectionalVoxelSubset(
1829+
PottsEnums.Side.BASAL,
1830+
-0.5,
1831+
voxels,
1832+
new double[] {0, 0, 0},
1833+
new Vector(0, 0, 1)));
18251834
}
18261835

18271836
@Test
18281837
public void getDirectionalVoxelSubset_thresholdAboveOne_throwsIllegalArgument() {
18291838
ArrayList<Voxel> voxels = new ArrayList<>();
18301839
voxels.add(new Voxel(0, 0, 0));
1831-
assertThrows(IllegalArgumentException.class, () ->
1832-
PottsLocation.getDirectionalVoxelSubset(
1833-
PottsEnums.Side.BASAL,
1834-
1.5,
1835-
voxels,
1836-
new double[]{0, 0, 0},
1837-
new Vector(0, 0, 1)));
1840+
assertThrows(
1841+
IllegalArgumentException.class,
1842+
() ->
1843+
PottsLocation.getDirectionalVoxelSubset(
1844+
PottsEnums.Side.BASAL,
1845+
1.5,
1846+
voxels,
1847+
new double[] {0, 0, 0},
1848+
new Vector(0, 0, 1)));
18381849
}
18391850

18401851
@Test
18411852
public void getDirectionalVoxelSubset_invalidSide_throwsIllegalArgument() {
18421853
ArrayList<Voxel> voxels = new ArrayList<>();
18431854
voxels.add(new Voxel(0, 0, 0));
1844-
assertThrows(IllegalArgumentException.class, () ->
1845-
PottsLocation.getDirectionalVoxelSubset(
1846-
PottsEnums.Side.UNDEFINED,
1847-
0.5, voxels,
1848-
new double[]{0, 0, 0}, new Vector(0, 0, 1)));
1855+
assertThrows(
1856+
IllegalArgumentException.class,
1857+
() ->
1858+
PottsLocation.getDirectionalVoxelSubset(
1859+
PottsEnums.Side.UNDEFINED,
1860+
0.5,
1861+
voxels,
1862+
new double[] {0, 0, 0},
1863+
new Vector(0, 0, 1)));
18491864
}
18501865

18511866
@Test
@@ -1857,10 +1872,12 @@ public void getDirectionalVoxelSubset_halfBasalHalfApical_noOverlap() {
18571872
double[] centroid = {0, 0, 0};
18581873
Vector axis = new Vector(0, 0, 1);
18591874

1860-
Bag basal = PottsLocation.getDirectionalVoxelSubset(
1861-
PottsEnums.Side.BASAL, 0.5, voxels, centroid, axis);
1862-
Bag apical = PottsLocation.getDirectionalVoxelSubset(
1863-
PottsEnums.Side.APICAL, 0.5, voxels, centroid, axis);
1875+
Bag basal =
1876+
PottsLocation.getDirectionalVoxelSubset(
1877+
PottsEnums.Side.BASAL, 0.5, voxels, centroid, axis);
1878+
Bag apical =
1879+
PottsLocation.getDirectionalVoxelSubset(
1880+
PottsEnums.Side.APICAL, 0.5, voxels, centroid, axis);
18641881

18651882
for (Object v : basal) {
18661883
assertFalse(apical.contains(v));
@@ -1876,10 +1893,12 @@ public void getDirectionalVoxelSubset_voxelsInBothBags_hasOverlap() {
18761893
double[] centroid = {0, 0, 0};
18771894
Vector axis = new Vector(0, 0, 1);
18781895

1879-
Bag basal = PottsLocation.getDirectionalVoxelSubset(
1880-
PottsEnums.Side.BASAL, 0.5, voxels, centroid, axis);
1881-
Bag apical = PottsLocation.getDirectionalVoxelSubset(
1882-
PottsEnums.Side.APICAL, 0.5, voxels, centroid, axis);
1896+
Bag basal =
1897+
PottsLocation.getDirectionalVoxelSubset(
1898+
PottsEnums.Side.BASAL, 0.5, voxels, centroid, axis);
1899+
Bag apical =
1900+
PottsLocation.getDirectionalVoxelSubset(
1901+
PottsEnums.Side.APICAL, 0.5, voxels, centroid, axis);
18831902

18841903
boolean voxelOnLineInBasal = false;
18851904
for (Object v : basal) {
@@ -1899,9 +1918,13 @@ public void getDirectionalVoxelSubset_nonZeroCentroid_returnsCorrectBasalHalf()
18991918
for (int i = 10; i < 20; i++) {
19001919
voxels.add(new Voxel(0, 0, i));
19011920
}
1902-
Bag result = PottsLocation.getDirectionalVoxelSubset(
1903-
PottsEnums.Side.BASAL, 0.5, voxels,
1904-
new double[]{0, 0, 14.5}, new Vector(0, 0, 1));
1921+
Bag result =
1922+
PottsLocation.getDirectionalVoxelSubset(
1923+
PottsEnums.Side.BASAL,
1924+
0.5,
1925+
voxels,
1926+
new double[] {0, 0, 14.5},
1927+
new Vector(0, 0, 1));
19051928
assertEquals(5, result.size());
19061929
for (int i = 10; i < 15; i++) {
19071930
assertTrue(result.contains(new Voxel(0, 0, i)));
@@ -1915,9 +1938,13 @@ public void getDirectionalVoxelSubset_diagonalAxis_halfBasal_returnsCorrectBag()
19151938
voxels.add(new Voxel(i, i, 0));
19161939
}
19171940
double inv = 1.0 / Math.sqrt(2);
1918-
Bag result = PottsLocation.getDirectionalVoxelSubset(
1919-
PottsEnums.Side.BASAL, 0.5, voxels,
1920-
new double[]{0, 0, 0}, new Vector(inv, inv, 0));
1941+
Bag result =
1942+
PottsLocation.getDirectionalVoxelSubset(
1943+
PottsEnums.Side.BASAL,
1944+
0.5,
1945+
voxels,
1946+
new double[] {0, 0, 0},
1947+
new Vector(inv, inv, 0));
19211948
assertEquals(3, result.size());
19221949
assertTrue(result.contains(new Voxel(0, 0, 0)));
19231950
assertTrue(result.contains(new Voxel(1, 1, 0)));
@@ -1931,9 +1958,13 @@ public void getDirectionalVoxelSubset_diagonalAxis_halfApical_returnsCorrectBag(
19311958
voxels.add(new Voxel(i, i, 0));
19321959
}
19331960
double inv = 1.0 / Math.sqrt(2);
1934-
Bag result = PottsLocation.getDirectionalVoxelSubset(
1935-
PottsEnums.Side.APICAL, 0.5, voxels,
1936-
new double[]{0, 0, 0}, new Vector(inv, inv, 0));
1961+
Bag result =
1962+
PottsLocation.getDirectionalVoxelSubset(
1963+
PottsEnums.Side.APICAL,
1964+
0.5,
1965+
voxels,
1966+
new double[] {0, 0, 0},
1967+
new Vector(inv, inv, 0));
19371968
assertEquals(3, result.size());
19381969
assertTrue(result.contains(new Voxel(2, 2, 0)));
19391970
assertTrue(result.contains(new Voxel(3, 3, 0)));
@@ -1948,13 +1979,16 @@ public void getDirectionalVoxelSubset_varyingXY_doesNotAffectProjectionOnZAxis()
19481979
voxels.add(new Voxel(2, 7, 2));
19491980
voxels.add(new Voxel(8, 0, 3));
19501981
voxels.add(new Voxel(4, 4, 4));
1951-
Bag result = PottsLocation.getDirectionalVoxelSubset(
1952-
PottsEnums.Side.BASAL, 0.5, voxels,
1953-
new double[]{0, 0, 0}, new Vector(0, 0, 1));
1982+
Bag result =
1983+
PottsLocation.getDirectionalVoxelSubset(
1984+
PottsEnums.Side.BASAL,
1985+
0.5,
1986+
voxels,
1987+
new double[] {0, 0, 0},
1988+
new Vector(0, 0, 1));
19541989
assertEquals(3, result.size());
19551990
assertTrue(result.contains(new Voxel(5, 3, 0)));
19561991
assertTrue(result.contains(new Voxel(1, 9, 1)));
19571992
assertTrue(result.contains(new Voxel(2, 7, 2)));
19581993
}
1959-
19601994
}

0 commit comments

Comments
 (0)