forked from 1b-agent/opencadstudio-upstream
ocs_doc_api: Phase 2b-c (linear Dimension) — Phase 2 complete
- CreateDimensionLinear(DimensionSpec) op + GetDimensionMeasurement query (append-only). - backend add_dimension_linear (Dimension::Linear via DimensionLinear::new) + dimension_measurement (linear/radius/diameter distance). - Dimension bounds from measured + definition points; Dimension handle + measurement(). - spec Dimension family; api_reference + binding_schema regenerated; mocks + baseline. - Test phase2c_dimension_linear_create_measurement_bounds -> 607 host lib + 8 crate + 3 consistency green. Phase 2 (full 2D + annotations) is now complete.
This commit is contained in:
1 parent
ba8e5ed0cd
commit
2dba0158ca
16 files changed
+209
-3
No files matched your search
@@ -25,6 +25,8 @@ struct MockBackend {
|
||||
text_values: HashMap<ObjectId, String>,
|
||||
/// Stored hatch boundary loops.
|
||||
hatch_boundaries: HashMap<ObjectId, Vec<Vec<[f64; 2]>>>,
|
||||
/// Stored dimension measurements.
|
||||
dimension_measurements: HashMap<ObjectId, f64>,
|
||||
}
|
||||
|
||||
impl MockBackend {
|
||||
@@ -106,6 +108,18 @@ impl DocApiBackend for MockBackend {
|
||||
fn hatch_boundary(&self, id: ObjectId) -> ApiResult<Vec<Vec<[f64; 2]>>> {
|
||||
self.hatch_boundaries.get(&id).cloned().ok_or(ApiError::UnknownId(id))
|
||||
}
|
||||
fn add_dimension_linear(&mut self, spec: &ocs_doc_api::ops::DimensionSpec) -> ApiResult<ObjectId> {
|
||||
let id = self.alloc("Dimension");
|
||||
let d = ((spec.first_point[0] - spec.second_point[0]).powi(2)
|
||||
+ (spec.first_point[1] - spec.second_point[1]).powi(2)
|
||||
+ (spec.first_point[2] - spec.second_point[2]).powi(2))
|
||||
.sqrt();
|
||||
self.dimension_measurements.insert(id, d);
|
||||
Ok(id)
|
||||
}
|
||||
fn dimension_measurement(&self, id: ObjectId) -> ApiResult<f64> {
|
||||
self.dimension_measurements.get(&id).copied().ok_or(ApiError::UnknownId(id))
|
||||
}
|
||||
fn add_vertex(&mut self, id: ObjectId, _at: usize, _point: [f64; 3]) -> ApiResult<()> {
|
||||
if self.entity_exists(id) {
|
||||
Ok(())
|
||||
|
||||
@@ -57,6 +57,7 @@ fn operation_variants() -> Vec<String> {
|
||||
Operation::CreateMText(ocs_doc_api::ops::MTextSpec { value: String::new(), insertion_point: [0.0; 3], height: 0.0 }),
|
||||
Operation::SetTextContent { id: ObjectId::from_u64(0), value: String::new() },
|
||||
Operation::CreateHatch(ocs_doc_api::ops::HatchSpec { boundary: vec![], solid: true }),
|
||||
Operation::CreateDimensionLinear(ocs_doc_api::ops::DimensionSpec { first_point: [0.0; 3], second_point: [0.0; 3], definition_point: [0.0; 3] }),
|
||||
];
|
||||
// Derive the variant names by serializing a probe of each and reading the
|
||||
// bincode variant index -> name map is not available; instead match by
|
||||
@@ -83,6 +84,7 @@ fn query_variants() -> Vec<String> {
|
||||
Query::GetGeometryRevision,
|
||||
Query::GetTextContent { id: ObjectId::from_u64(0) },
|
||||
Query::GetHatchBoundary { id: ObjectId::from_u64(0) },
|
||||
Query::GetDimensionMeasurement { id: ObjectId::from_u64(0) },
|
||||
];
|
||||
marker
|
||||
.iter()
|
||||
@@ -137,6 +139,7 @@ const OPERATION_BASELINE: &[&str] = &[
|
||||
"CreateMText",
|
||||
"SetTextContent",
|
||||
"CreateHatch",
|
||||
"CreateDimensionLinear",
|
||||
];
|
||||
|
||||
/// Recorded baseline of the `Query` variant order.
|
||||
@@ -149,6 +152,7 @@ const QUERY_BASELINE: &[&str] = &[
|
||||
"GetGeometryRevision",
|
||||
"GetTextContent",
|
||||
"GetHatchBoundary",
|
||||
"GetDimensionMeasurement",
|
||||
];
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user