ifc_geometry/authoring/
solid.rs1use ifc_model::{Entity, EntityId, Transaction, Value};
9
10use crate::error::GeometryError;
11use crate::solid::boolean::{slot as boolean_slot, IfcBooleanOperator};
12use crate::solid::swept::{extruded_slot, revolved_slot, swept_area_slot};
13
14use super::invalid;
15
16pub fn extruded_area_solid(
24 tx: &mut Transaction,
25 swept_area: EntityId,
26 position: Option<EntityId>,
27 extruded_direction: EntityId,
28 depth: f64,
29) -> Result<EntityId, GeometryError> {
30 if !depth.is_finite() || depth <= 0.0 {
31 return Err(invalid(
32 "IFCEXTRUDEDAREASOLID",
33 "Depth",
34 format!("expected a positive length, got {depth}"),
35 ));
36 }
37 let mut attrs = vec![Value::Null; 4];
38 attrs[swept_area_slot::SWEPT_AREA] = Value::Ref(swept_area);
39 attrs[swept_area_slot::POSITION] = position.map_or(Value::Null, Value::Ref);
40 attrs[extruded_slot::EXTRUDED_DIRECTION] = Value::Ref(extruded_direction);
41 attrs[extruded_slot::DEPTH] = Value::Real(depth);
42 Ok(tx.create(Entity::new("IFCEXTRUDEDAREASOLID", attrs)))
43}
44
45pub fn revolved_area_solid(
56 tx: &mut Transaction,
57 swept_area: EntityId,
58 position: Option<EntityId>,
59 axis: EntityId,
60 angle: f64,
61) -> Result<EntityId, GeometryError> {
62 if !angle.is_finite() || angle <= 0.0 || angle > std::f64::consts::TAU {
63 return Err(invalid(
64 "IFCREVOLVEDAREASOLID",
65 "Angle",
66 format!("expected an angle in (0, 2pi] radians, got {angle}"),
67 ));
68 }
69 let mut attrs = vec![Value::Null; 4];
70 attrs[swept_area_slot::SWEPT_AREA] = Value::Ref(swept_area);
71 attrs[swept_area_slot::POSITION] = position.map_or(Value::Null, Value::Ref);
72 attrs[revolved_slot::AXIS] = Value::Ref(axis);
73 attrs[revolved_slot::ANGLE] = Value::Real(angle);
74 Ok(tx.create(Entity::new("IFCREVOLVEDAREASOLID", attrs)))
75}
76
77pub fn boolean_result(
87 tx: &mut Transaction,
88 operator: IfcBooleanOperator,
89 first: EntityId,
90 second: EntityId,
91) -> Result<EntityId, GeometryError> {
92 if first == second {
93 return Err(invalid(
94 "IFCBOOLEANRESULT",
95 "SecondOperand",
96 "both operands are the same entity",
97 ));
98 }
99 let mut attrs = vec![Value::Null; 3];
100 attrs[boolean_slot::OPERATOR] = Value::Enum(operator.as_token().into());
101 attrs[boolean_slot::FIRST_OPERAND] = Value::Ref(first);
102 attrs[boolean_slot::SECOND_OPERAND] = Value::Ref(second);
103 Ok(tx.create(Entity::new("IFCBOOLEANRESULT", attrs)))
104}