use of android.util.Rational in project android_frameworks_base by DirtyUnicorns.
the class RationalTest method testCompareTo.
@SmallTest
public void testCompareTo() {
// unit is equal to itself
assertCompareEquals(UNIT, new Rational(1, 1));
// NaN is greater than anything but NaN
assertCompareEquals(NaN, new Rational(0, 0));
assertGreaterThan(NaN, UNIT);
assertGreaterThan(NaN, POSITIVE_INFINITY);
assertGreaterThan(NaN, NEGATIVE_INFINITY);
assertGreaterThan(NaN, ZERO);
// Positive infinity is greater than any other non-NaN
assertCompareEquals(POSITIVE_INFINITY, new Rational(1, 0));
assertGreaterThan(POSITIVE_INFINITY, UNIT);
assertGreaterThan(POSITIVE_INFINITY, NEGATIVE_INFINITY);
assertGreaterThan(POSITIVE_INFINITY, ZERO);
// Negative infinity is smaller than any other non-NaN
assertCompareEquals(NEGATIVE_INFINITY, new Rational(-1, 0));
assertLessThan(NEGATIVE_INFINITY, UNIT);
assertLessThan(NEGATIVE_INFINITY, POSITIVE_INFINITY);
assertLessThan(NEGATIVE_INFINITY, ZERO);
// A finite number with the same denominator is trivially comparable
assertGreaterThan(new Rational(3, 100), new Rational(1, 100));
assertGreaterThan(new Rational(3, 100), ZERO);
// Compare finite numbers with different divisors
assertGreaterThan(new Rational(5, 25), new Rational(1, 10));
assertGreaterThan(new Rational(5, 25), ZERO);
// Compare finite numbers with different signs
assertGreaterThan(new Rational(5, 25), new Rational(-1, 10));
assertLessThan(new Rational(-5, 25), ZERO);
}
use of android.util.Rational in project android_frameworks_base by DirtyUnicorns.
the class RationalTest method testConstructor.
@SmallTest
public void testConstructor() {
// Simple case
Rational r = new Rational(1, 2);
assertEquals(1, r.getNumerator());
assertEquals(2, r.getDenominator());
// Denominator negative
r = new Rational(-1, 2);
assertEquals(-1, r.getNumerator());
assertEquals(2, r.getDenominator());
// Numerator negative
r = new Rational(1, -2);
assertEquals(-1, r.getNumerator());
assertEquals(2, r.getDenominator());
// Both negative
r = new Rational(-1, -2);
assertEquals(1, r.getNumerator());
assertEquals(2, r.getDenominator());
// Infinity.
r = new Rational(1, 0);
assertEquals(1, r.getNumerator());
assertEquals(0, r.getDenominator());
// Negative infinity.
r = new Rational(-1, 0);
assertEquals(-1, r.getNumerator());
assertEquals(0, r.getDenominator());
// NaN.
r = new Rational(0, 0);
assertEquals(0, r.getNumerator());
assertEquals(0, r.getDenominator());
}
use of android.util.Rational in project android_frameworks_base by crdroidandroid.
the class StaticMetadata method getAeCompensationRangeChecked.
/**
* Get value of key android.control.aeCompensationRange and do the sanity check.
*
* @return default value if the value is null or malformed.
*/
public Range<Integer> getAeCompensationRangeChecked() {
Key<Range<Integer>> key = CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE;
Range<Integer> compensationRange = getValueFromKeyNonNull(key);
Rational compensationStep = getAeCompensationStepChecked();
float compensationStepF = compensationStep.floatValue();
final Range<Integer> DEFAULT_RANGE = Range.create((int) (CONTROL_AE_COMPENSATION_RANGE_DEFAULT_MIN / compensationStepF), (int) (CONTROL_AE_COMPENSATION_RANGE_DEFAULT_MAX / compensationStepF));
final Range<Integer> ZERO_RANGE = Range.create(0, 0);
if (compensationRange == null) {
return ZERO_RANGE;
}
// Legacy devices don't have a minimum range requirement
if (isHardwareLevelLimitedOrBetter() && !compensationRange.equals(ZERO_RANGE)) {
checkTrueForKey(key, " range value must be at least " + DEFAULT_RANGE + ", actual " + compensationRange + ", compensation step " + compensationStep, compensationRange.getLower() <= DEFAULT_RANGE.getLower() && compensationRange.getUpper() >= DEFAULT_RANGE.getUpper());
}
return compensationRange;
}
use of android.util.Rational in project android_frameworks_base by crdroidandroid.
the class CameraMetadataTest method testReadWritePrimitive.
@SmallTest
public void testReadWritePrimitive() {
// int32 (single)
checkKeyGetAndSet("android.control.aeExposureCompensation", Integer.TYPE, 0xC0FFEE);
// byte (single)
checkKeyGetAndSet("android.flash.maxEnergy", Byte.TYPE, (byte) 6);
// int64 (single)
checkKeyGetAndSet("android.flash.firingTime", Long.TYPE, 0xABCD12345678FFFFL);
// float (single)
checkKeyGetAndSet("android.lens.aperture", Float.TYPE, Float.MAX_VALUE);
// double (single) -- technically double x 3, but we fake it
checkKeyGetAndSet("android.jpeg.gpsCoordinates", Double.TYPE, Double.MAX_VALUE);
// rational (single)
checkKeyGetAndSet("android.sensor.baseGainFactor", Rational.class, new Rational(1, 2));
/**
* Weirder cases, that don't map 1:1 with the native types
*/
// bool (single) -- with TYPE_BYTE
checkKeyGetAndSet("android.control.aeLock", Boolean.TYPE, true);
// integer (single) -- with TYPE_BYTE
checkKeyGetAndSet("android.control.aePrecaptureTrigger", Integer.TYPE, 6);
}
use of android.util.Rational in project android_frameworks_base by crdroidandroid.
the class ColorSpaceTransform method copyElements.
/**
* Copy the {@link Rational} elements in row-major order from this matrix into the destination.
*
* @param destination
* an array big enough to hold at least {@code 9} elements after the
* {@code offset}
* @param offset
* a non-negative offset into the array
* @throws NullPointerException
* If {@code destination} was {@code null}
* @throws ArrayIndexOutOfBoundsException
* If there's not enough room to write the elements at the specified destination and
* offset.
*/
public void copyElements(Rational[] destination, int offset) {
checkArgumentNonnegative(offset, "offset must not be negative");
checkNotNull(destination, "destination must not be null");
if (destination.length - offset < COUNT) {
throw new ArrayIndexOutOfBoundsException("destination too small to fit elements");
}
for (int i = 0, j = 0; i < COUNT; ++i, j += RATIONAL_SIZE) {
int numerator = mElements[j + OFFSET_NUMERATOR];
int denominator = mElements[j + OFFSET_DENOMINATOR];
destination[i + offset] = new Rational(numerator, denominator);
}
}
Aggregations