forked from 1b-agent/opencadstudio-upstream
fix: keep exact snapping, source drawing data and adaptive options layout
Resolve curve intersections through cadkernel, retain empty exact results, gather analytic candidates independently of tessellation, and bound material uploads. Preserve large MINSERT data while limiting rendering work; remove obsolete review narratives.
This commit is contained in:
1 parent
4bb6aac0b6
commit
973af87d58
16 files changed
+57
-724
No files matched your search
@@ -568,12 +568,15 @@ struct MeshSurfaceParams {
|
||||
flags: [u32; 4],
|
||||
}
|
||||
|
||||
/// Downscale a decoded RGBA buffer so neither dimension exceeds `limit`,
|
||||
/// preserving aspect ratio (scaled by whichever dimension overshoots more).
|
||||
/// `None` only for genuinely malformed input (`rgba`'s length doesn't match
|
||||
/// `width * height * 4`) — the caller falls back to the 1x1 material color
|
||||
/// in that case, same as it already does for a missing image entirely.
|
||||
fn valid_rgba_size(width: u32, height: u32, pixels: &[u8]) -> bool {
|
||||
width > 0 && height > 0
|
||||
&& (width as usize).checked_mul(height as usize).and_then(|size| size.checked_mul(4)) == Some(pixels.len())
|
||||
}
|
||||
|
||||
fn downscale_rgba_to_limit(width: u32, height: u32, rgba: &[u8], limit: u32) -> Option<(u32, u32, Vec<u8>)> {
|
||||
if limit == 0 || !valid_rgba_size(width, height, rgba) {
|
||||
return None;
|
||||
}
|
||||
let buffer = image::RgbaImage::from_raw(width, height, rgba.to_vec())?;
|
||||
let scale = (limit as f64 / width.max(height) as f64).min(1.0);
|
||||
let new_width = ((width as f64 * scale).round() as u32).clamp(1, limit);
|
||||
@@ -590,14 +593,9 @@ fn upload_rgba_texture(
|
||||
fallback: [u8; 4],
|
||||
srgb: bool,
|
||||
) -> wgpu::TextureView {
|
||||
// A material map's decoded dimensions come straight from the source file
|
||||
// (`material_model::load_map_image`), uncapped — an oversized image would
|
||||
// otherwise fail `wgpu` texture-size validation and leave the material
|
||||
// unusable (audit: raster-image rendering already tiles to this same
|
||||
// limit in `image_gpu.rs`; a mesh material sampled by UV can't use that
|
||||
// per-quad tiling trick, so downscale instead of tiling).
|
||||
let limit = device.limits().max_texture_dimension_2d.max(1);
|
||||
let resized;
|
||||
let image = image.filter(|image| valid_rgba_size(image.width, image.height, &image.rgba));
|
||||
let (width, height, pixels): (u32, u32, &[u8]) = match image {
|
||||
Some(image) if image.width > limit || image.height > limit => {
|
||||
match downscale_rgba_to_limit(image.width, image.height, &image.rgba, limit) {
|
||||
|
||||
@@ -2701,13 +2701,6 @@ impl Pipeline {
|
||||
// O(highlighted), no per-wire string parse or deep geometry clone.
|
||||
let mut selected_wires: Vec<&WireModel> = Vec::new();
|
||||
let mut hover_wires: Vec<&WireModel> = Vec::new();
|
||||
// The index is built by walking the wires in order, so each handle's
|
||||
// slots come out ascending, and `patch_handle_index` only shifts them
|
||||
// by a constant, which keeps that. Cloning and re-sorting per handle
|
||||
// was one allocation and one sort for every selected entity — 186 468
|
||||
// of each on a whole-drawing selection. The assert holds the invariant
|
||||
// in place: if it ever breaks, a debug build says so here rather than
|
||||
// drawing the highlight in the wrong order.
|
||||
for h in selected {
|
||||
if let Some(idxs) = self.wire_handle_index.get(&h.value()) {
|
||||
debug_assert!(
|
||||
@@ -2747,25 +2740,6 @@ impl Pipeline {
|
||||
}
|
||||
}
|
||||
let t_gather = perf_started.map(|t| t.elapsed().as_secs_f64() * 1000.0);
|
||||
// One extraction pass per wire, where there used to be four.
|
||||
//
|
||||
// The old shape asked each extractor twice: once at the draw depth to
|
||||
// build the instances, then once more at depth 0.0 purely to ask
|
||||
// *whether* the wire is a circle or an ellipse — allocating a vector
|
||||
// each time and dropping it. Neither extractor's `Some`/`None` answer
|
||||
// depends on the depth: every `return None` in them turns on the
|
||||
// geometry (which `TangentGeom` variant, the radius, the axis lengths,
|
||||
// the parameters), and the depth is only written into the instance,
|
||||
// never read to decide. So the extraction that builds the instances
|
||||
// already answers the classification, and the second pair is pure
|
||||
// waste — 116 ms of shapes plus 57 ms of splitting, out of a 299 ms
|
||||
// highlight at 186 468 entities.
|
||||
//
|
||||
// A wire with a `render_instance` is a block wire, and both extractors
|
||||
// reject those outright, so it skips extraction altogether.
|
||||
// Selected keeps its colour unless a tint is configured; hover is
|
||||
// always recoloured. Both vectors carry selected first, then hover,
|
||||
// exactly as the four separate loops produced them.
|
||||
let (mut selected_circles, mut selected_ellipses, selected_regular, selected_blocks) =
|
||||
Self::classify_highlight_wires(
|
||||
&selected_wires,
|
||||
@@ -2857,12 +2831,6 @@ impl Pipeline {
|
||||
if let Some(started) = perf_started {
|
||||
let elapsed_ms = started.elapsed().as_secs_f64() * 1000.0;
|
||||
if elapsed_ms >= 1.0 {
|
||||
// Cumulative marks, differenced here: gathering the wires
|
||||
// from the handle index, classifying them and extracting their
|
||||
// analytic instances, uploading those, building the regular
|
||||
// wire instances, and the block ones. A one-time cost when the
|
||||
// selection changes, which puts it directly between the user's
|
||||
// second click and seeing the selection.
|
||||
let gather = t_gather.unwrap_or(0.0);
|
||||
let classify = t_shapes.unwrap_or(0.0);
|
||||
let analytic = t_split.unwrap_or(0.0);
|
||||
@@ -5725,12 +5693,6 @@ mod highlight_classification_tests {
|
||||
wire
|
||||
}
|
||||
|
||||
// The classification used to be a second pair of extractions at depth 0.0,
|
||||
// run purely to ask which bucket a wire belongs in. It now rides the
|
||||
// extraction that builds the instances. Nothing renders in a test, so a
|
||||
// wrong answer here would show up only as circles drawn wrong when
|
||||
// selected — this asserts the buckets directly, against the predicate the
|
||||
// old code used.
|
||||
#[test]
|
||||
fn each_wire_lands_in_the_bucket_the_old_predicate_chose() {
|
||||
let wires = vec![plain("1"), circle("2"), ellipse("3"), plain("4")];
|
||||
|
||||
@@ -1148,11 +1148,6 @@ impl WireGpu {
|
||||
|
||||
let _ = const_bgl;
|
||||
let max_packed_instances = super::gpu_budget::max_elements::<PackedWireInstance>(device);
|
||||
// Same fan-out the native path above uses: emitting a wire reads that
|
||||
// wire and the depth map and writes nothing shared, and a selection
|
||||
// large enough to be slow is exactly where it pays. `collect` on an
|
||||
// indexed parallel iterator keeps the order, which the instance indices
|
||||
// depend on.
|
||||
use crate::par::prelude::*;
|
||||
let per: Vec<Vec<PackedWireInstance>> = wires
|
||||
.par_iter()
|
||||
|
||||
Reference in new issue
Block a user