diff --git a/src/qelmt/arc.rs b/src/qelmt/arc.rs index fb5b5a5..84912a2 100644 --- a/src/qelmt/arc.rs +++ b/src/qelmt/arc.rs @@ -18,27 +18,56 @@ pub struct Arc { impl From<&entities::Arc> for Arc { fn from(arc: &entities::Arc) -> Self { - let temp_angle = if arc.start_angle > arc.end_angle { - (360.0 - arc.start_angle) + arc.end_angle + + let is_mirror = arc.normal.z < 0.0; + + let (start_angle, angle_span) = if is_mirror { + // 镜像变换:角度关于Y轴对称,即 θ -> 180° - θ + // 同时交换起始和结束角度以保持正确的绘制方向 + let mirrored_start = 180.0 - arc.end_angle; + let mirrored_end = 180.0 - arc.start_angle; + + // 标准化角度到0-360度范围 + let norm_start = if mirrored_start < 0.0 { + mirrored_start + 360.0 + } else { + mirrored_start + }; + let norm_end = if mirrored_end < 0.0 { + mirrored_end + 360.0 + } else { + mirrored_end + }; + + // 计算角度跨度 + let span = if norm_end >= norm_start { + norm_end - norm_start + } else { + (360.0 - norm_start) + norm_end + }; + + (norm_start, span) } else { - arc.end_angle - arc.start_angle + // 正常情况:直接使用原始角度 + let span = if arc.end_angle >= arc.start_angle { + arc.end_angle - arc.start_angle + } else { + (360.0 - arc.start_angle) + arc.end_angle + }; + (arc.start_angle, span) }; Arc { - x: arc.center.x - arc.radius, + x: if is_mirror { + -arc.center.x - arc.radius + } else { + arc.center.x - arc.radius + }, y: -arc.center.y - arc.radius, height: arc.radius * 2.0, width: arc.radius * 2.0, - start: if arc.start_angle < 0.0 { - -arc.start_angle - } else { - arc.start_angle - }, - angle: if temp_angle < 0.0 { - -temp_angle - } else { - temp_angle - }, + start: if start_angle < 0.0 { -start_angle } else { start_angle }, + angle: if angle_span < 0.0 { -angle_span } else { angle_span }, //in the original code antialias is always set to false...I'm guessing for performance //reasons...I'm trying to think if there is a time we might want to turn it on? diff --git a/src/qelmt/ellipse.rs b/src/qelmt/ellipse.rs index 6cce6e5..6dcf8ab 100644 --- a/src/qelmt/ellipse.rs +++ b/src/qelmt/ellipse.rs @@ -41,8 +41,8 @@ impl From<&entities::Ellipse> for Ellipse { Ellipse { x: ellipse.center.x - ellipse.major_axis.x, y: -ellipse.center.y - ellipse.major_axis.x * ellipse.minor_axis_ratio, - height: ellipse.major_axis.x * 2.0, - width: ellipse.major_axis.x * 2.0 * ellipse.minor_axis_ratio, + width: ellipse.major_axis.x * 2.0, + height: ellipse.major_axis.x * 2.0 * ellipse.minor_axis_ratio, //in the original code antialias is always set to false...I'm guessing for performance //reasons...I'm trying to think if there is a time we might want to turn it on?