forked from 1b-agent/opencadstudio-upstream
refactor(commands): per-entity MassProps + TextContent traits
Two free helpers in app/commands.rs lived as big match-on-EntityType blocks: massprop_entity (Circle/Arc/Line/LwPolyline/Ellipse area + perimeter + centroid, ~140 lines) and entity_text_content / replace_entity_text (Text/MText/AttributeDefinition/AttributeEntity). Move each to its own trait in entities/traits.rs and implement per-entity: MassPropsCalc — Circle, Arc, Line, LwPolyline, Ellipse TextContent — Text, MText, AttributeDefinition, AttributeEntity EntityTypeOps gets dispatch shims that route to the trait via the existing macro, so callsites just call entity.mass_props() / entity.text_content() / entity.replace_text(search, rep). The remaining free helpers in commands.rs (entity_list_details, entity_extra_info, entity_type_name, build_data_extraction_csv) are single-command formatting helpers tightly coupled to LIST / EXTRACT / text-format output. Distributing them as per-entity methods would inflate every entity file with command-side formatting concerns without making the command-side any cleaner — left in place. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
40180e9089
commit
e78321190a
10 files changed
+266
-193
No files matched your search
@@ -227,3 +227,16 @@ impl Transformable for Circle {
|
||||
apply_transform(self, t);
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::entities::traits::MassPropsCalc for Circle {
|
||||
fn mass_props(&self) -> crate::entities::traits::MassProps {
|
||||
use std::f64::consts::{PI, TAU};
|
||||
let r = self.radius;
|
||||
crate::entities::traits::MassProps {
|
||||
area: PI * r * r,
|
||||
perimeter: TAU * r,
|
||||
cx: self.center.x,
|
||||
cy: self.center.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user