From d505158845f40372b03d42abd0047942c977cd53 Mon Sep 17 00:00:00 2001
From: fctom1215 <fctom1215@outlook.com>
Date: 星期日, 26 七月 2020 18:14:00 +0800
Subject: [PATCH] 绘图优化

---
 app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java |  115 +++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 95 insertions(+), 20 deletions(-)

diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java b/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java
index d8bfc46..d878241 100644
--- a/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java
+++ b/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java
@@ -748,6 +748,9 @@
         }
 
         scale_x = Math.round(Math.abs(50 / Math.sqrt(Math.pow(car[0][0], 2) + Math.pow(car[0][1], 2)) ));
+
+        scale_x = 3;
+
         scale_y = scale_x;
 
         base_x = bmp.getWidth() / 2;
@@ -805,17 +808,42 @@
 
                         List<Integer> line = edgeBean.getLine();
                         Log.d(TAG, "璺竟娌� " + y + " 鍒嗘 " + line.size());
-                        path.moveTo((float) (base_x + (map[line.get(0)][0] - min_x) * scale_x), (float) (base_y + (map[line.get(0)][1] - min_y) * scale_y));
 
-                        Log.d(TAG, String.format("0. X = %f Y = %f", map[line.get(0)][0], map[line.get(0)][1]));
+                        int draw_status = 0;
 
-                        for (int z = 1; z < line.size(); z++) {
-                            path.lineTo((float) (base_x + (map[line.get(z)][0] - min_x) * scale_x), (float) (base_y + (map[line.get(z)][1] - min_y) * scale_y));
-                            Log.d(TAG, String.format("%d. X = %f Y = %f", z, map[line.get(z)][0], map[line.get(z)][1]));
+                        for (int z = 0; z < line.size(); z++) {
+                            float scr_x = (float) (base_x + (map[line.get(z)][0] - min_x) * scale_x);
+                            float scr_y = (float) (base_y + (map[line.get(z)][1] - min_y) * scale_y);
+
+                            if (scr_x >= 0 && scr_x <= bmp.getWidth() && scr_y >= 0 && scr_y <= bmp.getHeight()) {
+                                if (draw_status == 0) {
+                                    path.moveTo(scr_x, scr_y);
+                                    draw_status = 1;
+                                } else if (draw_status == 1) {
+                                    path.lineTo(scr_x, scr_y);
+                                }
+                            } else if (draw_status == 1) {
+                                canvas2.drawPath(path, paint);
+                                draw_status = 0;
+                            }
                         }
-                        Log.d(TAG, "璺竟娌�......");
-                        canvas2.drawPath(path, paint);
-                        Log.d(TAG, "璺竟娌垮畬姣�");
+                        if (draw_status == 1) {
+                            canvas2.drawPath(path, paint);
+                            draw_status = 0;
+                        }
+
+
+//                        path.moveTo((float) (base_x + (map[line.get(0)][0] - min_x) * scale_x), (float) (base_y + (map[line.get(0)][1] - min_y) * scale_y));
+//
+//                        Log.d(TAG, String.format("0. X = %f Y = %f", map[line.get(0)][0], map[line.get(0)][1]));
+//
+//                        for (int z = 1; z < line.size(); z++) {
+//                            path.lineTo((float) (base_x + (map[line.get(z)][0] - min_x) * scale_x), (float) (base_y + (map[line.get(z)][1] - min_y) * scale_y));
+//                            Log.d(TAG, String.format("%d. X = %f Y = %f", z, map[line.get(z)][0], map[line.get(z)][1]));
+//                        }
+//                        Log.d(TAG, "璺竟娌�......");
+//                        canvas2.drawPath(path, paint);
+                        Log.d(TAG, "宸﹁矾杈规部瀹屾瘯");
                     }
                 }
 
@@ -838,17 +866,42 @@
 
                         Path edgePath = new Path();
                         Log.d(TAG, "璺竟娌� " + y + " 鍒嗘 " + line.size());
-                        edgePath.moveTo((float) (base_x + (map[line.get(0)][0] - min_x) * scale_x), (float) (base_y + (map[line.get(0)][1] - min_y) * scale_y));
 
-                        Log.d(TAG, String.format("0. X = %f Y = %f", map[line.get(0)][0], map[line.get(0)][1]));
+                        int draw_status = 0;
 
-                        for (int z = 1; z < line.size(); z++) {
-                            edgePath.lineTo((float) (base_x + (map[line.get(z)][0] - min_x) * scale_x), (float) (base_y + (map[line.get(z)][1] - min_y) * scale_y));
-                            Log.d(TAG, String.format("%d. X = %f Y = %f", z, map[line.get(z)][0], map[line.get(z)][1]));
+                        for (int z = 0; z < line.size(); z++) {
+                            float scr_x = (float) (base_x + (map[line.get(z)][0] - min_x) * scale_x);
+                            float scr_y = (float) (base_y + (map[line.get(z)][1] - min_y) * scale_y);
+
+                            if (scr_x >= 0 && scr_x <= bmp.getWidth() && scr_y >= 0 && scr_y <= bmp.getHeight()) {
+                                if (draw_status == 0) {
+                                    edgePath.moveTo(scr_x, scr_y);
+                                    draw_status = 1;
+                                } else if (draw_status == 1) {
+                                    edgePath.lineTo(scr_x, scr_y);
+                                }
+                            } else if (draw_status == 1) {
+                                canvas2.drawPath(edgePath, paint);
+                                draw_status = 0;
+                            }
                         }
-                        Log.d(TAG, "璺竟娌�......");
-                        canvas2.drawPath(edgePath, paint);
-                        Log.d(TAG, "璺竟娌垮畬姣�");
+                        if (draw_status == 1) {
+                            canvas2.drawPath(edgePath, paint);
+                            draw_status = 0;
+                        }
+
+//                        edgePath.moveTo((float) (base_x + (map[line.get(0)][0] - min_x) * scale_x), (float) (base_y + (map[line.get(0)][1] - min_y) * scale_y));
+//
+//                        Log.d(TAG, String.format("0. X = %f Y = %f", map[line.get(0)][0], map[line.get(0)][1]));
+//
+//                        for (int z = 1; z < line.size(); z++) {
+//                            edgePath.lineTo((float) (base_x + (map[line.get(z)][0] - min_x) * scale_x), (float) (base_y + (map[line.get(z)][1] - min_y) * scale_y));
+//                            Log.d(TAG, String.format("%d. X = %f Y = %f", z, map[line.get(z)][0], map[line.get(z)][1]));
+//                        }
+//                        Log.d(TAG, "璺竟娌�......");
+//                        canvas2.drawPath(edgePath, paint);
+
+                        Log.d(TAG, "鍙宠矾杈规部瀹屾瘯");
                     }
                 }
 
@@ -881,12 +934,34 @@
 
                                 List<Integer> points = seg.getLine();
 
+                                int draw_status = 0;
 
-                                sepPath.moveTo((float) (base_x + (map[points.get(0)][0] - min_x) * scale_x), (float) (base_y + (map[points.get(0)][1] - min_y) * scale_y));
-                                for (int za = 1; za < points.size(); za++) {
-                                    sepPath.lineTo((float) (base_x + (map[points.get(za)][0] - min_x) * scale_x), (float) (base_y + (map[points.get(za)][1] - min_y) * scale_y));
+                                for (int za = 0; za < points.size(); za++) {
+                                    float scr_x = (float) (base_x + (map[points.get(za)][0] - min_x) * scale_x);
+                                    float scr_y = (float) (base_y + (map[points.get(za)][1] - min_y) * scale_y);
+
+                                    if (scr_x >= 0 && scr_x <= bmp.getWidth() && scr_y >= 0 && scr_y <= bmp.getHeight()) {
+                                        if (draw_status == 0) {
+                                            sepPath.moveTo(scr_x, scr_y);
+                                            draw_status = 1;
+                                        } else if (draw_status == 1) {
+                                            sepPath.lineTo(scr_x, scr_y);
+                                        }
+                                    } else if (draw_status == 1) {
+                                        canvas2.drawPath(sepPath, paint);
+                                        draw_status = 0;
+                                    }
                                 }
-                                canvas2.drawPath(sepPath, paint);
+                                if (draw_status == 1) {
+                                    canvas2.drawPath(sepPath, paint);
+                                    draw_status = 0;
+                                }
+
+//                                sepPath.moveTo((float) (base_x + (map[points.get(0)][0] - min_x) * scale_x), (float) (base_y + (map[points.get(0)][1] - min_y) * scale_y));
+//                                for (int za = 1; za < points.size(); za++) {
+//                                    sepPath.lineTo((float) (base_x + (map[points.get(za)][0] - min_x) * scale_x), (float) (base_y + (map[points.get(za)][1] - min_y) * scale_y));
+//                                }
+//                                canvas2.drawPath(sepPath, paint);
                             }
                         }
 

--
Gitblit v1.8.0