TopologyScale values for scaling the topology pane
TopologyScale helps to size the topology pane and properly size and place the display blocks inside it. It is based on the algorithm described in the design doc. Test: TopologyScaleTest Flag: com.android.settings.flags.display_topology_pane_in_display_list Bug: b/352648432 Change-Id: I8932e80c2b490fab0097fa315e536b292376d4a8
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.connecteddevice.display
|
||||
|
||||
import android.graphics.Point
|
||||
import android.graphics.PointF
|
||||
import android.graphics.RectF
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
fun assertPointF(x: Float, y: Float, delta: Float, actual: PointF) {
|
||||
assertEquals(x, actual.x, delta)
|
||||
assertEquals(y, actual.y, delta)
|
||||
}
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class TopologyScaleTest {
|
||||
@Test
|
||||
fun oneDisplay4to3Aspect() {
|
||||
val scale = TopologyScale(
|
||||
/* paneWidth= */ 640,
|
||||
listOf(RectF(0f, 0f, 640f, 480f)))
|
||||
|
||||
// blockRatio is higher than 0.05 in order to make the smallest display edge (480 dp) 48dp
|
||||
// in the pane.
|
||||
assertEquals(
|
||||
"{TopoScale blockRatio=0.100000 originPaneXY=288,216 paneHeight=480}", "" + scale)
|
||||
|
||||
assertEquals(Point(352, 264), scale.displayToPaneCoor(PointF(640f, 480f)))
|
||||
assertEquals(Point(320, 240), scale.displayToPaneCoor(PointF(320f, 240f)))
|
||||
assertEquals(PointF(640f, 480f), scale.paneToDisplayCoor(Point(352, 264)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun twoUnalignedDisplays() {
|
||||
val scale = TopologyScale(
|
||||
/* paneWidth= */ 300,
|
||||
listOf(RectF(0f, 0f, 1920f, 1200f), RectF(1920f, -300f, 3840f, 900f)))
|
||||
|
||||
assertEquals(
|
||||
"{TopoScale blockRatio=0.046875 originPaneXY=60,37 paneHeight=117}", "" + scale)
|
||||
|
||||
assertEquals(Point(78, 55), scale.displayToPaneCoor(PointF(400f, 400f)))
|
||||
assertEquals(Point(42, 37), scale.displayToPaneCoor(PointF(-400f, 0f)))
|
||||
assertPointF(-384f, 106.6666f, 0.001f, scale.paneToDisplayCoor(Point(42, 42)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun twoDisplaysBlockRatioBumpedForGarSizeMinimumHorizontal() {
|
||||
val scale = TopologyScale(
|
||||
/* paneWidth= */ 192,
|
||||
listOf(RectF(0f, 0f, 240f, 320f), RectF(-240f, -320f, 0f, 0f)))
|
||||
|
||||
// blockRatio is higher than 0.05 in order to make the smallest display edge (240 dp) 48dp
|
||||
// in the pane.
|
||||
assertEquals(
|
||||
"{TopoScale blockRatio=0.200000 originPaneXY=96,128 paneHeight=256}", "" + scale)
|
||||
|
||||
assertEquals(Point(192, 256), scale.displayToPaneCoor(PointF(480f, 640f)))
|
||||
assertEquals(Point(96, 64), scale.displayToPaneCoor(PointF(0f, -320f)))
|
||||
assertPointF(220f, -430f, 0.001f, scale.paneToDisplayCoor(Point(140, 42)))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user