-
-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package android.graphics; | ||
|
||
import java.util.Objects; | ||
|
||
public class Point { | ||
public int x; | ||
public int y; | ||
|
||
public Point(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Point point = (Point) o; | ||
return x == point.x && y == point.y; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(x, y); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Point{" + | ||
"x=" + x + | ||
", y=" + y + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package android.util; | ||
|
||
import java.util.Objects; | ||
|
||
public class Pair<F, S> { | ||
public final F first; | ||
public final S second; | ||
|
||
public Pair(F first, S second) { | ||
this.first = first; | ||
this.second = second; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Pair<?, ?> pair = (Pair<?, ?>) o; | ||
return Objects.equals(first, pair.first) && Objects.equals(second, pair.second); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(first, second); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Pair{" + | ||
"first=" + first + | ||
", second=" + second + | ||
'}'; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
encoder/src/test/java/com/pedro/encoder/SizeCalculatorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.pedro.encoder | ||
|
||
import android.util.Pair | ||
import android.graphics.Point | ||
import com.pedro.encoder.utils.gl.AspectRatioMode | ||
import com.pedro.encoder.utils.gl.SizeCalculator | ||
import junit.framework.TestCase.assertEquals | ||
import org.junit.Test | ||
|
||
|
||
/** | ||
* Possible cases: | ||
* | ||
* stream to preview (Adjust and Fill) | ||
* 1:1 to 1:1 | ||
* 1:1 to 16:9 | ||
* 1:1 to 9:16 | ||
* | ||
* 16:9 to 16:9 | ||
* 16:9 to 1:1 | ||
* 16:9 to 9:16 | ||
* | ||
* 9:16 to 9:16 | ||
* 9:16 to 16:9 | ||
* 9:16 to 1:1 | ||
*/ | ||
class SizeCalculatorTest { | ||
|
||
@Test | ||
fun testAdjust1_1toX() { | ||
val to1_1 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 100, 100, 100, 100) | ||
assertEquals(Pair(Point(0, 0), Point(100, 100)), to1_1) | ||
|
||
val to16_9 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 160, 90, 100, 100) | ||
assertEquals(Pair(Point(35, 0), Point(90, 90)), to16_9) | ||
|
||
val to9_16 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 90, 160, 100, 100) | ||
assertEquals(Pair(Point(0, 35), Point(90, 90)), to9_16) | ||
} | ||
|
||
@Test | ||
fun testAdjust16_9toX() { | ||
val to1_1 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 100, 100, 100, 100) | ||
assertEquals(Pair(Point(0, 0), Point(100, 100)), to1_1) | ||
|
||
val to16_9 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 160, 90, 100, 100) | ||
assertEquals(Pair(Point(35, 0), Point(90, 90)), to16_9) | ||
|
||
val to9_16 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 90, 160, 100, 100) | ||
assertEquals(Pair(Point(0, 35), Point(90, 90)), to9_16) | ||
} | ||
|
||
@Test | ||
fun testAdjust9_16toX() { | ||
|
||
} | ||
|
||
@Test | ||
fun testFill1_1toX() { | ||
|
||
} | ||
|
||
@Test | ||
fun testFill16_9toX() { | ||
|
||
} | ||
|
||
@Test | ||
fun testFill9_16toX() { | ||
|
||
} | ||
} |