Search in sources :

Example 81 with Rational

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);
}
Also used : Rational(android.util.Rational) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 82 with Rational

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());
}
Also used : Rational(android.util.Rational) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 83 with Rational

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;
}
Also used : Rational(android.util.Rational) Range(android.util.Range)

Example 84 with Rational

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);
}
Also used : Rational(android.util.Rational) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 85 with Rational

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);
    }
}
Also used : Rational(android.util.Rational)

Aggregations

Rational (android.util.Rational)96 SmallTest (android.test.suitebuilder.annotation.SmallTest)50 Range (android.util.Range)15 Size (android.util.Size)6 Point (android.graphics.Point)5 Pair (android.util.Pair)5 InvalidObjectException (java.io.InvalidObjectException)5 PictureInPictureParams (android.app.PictureInPictureParams)4 TargetApi (android.annotation.TargetApi)3 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 RemoteAction (android.app.RemoteAction)1 Intent (android.content.Intent)1 Rect (android.graphics.Rect)1 RequiresApi (androidx.annotation.RequiresApi)1 RequiresPermission (androidx.annotation.RequiresPermission)1 CameraSelector (androidx.camera.core.CameraSelector)1 StringBuilder (java.lang.StringBuilder)1 DecimalFormat (java.text.DecimalFormat)1