ifc_alignment/authoring/
mod.rs1mod layout;
17mod linear;
18mod referent;
19mod segment;
20
21pub use layout::{alignment, alignment_segment, cant_layout, horizontal_layout, vertical_layout};
22pub use linear::{linear_element, linear_positioning_element};
23pub use referent::{
24 axis2_placement_linear, cartesian_point, linear_placement, point_by_distance, referent,
25 stationing,
26};
27pub use segment::{
28 cant_segment, horizontal_segment, vertical_segment, CantSegmentDraft, HorizontalSegmentDraft,
29 VerticalSegmentDraft,
30};
31
32use ifc_model::guid::Guid;
33use ifc_model::Value;
34
35use crate::error::AlignmentError;
36
37pub(crate) fn invalid(
39 type_name: &'static str,
40 attribute: &'static str,
41 detail: impl Into<String>,
42) -> AlignmentError {
43 AlignmentError::InvalidAuthoredValue {
44 type_name,
45 attribute,
46 detail: detail.into(),
47 }
48}
49
50pub(crate) fn finite(
53 type_name: &'static str,
54 attribute: &'static str,
55 value: f64,
56) -> Result<(), AlignmentError> {
57 if value.is_finite() {
58 Ok(())
59 } else {
60 Err(invalid(
61 type_name,
62 attribute,
63 format!("{value} is not finite"),
64 ))
65 }
66}
67
68pub(crate) fn guid(type_name: &'static str, value: &str) -> Result<Value, AlignmentError> {
73 if Guid::parse(value).is_none() {
74 return Err(invalid(
75 type_name,
76 "GlobalId",
77 format!(
78 "{value:?} is not a compressed IFC GlobalId (22 characters of \
79 0-9 A-Z a-z _ $, the first 0-3)"
80 ),
81 ));
82 }
83 Ok(Value::Text(value.into()))
84}