解决圆弧镜像的问题

master
liaoxianglian 5 months ago
parent f8d92515bd
commit ab767ddc6a

@ -18,27 +18,56 @@ pub struct Arc {
impl From<&entities::Arc> for Arc { impl From<&entities::Arc> for Arc {
fn from(arc: &entities::Arc) -> Self { 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 { } 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 { 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, y: -arc.center.y - arc.radius,
height: arc.radius * 2.0, height: arc.radius * 2.0,
width: arc.radius * 2.0, width: arc.radius * 2.0,
start: if arc.start_angle < 0.0 { start: if start_angle < 0.0 { -start_angle } else { start_angle },
-arc.start_angle angle: if angle_span < 0.0 { -angle_span } else { angle_span },
} else {
arc.start_angle
},
angle: if temp_angle < 0.0 {
-temp_angle
} else {
temp_angle
},
//in the original code antialias is always set to false...I'm guessing for performance //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? //reasons...I'm trying to think if there is a time we might want to turn it on?

@ -41,8 +41,8 @@ impl From<&entities::Ellipse> for Ellipse {
Ellipse { Ellipse {
x: ellipse.center.x - ellipse.major_axis.x, x: ellipse.center.x - ellipse.major_axis.x,
y: -ellipse.center.y - ellipse.major_axis.x * ellipse.minor_axis_ratio, 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,
width: ellipse.major_axis.x * 2.0 * ellipse.minor_axis_ratio, 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 //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? //reasons...I'm trying to think if there is a time we might want to turn it on?

Loading…
Cancel
Save