forked from 1b-agent/opencadstudio-upstream
Merge pull request #1206 from Ramox81/codex/fix-region-measurement-persistence-20260911
This commit is contained in:
commit
c4506bf0d9
4 files changed
+73
-28
No files matched your search
+7
-13
@@ -213,14 +213,8 @@ fn entity_json(e: &acadrust::EntityType, detail: &str) -> Value {
|
||||
_ => {}
|
||||
}
|
||||
if detail == "full" {
|
||||
let bounds = e.as_entity().bounding_box();
|
||||
map.insert(
|
||||
"bounds".into(),
|
||||
json!({
|
||||
"min":[bounds.min.x,bounds.min.y,bounds.min.z],
|
||||
"max":[bounds.max.x,bounds.max.y,bounds.max.z]
|
||||
}),
|
||||
);
|
||||
let (min, max) = crate::scene::convert::tess::entity_bounds(e);
|
||||
map.insert("bounds".into(), json!({ "min": min, "max": max }));
|
||||
if let Ok(Value::Object(wrapper)) = serde_json::to_value(e) {
|
||||
if let Some((_, properties)) = wrapper.into_iter().next() {
|
||||
map.insert("properties".into(), properties);
|
||||
@@ -654,11 +648,11 @@ impl OpenCADStudio {
|
||||
continue;
|
||||
}
|
||||
if let Some(bounds) = bounds {
|
||||
let entity_bounds = e.as_entity().bounding_box();
|
||||
if entity_bounds.max.x < bounds[0]
|
||||
|| entity_bounds.max.y < bounds[1]
|
||||
|| entity_bounds.min.x > bounds[2]
|
||||
|| entity_bounds.min.y > bounds[3]
|
||||
let (min, max) = crate::scene::convert::tess::entity_bounds(e);
|
||||
if max[0] < bounds[0]
|
||||
|| max[1] < bounds[1]
|
||||
|| min[0] > bounds[2]
|
||||
|| min[1] > bounds[3]
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -968,7 +968,7 @@ impl OpenCADStudio {
|
||||
let Some(entity) = tab.scene.document.get_entity(handle) else {
|
||||
continue;
|
||||
};
|
||||
let bb = entity.as_entity().bounding_box();
|
||||
let (min, max) = crate::scene::convert::tess::entity_bounds(entity);
|
||||
let metrics = tab
|
||||
.scene
|
||||
.meshes
|
||||
@@ -994,7 +994,7 @@ impl OpenCADStudio {
|
||||
"area":planar.curve.is_closed().then(|| planar.curve.enclosed_area().abs())
|
||||
})
|
||||
});
|
||||
out.push(json!({"handle":format!("{:X}",handle.value()),"type":crate::entities::names::ui_name(entity),"bounds":{"min":[bb.min.x,bb.min.y,bb.min.z],"max":[bb.max.x,bb.max.y,bb.max.z]},"curve":curve,"mesh":metrics.map(|m|json!({"vertices":m.metrics.vertices,"triangles":m.metrics.triangles,"surface_area":m.metrics.surface_area,"volume":m.metrics.volume,"centroid":m.metrics.centroid,"moment_of_inertia":m.metrics.moment_of_inertia,"principal_directions":m.metrics.principal_directions,"principal_moments":m.metrics.principal_moments,"product_of_inertia":m.metrics.product_of_inertia,"radii_of_gyration":m.metrics.radii_of_gyration}))}));
|
||||
out.push(json!({"handle":format!("{:X}",handle.value()),"type":crate::entities::names::ui_name(entity),"bounds":{"min":min,"max":max},"curve":curve,"mesh":metrics.map(|m|json!({"vertices":m.metrics.vertices,"triangles":m.metrics.triangles,"surface_area":m.metrics.surface_area,"volume":m.metrics.volume,"centroid":m.metrics.centroid,"moment_of_inertia":m.metrics.moment_of_inertia,"principal_directions":m.metrics.principal_directions,"principal_moments":m.metrics.principal_moments,"product_of_inertia":m.metrics.product_of_inertia,"radii_of_gyration":m.metrics.radii_of_gyration}))}));
|
||||
}
|
||||
json!({"ok":true,"document_id":tab.id,"geometry_revision":tab.scene.geometry_epoch,"measurements":out})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user