diff --git a/change.txt b/change.txt index 30b2b1d147..7d352fe32c 100644 --- a/change.txt +++ b/change.txt @@ -12,6 +12,8 @@ Version : 1.1.8 - PackedArray * Added isEquals() + * Fixed bug where set(index, point) overwrite the value of `point` + * Added implementation specific variants of set( index , ... ) --------------------- Date : 2024/Oct/05 diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_F64.java index a115853cc1..231844ac44 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -39,6 +39,12 @@ public final void append( double x, double y ) { array.add(y); } + public void set( int index, double x, double y ) { + index *= 2; + array.data[index++] = x; + array.data[index] = y; + } + @Override public void append( Point2D_F64 element ) { append(element.x, element.y); } diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I16.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I16.java index c6e4bee2d2..1b75d875a0 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I16.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I16.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -56,6 +56,12 @@ public final void append( int x, int y ) { array.add(y); } + public void set( int index, int x, int y ) { + index *= 2; + array.data[index++] = (short)x; + array.data[index] = (short)y; + } + @Override public void append( Point2D_I16 element ) { append(element.x, element.y); } diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I32.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I32.java index f4f6deb0e3..f9798f52aa 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I32.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I32.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -56,6 +56,12 @@ public final void append( int x, int y ) { array.add(y); } + public void set( int index, int x, int y ) { + index *= 2; + array.data[index++] = x; + array.data[index] = y; + } + @Override public void append( Point2D_I32 element ) { append(element.x, element.y); } diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint3D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint3D_F64.java index bde56c68a2..373ac42c12 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint3D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint3D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -46,6 +46,13 @@ public void append( double x, double y, double z) { array.add(z); } + public void set( int index, double x, double y, double z ) { + index *= 3; + array.data[index++] = x; + array.data[index++] = y; + array.data[index] = z; + } + @Override public void set( int index, Point3D_F64 element ) { index *= 3; array.data[index++] = element.x; diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint4D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint4D_F64.java index 3bc721e1ad..24f39bbb38 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint4D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint4D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -56,6 +56,14 @@ public void append( double x, double y, double z, double w ) { array.add(w); } + public void set( int index, double x, double y, double z, double w ) { + index *= 4; + array.data[index++] = x; + array.data[index++] = y; + array.data[index++] = z; + array.data[index] = w; + } + @Override public void set( int index, Point4D_F64 element ) { index *= 4; array.data[index++] = element.x; diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint2D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint2D_F64.java index 2dc7008fb8..8c85f3b436 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint2D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint2D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -72,6 +72,14 @@ public void append( double x, double y ) { array.add(y); } + public void set( int index, double x, double y ) { + index *= DOF; + double[] block = array.getBlocks().get(index/array.getBlockSize()); + int where = index%array.getBlockSize(); + block[where] = x; + block[where + 1] = y; + } + @Override public void append( Point2D_F64 element ) { array.add(element.x); array.add(element.y); @@ -81,8 +89,8 @@ public void append( double x, double y ) { index *= DOF; double[] block = array.getBlocks().get(index/array.getBlockSize()); int where = index%array.getBlockSize(); - element.x = block[where]; - element.y = block[where + 1]; + block[where] = element.x; + block[where + 1] = element.y; } @Override public Point2D_F64 getTemp( int index ) { diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint3D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint3D_F64.java index 3c1163a798..8dd27882a4 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint3D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint3D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -82,13 +82,22 @@ public void append( GeoTuple3D_F64 element ) { append(element.x, element.y, element.z); } + public void set( int index, double x, double y, double z ) { + index *= DOF; + double[] block = array.getBlocks().get(index/array.getBlockSize()); + int where = index%array.getBlockSize(); + block[where] = x; + block[where + 1] = y; + block[where + 2] = z; + } + @Override public void set( int index, Point3D_F64 element ) { index *= DOF; double[] block = array.getBlocks().get(index/array.getBlockSize()); int where = index%array.getBlockSize(); - element.x = block[where]; - element.y = block[where + 1]; - element.z = block[where + 2]; + block[where] = element.x; + block[where + 1] = element.y; + block[where + 2] = element.z; } /** diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint4D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint4D_F64.java index 62dfab8146..d1337a10cd 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint4D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint4D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -77,6 +77,16 @@ public void append( double x, double y, double z, double w ) { array.add(w); } + public void set( int index, double x, double y, double z, double w ) { + index *= DOF; + double[] block = array.getBlocks().get(index/array.getBlockSize()); + int where = index%array.getBlockSize(); + block[where] = x; + block[where + 1] = y; + block[where + 2] = z; + block[where + 3] = w; + } + @Override public void append( Point4D_F64 element ) { array.add(element.x); array.add(element.y); @@ -88,10 +98,10 @@ public void append( double x, double y, double z, double w ) { index *= DOF; double[] block = array.getBlocks().get(index/array.getBlockSize()); int where = index%array.getBlockSize(); - element.x = block[where]; - element.y = block[where + 1]; - element.z = block[where + 2]; - element.w = block[where + 3]; + block[where] = element.x; + block[where + 1] = element.y; + block[where + 2] = element.z; + block[where + 3] = element.w; } @Override public Point4D_F64 getTemp( int index ) { diff --git a/main/boofcv-types/src/test/java/boofcv/struct/packed/GenericPackedArrayChecks.java b/main/boofcv-types/src/test/java/boofcv/struct/packed/GenericPackedArrayChecks.java index 70e46cf860..ede6329265 100644 --- a/main/boofcv-types/src/test/java/boofcv/struct/packed/GenericPackedArrayChecks.java +++ b/main/boofcv-types/src/test/java/boofcv/struct/packed/GenericPackedArrayChecks.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -156,7 +156,15 @@ public abstract class GenericPackedArrayChecks extends BoofStandardJUnit { alg.append(createRandomPoint()); var p = createRandomPoint(); + var copy = createRandomPoint(); + alg.copy(p, copy); + alg.set(1, p); + + // make sure set isn't writing to 'p'. yes this was a bug + checkEquals(p, copy); + + // Retrieve the value and see if it's the same T found = alg.getTemp(1); checkEquals(p, found); } diff --git a/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedArrayPoint2D_F64.java b/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedArrayPoint2D_F64.java index ce38bb53de..5f3e714f33 100644 --- a/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedArrayPoint2D_F64.java +++ b/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedArrayPoint2D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -23,8 +23,7 @@ import org.ejml.UtilEjml; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.*; public class TestPackedArrayPoint2D_F64 extends GenericPackedArrayChecks { @@ -34,8 +33,8 @@ public class TestPackedArrayPoint2D_F64 extends GenericPackedArrayChecks { @@ -48,6 +47,14 @@ public class TestPackedArrayPoint3D_F64 extends GenericPackedArrayChecks { @@ -49,6 +48,14 @@ public class TestPackedArrayPoint4D_F64 extends GenericPackedArrayChecks { @@ -48,6 +47,14 @@ public class TestPackedBigArrayPoint2D_F64 extends GenericPackedArrayChecks { @@ -51,6 +50,14 @@ public class TestPackedBigArrayPoint3D_F64 extends GenericPackedArrayChecks(); points.add(new Point3D_F64(1, 2, 3)); diff --git a/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedBigArrayPoint4D_F64.java b/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedBigArrayPoint4D_F64.java index a38e49c986..9674c0ed41 100644 --- a/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedBigArrayPoint4D_F64.java +++ b/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedBigArrayPoint4D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2025, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -24,8 +24,7 @@ import org.ejml.UtilEjml; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.*; public class TestPackedBigArrayPoint4D_F64 extends GenericPackedArrayChecks { @@ -50,6 +49,14 @@ public class TestPackedBigArrayPoint4D_F64 extends GenericPackedArrayChecks