张世豪
4 天以前 dc9dce0555beb85d1262893fd5d56747d6a83855
src/zhuye/bianjiedrwa.java
@@ -23,24 +23,42 @@
            return; // 无数据返回
        } // if结束
        Path2D path = new Path2D.Double(); // 创建路径
        float strokeWidth = (float) (3 / Math.max(0.5, scale)); // 计算边线宽度
        // 填充区域
        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); // 绘制完整边界(包括起点到终点的连接)
        }
    } // 方法结束
} // 类结束