Skip to content

Commit

Permalink
TupleDesc - Added isEquals()
Browse files Browse the repository at this point in the history
  • Loading branch information
lessthanoptimal committed Apr 20, 2024
1 parent a9a24b0 commit 12455ce
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
7 changes: 7 additions & 0 deletions change.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Version Meaning: <compatible>.<feature>.<bug fix>
- Second digit indicates if a new feature was added and/or if only a minor refactoring has been done
- Last digit always indicates a bug fix and other minor changes

---------------------
Date : 2024
Version : 1.1.4

- TupleDesc
* Added isEquals()

---------------------------------------------
Date : 2024/Feb/24
Version : 1.1.3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Peter Abeles. All Rights Reserved.
* Copyright (c) 2024, Peter Abeles. All Rights Reserved.
*
* This file is part of BoofCV (http://boofcv.org).
*
Expand Down Expand Up @@ -43,6 +43,9 @@ public interface TupleDesc<T extends TupleDesc> extends Serializable {
*/
double getDouble( int index );

/** Returns true if the type data structure are identical */
boolean isEquals( T tuple );

/**
* Number of elements in the tuple.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Peter Abeles. All Rights Reserved.
* Copyright (c) 2024, Peter Abeles. All Rights Reserved.
*
* This file is part of BoofCV (http://boofcv.org).
*
Expand Down Expand Up @@ -58,25 +58,33 @@ public void setBit( int bit, boolean value ) {
data[index] &= ~(1 << (bit%32));
}

@Override
public void setTo( TupleDesc_B source ) {
@Override public void setTo( TupleDesc_B source ) {
if (data.length < source.data.length)
throw new IllegalArgumentException("Data array is too small to store the source array.");

this.numBits = source.numBits;
System.arraycopy(source.data, 0, data, 0, source.data.length);
}

@Override
public double getDouble( int index ) {
@Override public double getDouble( int index ) {
if (isBitTrue(index))
return 1;
else
return -1;
}

@Override
public int size() {
@Override public boolean isEquals( TupleDesc_B tuple ) {
if (size() != tuple.size())
return false;

for (int i = 0; i < size(); i++) {
if (data[i] != tuple.data[i])
return false;
}
return true;
}

@Override public int size() {
return numBits;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Peter Abeles. All Rights Reserved.
* Copyright (c) 2024, Peter Abeles. All Rights Reserved.
*
* This file is part of BoofCV (http://boofcv.org).
*
Expand Down Expand Up @@ -61,6 +61,17 @@ public void fill( double value ) {
return data[index];
}

@Override public boolean isEquals( TupleDesc_F64 tuple ) {
if (size() != tuple.size())
return false;

for (int i = 0; i < size(); i++) {
if (data[i] != tuple.data[i])
return false;
}
return true;
}

@Override public int size() {
return data.length;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Peter Abeles. All Rights Reserved.
* Copyright (c) 2024, Peter Abeles. All Rights Reserved.
*
* This file is part of BoofCV (http://boofcv.org).
*
Expand Down Expand Up @@ -43,6 +43,17 @@ public void fill( byte value ) {
Arrays.fill(this.data, value);
}

@Override public boolean isEquals( TD tuple ) {
if (size() != tuple.size())
return false;

for (int i = 0; i < size(); i++) {
if (data[i] != tuple.data[i])
return false;
}
return true;
}

@Override
public void setTo( TD source ) {
System.arraycopy(source.data, 0, data, 0, data.length);
Expand Down

0 comments on commit 12455ce

Please sign in to comment.