-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from aoliaoaoaojiao/master
feat:Add coordinate conversion between adb vertical coordinate system and poco coordinate system
- Loading branch information
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/main/java/org/cloud/sonic/driver/common/tool/PocoXYTransformer.java
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,78 @@ | ||
/* | ||
* Copyright (C) [SonicCloudOrg] Sonic 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 org.cloud.sonic.driver.common.tool; | ||
|
||
/*** | ||
* poco coordinate system conversion and vertical coordinate system converter | ||
*/ | ||
public class PocoXYTransformer { | ||
/** | ||
* Convert adb vertical coordinates to poco coordinate system coordinates according to different directions | ||
* | ||
* @param x x poco coordinate point x | ||
* @param y y poco coordinate point y | ||
* @param w w ScreenWidth | ||
* @param h h ScreenHeight | ||
* @param orientation The device orientation, based on the vertical direction of the mobile device, | ||
* rotate 90° counterclockwise, orientation=90, 180° counterclockwise, orientation=180, | ||
* and so on | ||
* @return {@link int[]} | ||
*/ | ||
public static double[] PocoTransformerVertical(double x, double y, double w, double h, Integer orientation) { | ||
if (orientation == 90) { | ||
double temp = x; | ||
x = w - y; | ||
y = temp; | ||
} else if (orientation == 180) { | ||
x = w - x; | ||
y = h - y; | ||
} else if (orientation == 270) { | ||
double temp = x; | ||
x = y; | ||
y = h - temp; | ||
} | ||
return new double[]{x, y}; | ||
} | ||
|
||
/** | ||
* Convert the coordinate system of poco to the coordinates in the adb vertical coordinate system | ||
* | ||
* @param x x vertical coordinate x | ||
* @param y y vertical coordinate y | ||
* @param w w ScreenWidth | ||
* @param h h ScreenHeight | ||
* @param orientation The device orientation, based on the vertical direction of the mobile device, | ||
* rotate 90° counterclockwise, orientation=90, 180° counterclockwise, orientation=180, | ||
* and so on | ||
* @return {@link int[]} | ||
*/ | ||
public static double[] VerticalTransformerPoco(double x, double y, double w, double h, Integer orientation) { | ||
if (orientation == 90) { | ||
double temp = x; | ||
x = y; | ||
y = w - temp; | ||
} else if (orientation == 180) { | ||
x = w - x; | ||
y = h - y; | ||
} else if (orientation == 270) { | ||
double temp = x; | ||
x = h - y; | ||
y = temp; | ||
} | ||
return new double[]{x, y}; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/java/org/cloud/sonic/driver/common/tool/PocoXYTransformerTest.java
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,42 @@ | ||
package org.cloud.sonic.driver.common.tool; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import javax.swing.plaf.synth.SynthOptionPaneUI; | ||
|
||
public class PocoXYTransformerTest { | ||
double width = 100, height = 1000; | ||
|
||
@Test | ||
public void testOriToUP() { | ||
double pocoX = 100, pocoY = 50; | ||
double[]result = PocoXYTransformer.PocoTransformerVertical(pocoX,pocoY,width,height,270); | ||
Assert.assertEquals(result[0],pocoY,0); | ||
Assert.assertEquals(result[1],height-pocoX,0); | ||
System.out.printf("x:%s,y:%s",result[0],result[1]); | ||
System.out.println(); | ||
|
||
result = PocoXYTransformer.PocoTransformerVertical(pocoX,pocoY,width,height,90); | ||
Assert.assertEquals(result[0],pocoY,0); | ||
Assert.assertEquals(result[1],pocoX,0); | ||
System.out.printf("x:%s,y:%s",result[0],result[1]); | ||
System.out.println(); | ||
} | ||
|
||
@Test | ||
public void testUPToOri() { | ||
double upx = 50,upy = 100; | ||
double[]result = PocoXYTransformer.VerticalTransformerPoco(upx,upy,width,height,270); | ||
Assert.assertEquals(result[0],height-upy,0); | ||
Assert.assertEquals(result[1],upx,0); | ||
System.out.printf("x:%s,y:%s",result[0],result[1]); | ||
System.out.println(); | ||
|
||
result = PocoXYTransformer.VerticalTransformerPoco(upx,upy,width,height,90); | ||
Assert.assertEquals(result[0],upy,0); | ||
Assert.assertEquals(result[1],upx,0); | ||
System.out.printf("x:%s,y:%s",result[0],result[1]); | ||
System.out.println(); | ||
} | ||
} |