ifc_geometry/authoring/std_profile/
closed_section.rs1use ifc_model::{Entity, EntityId, Transaction, Value};
6
7use crate::error::GeometryError;
8use crate::slots::profile_slot as base;
9use crate::slots::section_slot as slot;
10
11use super::super::require_finite;
12use super::{
13 non_negative, parameterized, positive, put_opt, rule, ProfileHeader, RectangleHollowDims,
14 RectangleHollowFillets, TrapeziumDims,
15};
16
17pub fn ellipse_profile(
25 tx: &mut Transaction,
26 header: ProfileHeader<'_>,
27 semi_axis_1: f64,
28 semi_axis_2: f64,
29) -> Result<EntityId, GeometryError> {
30 const T: &str = "IFCELLIPSEPROFILEDEF";
31 positive(T, "SemiAxis1", semi_axis_1)?;
32 positive(T, "SemiAxis2", semi_axis_2)?;
33 let mut attrs = parameterized(T, 5, header);
34 attrs[slot::E_SEMI1] = Value::Real(semi_axis_1);
35 attrs[slot::E_SEMI2] = Value::Real(semi_axis_2);
36 Ok(tx.create(Entity::new(T, attrs)))
37}
38
39pub fn trapezium_profile(
48 tx: &mut Transaction,
49 header: ProfileHeader<'_>,
50 dims: TrapeziumDims,
51) -> Result<EntityId, GeometryError> {
52 const T: &str = "IFCTRAPEZIUMPROFILEDEF";
53 let TrapeziumDims {
54 bottom_x_dim,
55 top_x_dim,
56 y_dim,
57 top_x_offset,
58 } = dims;
59 positive(T, "BottomXDim", bottom_x_dim)?;
60 positive(T, "TopXDim", top_x_dim)?;
61 positive(T, "YDim", y_dim)?;
62 require_finite(T, "TopXOffset", &[top_x_offset])?;
63 let mut attrs = parameterized(T, 7, header);
64 attrs[slot::TZ_BOTTOM] = Value::Real(bottom_x_dim);
65 attrs[slot::TZ_TOP] = Value::Real(top_x_dim);
66 attrs[slot::TZ_Y] = Value::Real(y_dim);
67 attrs[slot::TZ_OFFSET] = Value::Real(top_x_offset);
68 Ok(tx.create(Entity::new(T, attrs)))
69}
70pub fn rectangle_hollow_profile(
82 tx: &mut Transaction,
83 header: ProfileHeader<'_>,
84 dims: RectangleHollowDims,
85 fillets: RectangleHollowFillets,
86) -> Result<EntityId, GeometryError> {
87 const T: &str = "IFCRECTANGLEHOLLOWPROFILEDEF";
88 let RectangleHollowDims {
89 x_dim,
90 y_dim,
91 wall_thickness,
92 } = dims;
93 let inner_fillet_radius = fillets.inner;
94 let outer_fillet_radius = fillets.outer;
95 positive(T, "XDim", x_dim)?;
96 positive(T, "YDim", y_dim)?;
97 positive(T, "WallThickness", wall_thickness)?;
98 non_negative(T, "InnerFilletRadius", inner_fillet_radius)?;
99 non_negative(T, "OuterFilletRadius", outer_fillet_radius)?;
100 let half_x = x_dim / 2.0;
101 let half_y = y_dim / 2.0;
102 if wall_thickness >= half_x || wall_thickness >= half_y {
103 return Err(rule(
104 T,
105 "WallThickness",
106 format!("{wall_thickness} is not below half of both dimensions ({half_x}, {half_y})"),
107 ));
108 }
109 if let Some(inner) = inner_fillet_radius {
110 let bore_x = half_x - wall_thickness;
111 let bore_y = half_y - wall_thickness;
112 if inner > bore_x || inner > bore_y {
113 return Err(rule(
114 T,
115 "InnerFilletRadius",
116 format!("{inner} exceeds the bore the wall leaves ({bore_x} by {bore_y})"),
117 ));
118 }
119 }
120 if let Some(outer) = outer_fillet_radius {
121 if outer > half_x || outer > half_y {
122 return Err(rule(
123 T,
124 "OuterFilletRadius",
125 format!("{outer} exceeds a half-dimension ({half_x}, {half_y})"),
126 ));
127 }
128 }
129 let mut attrs = parameterized(T, 8, header);
130 attrs[base::X_DIM] = Value::Real(x_dim);
131 attrs[base::Y_DIM] = Value::Real(y_dim);
132 attrs[base::RECT_WALL_THICKNESS] = Value::Real(wall_thickness);
133 put_opt(&mut attrs, base::RECT_INNER_RADIUS, inner_fillet_radius);
134 put_opt(&mut attrs, base::RECT_OUTER_RADIUS, outer_fillet_radius);
135 Ok(tx.create(Entity::new(T, attrs)))
136}
137
138pub fn circle_hollow_profile(
146 tx: &mut Transaction,
147 header: ProfileHeader<'_>,
148 radius: f64,
149 wall_thickness: f64,
150) -> Result<EntityId, GeometryError> {
151 const T: &str = "IFCCIRCLEHOLLOWPROFILEDEF";
152 positive(T, "Radius", radius)?;
153 positive(T, "WallThickness", wall_thickness)?;
154 if wall_thickness >= radius {
155 return Err(rule(
156 T,
157 "WallThickness",
158 format!("{wall_thickness} is not below the Radius {radius}"),
159 ));
160 }
161 let mut attrs = parameterized(T, 5, header);
162 attrs[base::RADIUS] = Value::Real(radius);
163 attrs[base::CIRCLE_WALL_THICKNESS] = Value::Real(wall_thickness);
164 Ok(tx.create(Entity::new(T, attrs)))
165}