@Override public boolean equals(final Object obj) { return obj instanceof Box && Box.equals(this, (Box) obj); }
@Override public int hashCode() { return Box.hashCode( this ); }
/** * Computes a hash code for a box. The hash code value is based on the * position, lengths and boundary type. * * @param box * The box for which to compute the hash code. * @return Hash code of the box. */ static int hashCode( final Box box ) { int result = 17; for ( int d = 0; d < box.numDimensions(); d++ ) result += 31 * box.realMin( d ) + 31 * box.realMax( d ); if ( box.boundaryType() == BoundaryType.CLOSED ) result += 5; else if ( box.boundaryType() == BoundaryType.OPEN ) result += 8; return result; }
@Override public Roi convert(final Box mask) { return new Roi(mask.realMin(0), mask.realMin(1), mask.sideLength(0), mask .sideLength(1)); }
/** * Determines whether two boxes describe the same region. * <p> * Two boxes are equal iff they have the same dimensionality, boundary type, * lengths and position. * </p> * * @param box1 * The first box to compare. * @param box2 * The second box to compare. * @return True iff the boxes describe the same region. */ static boolean equals( final Box box1, final Box box2 ) { if ( box1 == null && box2 == null ) return true; if ( box1 == null || box2 == null || !Masks.sameTypesAndDimensions( box1, box2 ) ) return false; for ( int d = 0; d < box1.numDimensions(); d++ ) if ( box1.sideLength( d ) != box2.sideLength( d ) ) return false; return Util.locationsEqual( box1.center(), box2.center() ); } }
@Override public boolean equals( final Object obj ) { return obj instanceof Box && Box.equals( this, ( Box ) obj ); }
@Override public int hashCode() { return Box.hashCode(this); }