|
@@ -1,5 +1,10 @@
|
|
|
package com.fdkankan.indoor.base.convert;
|
|
|
|
|
|
+import com.fdkankan.indoor.base.exception.BaseRuntimeException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
public class AffineTransform {
|
|
|
public static double getAngle(Point p1, Point p2) {
|
|
|
double angle = Math.atan2(p2.getX() - p1.getX(), p2.getY() - p1.getY());
|
|
@@ -9,6 +14,18 @@ public class AffineTransform {
|
|
|
public static double getScale(Point p1, Point b1, Point p2, Point b2) {
|
|
|
// 被除数不能等于0
|
|
|
double a = getLength(b1, b2) / getLength(p1, p2) ;
|
|
|
+ // 2021-12-10 double计算NaN,Infinity 不抛出异常, 需要手动catch
|
|
|
+ if (Double.isInfinite(a)){
|
|
|
+ String msg = "计算数据异常, 数据Infinity(无穷大)";
|
|
|
+ log.error(msg+ ": {}", a );
|
|
|
+ throw new BaseRuntimeException(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Double.isNaN(a)){
|
|
|
+ String msg = "计算数据异常, 数据空NaN";
|
|
|
+ log.error(msg+ ": {}", a );
|
|
|
+ throw new BaseRuntimeException(msg);
|
|
|
+ }
|
|
|
return a;
|
|
|
}
|
|
|
|
|
@@ -38,4 +55,16 @@ public class AffineTransform {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void tedst(){
|
|
|
+ Point p1 = new Point(0,0);
|
|
|
+ Point p2 = new Point(0,0);
|
|
|
+ Point b1 = new Point(0,0);
|
|
|
+ Point b2 = new Point(0,0);
|
|
|
+ double scale = getScale(p1, b1, p2, b2);
|
|
|
+ System.out.println(scale);
|
|
|
+ System.out.println(Double.isInfinite(scale));
|
|
|
+ System.out.println("Infinity".equals(scale));
|
|
|
+ }
|
|
|
+
|
|
|
}
|