Skip to content

Commit

Permalink
Merge pull request #31 from aoliaoaoaojiao/master
Browse files Browse the repository at this point in the history
feat:Add coordinate conversion between adb vertical coordinate system and poco coordinate system
  • Loading branch information
ZhouYixun authored Oct 14, 2022
2 parents c15689b + 5667612 commit 9676dad
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
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};
}
}
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();
}
}

0 comments on commit 9676dad

Please sign in to comment.