张世豪
6 天以前 c498385fb7e372d13e2ee76d7b54ae2381728082
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package zhuye;
 
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.util.List;
 
/**
 * Utility renderer for handheld boundary previews.
 */
public final class adddikuaiyulan {
    private static final Color HANDHELD_BOUNDARY_FILL = new Color(51, 153, 255, 60);
    private static final Color HANDHELD_BOUNDARY_BORDER = new Color(0, 100, 0, 220);
    private static final Color HANDHELD_BOUNDARY_POINT = new Color(0, 100, 0);
    private static final double BASE_WORLD_MARKER_SIZE = 0.27d; // halve the base diameter for subtler markers
    private static final double MIN_PIXEL_DIAMETER = 3.0d;
    private static final double MAX_PIXEL_DIAMETER = 9.0d;
    private static volatile double cachedMarkerPixelDiameter = -1.0d;
 
    private adddikuaiyulan() {
    }
 
    public static void drawPreview(Graphics2D g2d,
                                   List<Point2D.Double> previewPoints,
                                   double scale,
                                   boolean previewActive,
                                   double diameterScale) {
        if (!previewActive) {
            cachedMarkerPixelDiameter = -1.0d;
        }
 
        if (g2d == null || !previewActive || previewPoints == null || previewPoints.isEmpty()) {
            return;
        }
 
        Path2D.Double path = new Path2D.Double();
        boolean started = false;
        for (Point2D.Double point : previewPoints) {
            if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
                continue;
            }
            if (!started) {
                path.moveTo(point.x, point.y);
                started = true;
            } else {
                path.lineTo(point.x, point.y);
            }
        }
 
        if (!started) {
            return;
        }
 
        Stroke originalStroke = g2d.getStroke();
        Color originalColor = g2d.getColor();
 
        if (previewPoints.size() >= 3) {
            path.closePath();
            g2d.setColor(HANDHELD_BOUNDARY_FILL);
            g2d.fill(path);
        }
 
        float outlineWidth = 0.1f;
        g2d.setStroke(new BasicStroke(outlineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g2d.setColor(HANDHELD_BOUNDARY_BORDER);
        g2d.draw(path);
 
        if (cachedMarkerPixelDiameter <= 0.0d) {
            double previousPixelDiameter = Math.abs(BASE_WORLD_MARKER_SIZE * scale);
            if (previousPixelDiameter <= 0.0d) {
                previousPixelDiameter = MIN_PIXEL_DIAMETER;
            }
            cachedMarkerPixelDiameter = Math.max(MIN_PIXEL_DIAMETER,
                Math.min(MAX_PIXEL_DIAMETER, previousPixelDiameter));
        }
 
    double effectiveScale = Math.max(0.01d, scale);
    double markerSize = cachedMarkerPixelDiameter / effectiveScale;
    double normalizedScale = Double.isFinite(diameterScale) && diameterScale > 0.0d ? diameterScale : 1.0d;
    markerSize *= normalizedScale;
    double markerRadius = markerSize / 2.0d;
 
        for (Point2D.Double point : previewPoints) {
            if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
                continue;
            }
            Shape marker = new Ellipse2D.Double(point.x - markerRadius, point.y - markerRadius, markerSize, markerSize);
            g2d.setColor(HANDHELD_BOUNDARY_POINT);
            g2d.fill(marker);
        }
 
        g2d.setStroke(originalStroke);
        g2d.setColor(originalColor);
    }
}