张世豪
10 小时以前 13d032241e1a2938a8be4f64c9171e1240e9ea1e
src/zhuye/bianjiedrwa.java
@@ -23,24 +23,59 @@
            return; // 无数据返回
        } // if结束
        Path2D path = new Path2D.Double(); // 创建路径
        float strokeWidth = (float) (6 / Math.max(0.5, scale)); // 计算边线宽度(增加一倍,从3改为6)
        // 填充区域
        Path2D fillPath = new Path2D.Double(); // 创建填充路径
        boolean first = true; // 首点标记
        for (Point2D.Double point : boundary) { // 遍历点
            if (first) { // 首个点
                path.moveTo(point.x, point.y); // 移动到开始点
                fillPath.moveTo(point.x, point.y); // 移动到开始点
                first = false; // 更新标记
            } else { // 其他点
                path.lineTo(point.x, point.y); // 连线到下个点
                fillPath.lineTo(point.x, point.y); // 连线到下个点
            } // if结束
        } // for结束
        path.closePath(); // 闭合路径
        float strokeWidth = (float) (3 / Math.max(0.5, scale)); // 计算边线宽度
        g2d.setStroke(new BasicStroke(strokeWidth)); // 设置描边
        fillPath.closePath(); // 闭合路径
        g2d.setColor(fillColor); // 设置填充色
        g2d.fill(path); // 填充区域
        g2d.fill(fillPath); // 填充区域
        g2d.setColor(borderColor); // 设置边线颜色
        g2d.draw(path); // 绘制边界
        // 绘制边界线(包括起点到终点的连接)- 实线
        if (boundary.size() >= 2) {
            Path2D.Double borderPath = new Path2D.Double(); // 创建边界路径
            Point2D.Double firstPoint = boundary.get(0);
            borderPath.moveTo(firstPoint.x, firstPoint.y); // 移动到起点
            for (int i = 1; i < boundary.size(); i++) { // 从第二个点到最后一个点
                Point2D.Double point = boundary.get(i);
                borderPath.lineTo(point.x, point.y); // 连线
            }
            // 如果最后一个点不是第一个点,则连接到起点形成闭合
            Point2D.Double lastPoint = boundary.get(boundary.size() - 1);
            if (!lastPoint.equals(firstPoint)) {
                borderPath.lineTo(firstPoint.x, firstPoint.y); // 连接到起点形成闭合
            }
            // 绘制外层实线边界(宽度增加一倍)
            g2d.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // 设置实线描边
            g2d.setColor(borderColor); // 设置边线颜色
            g2d.draw(borderPath); // 绘制完整边界(包括起点到终点的连接)
            // 在边界线中间绘制深灰色小圆点虚线
            float dashedLineWidth = strokeWidth / 3.0f; // 虚线宽度为实线的三分之一
            float[] dashPattern = {2.0f, 2.0f}; // 等间隔小圆点虚线模式:2像素实线(形成圆点),2像素空白(均匀间隔)
            BasicStroke dashedStroke = new BasicStroke(
                dashedLineWidth,
                BasicStroke.CAP_ROUND, // 使用圆形端点,形成圆点效果
                BasicStroke.JOIN_ROUND,
                0.0f,
                dashPattern,
                0.0f
            );
            g2d.setStroke(dashedStroke); // 设置虚线描边
            Color darkGrayColor = new Color(64, 64, 64); // 深灰色
            g2d.setColor(darkGrayColor); // 设置虚线颜色
            g2d.draw(borderPath); // 在中间绘制小圆点虚线
        }
    } // 方法结束
} // 类结束