diff --git a/ht/src/main/java/com/ccsens/ht/bean/vo/QuestionVo.java b/ht/src/main/java/com/ccsens/ht/bean/vo/QuestionVo.java index 48d08e00..4c73f908 100644 --- a/ht/src/main/java/com/ccsens/ht/bean/vo/QuestionVo.java +++ b/ht/src/main/java/com/ccsens/ht/bean/vo/QuestionVo.java @@ -323,6 +323,14 @@ public class QuestionVo { private int x; @ApiModelProperty("横坐标") private int y; + + public Coordinate() { + } + + public Coordinate(int x, int y) { + this.x = x; + this.y = y; + } } @@ -372,19 +380,23 @@ public class QuestionVo { private Long reflectOnTime; @ApiModelProperty("落笔总时间(所有笔画绘图时间)") private long paintTime; + @ApiModelProperty("原点坐标 x,y") + private String center; @ApiModelProperty("中心 暂定为坐标:X,Y") private String centreCoordinate; + @ApiModelProperty("中心相对原点坐标 X,Y") + private String showCentreCoordinate; @ApiModelProperty("重心 暂定为坐标:X,Y") private String barycenterCoordinate; // 上下左右应部分图片存在倒转展示的问题,前端应反向展示 @ApiModelProperty("上边距距离画板中心的距离") - private int topLength; + private Coordinate top; @ApiModelProperty("下边距距离画板中心的距离") - private int bottomLength; + private Coordinate bottom ; @ApiModelProperty("上边距距离画板中心的距离") - private int leftLength; + private Coordinate left; @ApiModelProperty("下边距距离画板中心的距离") - private int rightLength; + private Coordinate right; @ApiModelProperty("最小外接长方形面积 单位为px") private double minRectangleAcreage; @ApiModelProperty("最小外接圆面积 单位为px 保留两位小数") diff --git a/ht/src/main/java/com/ccsens/ht/service/QuestionService.java b/ht/src/main/java/com/ccsens/ht/service/QuestionService.java index c64341ec..5c0df4b4 100644 --- a/ht/src/main/java/com/ccsens/ht/service/QuestionService.java +++ b/ht/src/main/java/com/ccsens/ht/service/QuestionService.java @@ -630,15 +630,17 @@ public class QuestionService implements IQuestionService { public int line; /** 第几个点 */ public int point; + public int x; + public int y; public PointPosition(){} - public PointPosition(int value, int line, int point) { + public PointPosition(int value, int line, int point, int x, int y) { this.value = value; this.line = line; this.point = point; } - public void change(int value, int line, int point) { + public void change(int value, int line, int point, int x, int y) { this.value = value; this.line = line; this.point = point; @@ -724,11 +726,11 @@ public class QuestionService implements IQuestionService { int x = Integer.parseInt(split1[0]); int y = Integer.parseInt(split1[1]); if (!hadValue) { - minX = new PointPosition(x, i, j); - maxX = new PointPosition(x, i, j); - minY = new PointPosition(y, i, j); + minX = new PointPosition(x, i, j, x, y); + maxX = new PointPosition(x, i, j, x, y); + minY = new PointPosition(y, i, j, x, y); - maxY = new PointPosition(y, i, j); + maxY = new PointPosition(y, i, j, x, y); hadValue = true; continue; @@ -736,15 +738,15 @@ public class QuestionService implements IQuestionService { // 最大最小横坐标 if (minX.value > x) { - minX.change(x,i,j); + minX.change(x,i,j, x, y); } else if (maxX.value < x) { - maxX.change(x,i,j); + maxX.change(x,i,j, x, y); } // 最大最小纵坐标 if (minY.value > y) { - minY.change(y,i,j); + minY.change(y,i,j, x, y); } else if (maxY.value < y) { - maxY.change(y,i,j); + maxY.change(y,i,j, x, y); } } @@ -818,32 +820,39 @@ public class QuestionService implements IQuestionService { parameter.setReflectOnTime(reflectOnTime); // 落笔总时长 parameter.setPaintTime(paintTime); - //计算中心 + + // 计算原点(画板中心) 画板是否为canvas的一半 + int canvasHeight = htPatientCanvas.getCanvasHeight(); + int canvasWidth = htPatientCanvas.getCanvasWidth(); + boolean half = question.getOperateType() == Constant.Ht.Operation.PAINT_HALF || + question.getOperateType() == Constant.Ht.Operation.PAINT_HALF_IMG; + int centerX = half ? (canvasWidth / 2 + 30) / 2 : canvasWidth / 2; + int centerY = canvasHeight / 2; + + //计算图形中心 int x = (maxX.value + minX.value) / 2; int y = (maxY.value + minY.value) / 2; String centreCoordinate = x + "," + y; parameter.setCentreCoordinate(centreCoordinate); + parameter.setShowCentreCoordinate((x-centerX) + "," + (y-centerY)); // TODO 重心 parameter.setBarycenterCoordinate(centreCoordinate); //最小长方形面积 double acreage = (maxX.value - minX.value) * (maxY.value - minY.value); parameter.setMinRectangleAcreage(acreage); + + // 计算四个边界点构成的长方形距离画板重心的距离 + + + // 四个边界点 + 最小圆面积 四舍五入 sqrt int radiusSqrt = setFourPoint(canvasPoints, minX, maxX, minY, maxY, x, y); parameter.setMinCircleAcreage(new BigDecimal(Math.PI * radiusSqrt).setScale(2, BigDecimal.ROUND_HALF_UP)); - // 计算四个边界点构成的长方形距离画板重心的距离 - int canvasHeight = htPatientCanvas.getCanvasHeight(); - int canvasWidth = htPatientCanvas.getCanvasWidth(); - // 画板是否为canvas的一半 - boolean half = question.getOperateType() == Constant.Ht.Operation.PAINT_HALF || - question.getOperateType() == Constant.Ht.Operation.PAINT_HALF_IMG; - int centerX = half ? (canvasWidth / 2 + 30) / 2 : canvasWidth / 2; - int centerY = canvasHeight / 2; - parameter.setTopLength(Math.abs(minY.value - centerY)); - parameter.setBottomLength(Math.abs(maxY.value - centerY)); - parameter.setLeftLength(Math.abs(minX.value - centerX)); - parameter.setRightLength(Math.abs(maxX.value - centerX)); + parameter.setTop(new QuestionVo.Coordinate(minY.x - centerX, minY.y - centerY)); + parameter.setBottom(new QuestionVo.Coordinate(maxY.x - centerX, maxY.y - centerY)); + parameter.setLeft(new QuestionVo.Coordinate(minX.x - centerX, minX.y - centerY)); + parameter.setRight(new QuestionVo.Coordinate(maxX.x - centerX, maxX.y - centerY)); //平均长度 BigDecimal aveLength = BigDecimal.valueOf(totalLength / canvasPoints.size()).setScale(2, RoundingMode.HALF_UP); @@ -867,7 +876,7 @@ public class QuestionService implements IQuestionService { } /** - * 设置 四个特殊点 + * 设置 四个特殊点,计算中心点、四个特殊点相对原点(画板中心)的距离 计算点到中心点距离的平方的最大值 * @param canvasPoints 记录 * @param minX 最左点 * @param maxX 最右点