forked from 1b-agent/opencadstudio-upstream
Attach analytical arc to polyline Arc mode rubber-band preview
This commit is contained in:
1 parent
ec3b6b89f6
commit
a754fac6d4
4 files changed
+223
-8
No files matched your search
@@ -219,7 +219,33 @@ fn split_mixed_polyline(
|
||||
|
||||
// Emit each arc segment as an analytical wire (CircleGpu target)
|
||||
for tg in tangent_geoms {
|
||||
if matches!(tg, TangentGeom::Arc { .. }) {
|
||||
if let TangentGeom::Arc {
|
||||
center,
|
||||
axis_x,
|
||||
axis_y,
|
||||
radius,
|
||||
start_angle,
|
||||
end_angle,
|
||||
} = *tg
|
||||
{
|
||||
let mut arc_pts = Vec::with_capacity(17);
|
||||
let n = 16;
|
||||
let sweep = if end_angle >= start_angle {
|
||||
end_angle - start_angle
|
||||
} else {
|
||||
end_angle - start_angle + std::f64::consts::TAU
|
||||
};
|
||||
for s in 0..=n {
|
||||
let frac = s as f64 / n as f64;
|
||||
let ang = start_angle + frac * sweep;
|
||||
let p = [
|
||||
center[0] + radius * (ang.cos() * axis_x[0] + ang.sin() * axis_y[0]),
|
||||
center[1] + radius * (ang.cos() * axis_x[1] + ang.sin() * axis_y[1]),
|
||||
center[2] + radius * (ang.cos() * axis_x[2] + ang.sin() * axis_y[2]),
|
||||
];
|
||||
arc_pts.push(p);
|
||||
}
|
||||
let (points, points_low) = points_to_ds(arc_pts);
|
||||
out.push(WireModel {
|
||||
bg_adapt: None,
|
||||
point_marker: None,
|
||||
@@ -238,8 +264,8 @@ fn split_mixed_polyline(
|
||||
dash_align_end: None,
|
||||
text_verts: Vec::new(),
|
||||
name: name.to_string(),
|
||||
points: Vec::new(),
|
||||
points_low: Vec::new(),
|
||||
points,
|
||||
points_low,
|
||||
color,
|
||||
selected,
|
||||
pattern_length,
|
||||
|
||||
@@ -408,3 +408,76 @@ fn late_device_errors_invalidate_uploaded_content_and_targets() {
|
||||
"the same error must not invalidate twice"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires a GPU adapter"]
|
||||
fn test_pline_arc_switch_preview_and_render() {
|
||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle());
|
||||
let adapter = block_on(instance.request_adapter(&wgpu::RequestAdapterOptions::default()))
|
||||
.expect("GPU adapter");
|
||||
let (device, queue) = block_on(adapter.request_device(&wgpu::DeviceDescriptor {
|
||||
required_limits: adapter.limits(),
|
||||
..Default::default()
|
||||
}))
|
||||
.expect("GPU device");
|
||||
let mut pipeline = Pipeline::new(&device, &queue, wgpu::TextureFormat::Bgra8UnormSrgb);
|
||||
let depth = rustc_hash::FxHashMap::default();
|
||||
use crate::command::CadCommand;
|
||||
|
||||
let mut cmd = crate::modules::draw::draw::polyline::PlineCommand::new();
|
||||
cmd.on_point(glam::DVec3::new(0.0, 0.0, 0.0));
|
||||
let _res = cmd.on_point(glam::DVec3::new(10.0, 0.0, 0.0));
|
||||
cmd.set_live_handle(acadrust::Handle::new(1));
|
||||
cmd.on_text_input("A");
|
||||
|
||||
let test_points = [
|
||||
glam::DVec3::new(10.0, 0.0, 0.0),
|
||||
glam::DVec3::new(10.0000001, 0.0, 0.0),
|
||||
glam::DVec3::new(10.0, 0.0000001, 0.0),
|
||||
glam::DVec3::new(10.0, -0.0000001, 0.0),
|
||||
glam::DVec3::new(9.9999999, 0.0, 0.0),
|
||||
glam::DVec3::new(15.0, 5.0, 0.0),
|
||||
glam::DVec3::new(10.0, 10.0, 0.0),
|
||||
glam::DVec3::new(5.0, 5.0, 0.0),
|
||||
glam::DVec3::new(0.0, 0.0, 0.0),
|
||||
];
|
||||
|
||||
pipeline.ensure_depth_texture(&device, iced::Size::new(512, 512));
|
||||
let texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: Some("test_target"),
|
||||
size: wgpu::Extent3d {
|
||||
width: 512,
|
||||
height: 512,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
view_formats: &[],
|
||||
});
|
||||
let target = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
for pt in test_points {
|
||||
let wire = cmd.on_mouse_move(pt);
|
||||
if let Some(w) = wire {
|
||||
pipeline.upload_preview_wires(&device, &queue, &[w], &depth);
|
||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
label: Some("test_encoder"),
|
||||
});
|
||||
pipeline.render(
|
||||
&mut encoder,
|
||||
&target,
|
||||
iced::Size::new(512, 512),
|
||||
iced::Rectangle { x: 0, y: 0, width: 512, height: 512 },
|
||||
[0.0, 0.0, 0.0, 1.0],
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
queue.submit(Some(encoder.finish()));
|
||||
device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user