1
2use serde::{Deserialize, Serialize};
3use wasm_bindgen::prelude::*;
4
5macro_rules! env_read {
10 ($name:literal) => {{
11 static CELL: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
12 $crate::env_read::read($name, &CELL)
13 }};
14}
15#[macro_export]
23macro_rules! switch {
24 (live $name:expr, $default:expr) => {
25 $crate::env_read::switch_live($name, $default, $crate::env_read::Grammar::Switch)
26 };
27 ($name:expr, $default:expr) => {{
28 static CELL: std::sync::OnceLock<Option<bool>> = std::sync::OnceLock::new();
29 $crate::env_read::switch($name, &CELL, $default, $crate::env_read::Grammar::Switch)
30 }};
31}
32
33#[macro_export]
37macro_rules! debug_flag {
38 (live $name:expr) => {
39 $crate::env_read::switch_live($name, false, $crate::env_read::Grammar::Flag)
40 };
41 ($name:expr) => {{
42 static CELL: std::sync::OnceLock<Option<bool>> = std::sync::OnceLock::new();
43 $crate::env_read::switch($name, &CELL, false, $crate::env_read::Grammar::Flag)
44 }};
45}
46
47#[macro_export]
51macro_rules! mode_switch {
52 (live $name:expr, $default_on:expr) => {
53 $crate::env_read::mode_live($name, $default_on)
54 };
55 ($name:expr, $default_on:expr) => {{
56 static CELL: std::sync::OnceLock<Option<$crate::env_read::Mode>> = std::sync::OnceLock::new();
57 $crate::env_read::mode($name, &CELL, $default_on)
58 }};
59}
60
61macro_rules! profile_line {
64 ($($arg:tt)*) => { $crate::profile::profile_emit(format_args!($($arg)*)) };
65}
66
67#[cfg(all(feature = "wasm-talc", target_family = "wasm", not(target_feature = "atomics")))]
69#[global_allocator]
70static TALC: talc::wasm::WasmDynamicTalc = talc::wasm::new_wasm_dynamic_allocator();
71
72#[cfg(all(feature = "native-rusty-alloc", not(target_family = "wasm")))]
74#[cfg(not(feature = "profile-wall"))]
75#[global_allocator]
76static RUSTY_ALLOC: rusty_alloc_api::RustyAlloc = rusty_alloc_api::RustyAlloc;
77
78#[cfg(all(feature = "native-rusty-alloc", not(target_family = "wasm"), feature = "profile-wall"))]
79#[global_allocator]
80static RUSTY_ALLOC: wall_profile::Allocator<rusty_alloc_api::RustyAlloc> = wall_profile::Allocator(rusty_alloc_api::RustyAlloc);
81
82mod profile;
83#[cfg(feature = "profile-wall")]
84mod wall_profile;
85#[cfg(not(feature = "profile-wall"))]
86#[path = "wall_profile_off.rs"]
87mod wall_profile;
88#[cfg(feature = "profile-wall")]
89mod reader_profile;
90#[cfg(not(feature = "profile-wall"))]
91#[path = "reader_profile_off.rs"]
92mod reader_profile;
93
94
95#[doc(hidden)]
98pub mod env_read;
99
100pub mod panic_hook;
105
106pub mod text;
109
110#[path = "geometry/tolerance.rs"]
111mod tolerance;
112pub use tolerance::{
113 curve_model_scale, model_scale, report_scale_migration, solid_model_scale, solid_scale,
114 offset_construction_band, vertex_tolerance_from_edges, KernelTolerances,
115 MeasuredTolerance, OFFSET_CONSTRUCTION_FLOOR, OFFSET_CONSTRUCTION_REL,
116 VERTEX_MATCH_FLOOR, VOLUME_DRIFT_ABS, VOLUME_DRIFT_REL,
117};
118#[path = "geometry/entity_tolerance.rs"]
123mod entity_tolerance;
124pub use entity_tolerance::{EntityTolerances, EDGE_CAP_FRACTION, VERTEX_CAP_FRACTION};
125#[path = "props/diagnostics.rs"]
126mod diagnostics;
127pub use diagnostics::{
128 Approximation, ApproximationBudget, Backing, BudgetMechanism, BudgetReason, MeasuredComponent, DiagnosticEvent, DiagnosticSeverity, EdgeOrigin, KernelDiagnostics,
129 KernelOutcome, KernelRefusal, OffCarrierEdge,
130 KernelStage, OrRefuse, RefusalClass, SoundnessDefect, UndecidedCause,
131};
132#[path = "geometry/polygon.rs"]
133pub mod polygon;
134#[path = "geometry/curve.rs"]
135mod curve;
136pub use curve::{
137 make_arc, make_circle, make_hyperbola, make_line, make_parabola, uniform_clamped_knots,
138 KnotVector, NurbsCurve, Vec4, KNOT_DEDUP_EPS, KNOT_IDENTITY_TOL,
139};
140#[path = "blending/blend/mod.rs"]
141mod blend;
142pub use blend::{
143 take_blend_approximations, take_blend_notes,
144 blend_timing_capture, take_blend_timings, BlendTiming,
145 blend_closed_edge, blend_edge_variable, blend_open_edge, blend_smooth_chain,
146 round_convex_corner,
147};
148#[path = "blending/fillet.rs"]
149mod fillet;
150pub use fillet::{
151 chamfer_edge, chamfer_edge_angle, chamfer_edge_asymmetric, chamfer_edges_angle,
152 chamfer_edges_asymmetric, fillet_edge, fillet_edges, fillet_edges_reported, fillet_edges_reported_at_offset,
153 fillet_edges_variable, fillet_edges_variable_law, fillet_edges_variable_vertex_radii,
154 BlendSelection,
155};
156#[path = "blending/law.rs"]
157mod law;
158pub use law::{LawSegment, RadiusLaw};
159#[path = "geometry/fit.rs"]
160mod fit;
161pub use fit::{
162 fit_polyline, fit_polyline_at, fit_polyline_of_degree, interpolate_curve, interpolate_curve_closed,
163 interpolate_curve_local, interpolate_curve_thinned, interpolate_curve_with_end_tangents,
164 simplify_polyline, simplify_polyline_indices, solve_banded, solve_dense, PolylineFit,
165 PolylineFitExit, PolylineFitLedger, PolylineFitReport, PolylineFitScope, MAX_FIT_STATIONS,
166};
167#[path = "geometry/image_curve.rs"]
168mod image_curve;
169pub use image_curve::{affine_image_curve, image_curve, image_curve_pair, ImageCurve, ImageCurveTier};
170#[path = "geometry/surface.rs"]
171mod surface;
172pub use surface::{
173 carrier_preview_patch, make_cone_surface, make_cylinder_surface, make_extrusion, make_plane,
174 make_revolution, make_sphere_surface, make_sphere_surface_framed, make_torus_surface,
175 ExtendRefusal, NurbsSurface, SurfaceSide, WeightSite, MAXIMUM_FOLD_ANGLE,
176 MAXIMUM_GROWTH_RATIO,
177};
178#[path = "geometry/control_cage.rs"]
179mod control_cage;
180pub use control_cage::{
181 CagePoint, CagePrimitive, ControlCage, CAGE_DEGREE, MAX_RINGS, MAX_SEGMENTS, MIN_RINGS,
182 MIN_SEGMENTS,
183};
184#[path = "geometry/coons.rs"]
185mod coons;
186pub use coons::{
187 coons_bilinear, coons_bilinear_reported, coons_with_ribbons, CompatWork, CoonsRefusal,
188 CoonsReport, RibbonReport,
189};
190#[path = "geometry/gordon.rs"]
191mod gordon;
192pub use gordon::{gordon_surface, gordon_surface_reported, GordonRefusal, GordonReport};
193#[path = "geometry/analytic_surface.rs"]
194mod analytic_surface;
195pub use analytic_surface::{
196 circle_angle_to_parameter, intersect_analytic_pair, plane_ruled_section_arc,
197 revolution_structure, AnalyticSurface, RevolutionFrame, RevolutionStructure,
198};
199pub(crate) use analytic_surface::{
200 canonical_carriers_enabled, canonicalise_carriers, intersect_analytic_pair_with, ruled_gate,
201 ruled_gate_census, CanonicalReport, CanonicalRewrite, RuledGate,
202};
203#[path = "geometry/sphere_chart.rs"]
204mod sphere_chart;
205pub use sphere_chart::{
206 canonicalize_points, chart_grid_divisions, chart_grid_parameters, corner_index,
207 cube_edge_corner, cube_edge_divisions, cube_edge_index, cube_edge_parameters,
208 cube_edge_parts, Chart, ChartSegment, ChartSide, SphereAtlas,
209 SphericalRegion, CHART_COUNT, CUBE_CORNER_COUNT, CUBE_EDGE_COUNT,
210};
211#[path = "brep/solid_codec.rs"]
212mod solid_codec;
213pub use solid_codec::{decode_solid, encode_solid, SolidNames, SOLID_CODEC_VERSION, SOLID_CODEC_VERSION_KIND};
214#[path = "brep/topology.rs"]
215mod topology;
216pub use topology::{
217 make_box_brep, make_cylinder_brep, make_pyramid_brep, topology_kind, BodyKind, BrepSolid, CellRecord, CoedgeRecord,
218 FaceRecord, IssueKind, KindReport, LoopRecord, TopologyKind, ValidationReport,
219};
220#[path = "brep/soundness.rs"]
221mod soundness;
222pub use soundness::{
223 face_self_intersections, loop_self_crossings, shell_vector_areas, solid_connectivity,
224 solid_euler, solid_self_intersections, ConnectivityReport, CrossingConfirmation, EulerReport,
225 CertificateScope, CertifiedFacePair, FaceCrossing, FaceFold, FaceVectorArea,
226 LoopCrossing, LoopCrossingReport, SelfIntersectionOptions, SelfIntersectionReport,
227 ClosureReading, ShellConnectivity, ShellVectorArea, VectorAreaReport, CrossingUndecidedCause, UndecidedCrossing,
228 MAX_LISTED_UNDECIDED,
229};
230#[path = "brep/topology_arena.rs"]
231mod topology_arena;
232pub use topology_arena::{
233 ArenaCoedge, ArenaEdge, ArenaFace, ArenaLoop, ArenaShell, ArenaVertex, CoedgeId, EdgeId,
234 FaceId, LoopId, ShellId, TopologyArena, VertexId,
235};
236#[path = "brep/analytic_topology.rs"]
237mod analytic_topology;
238pub use analytic_topology::{
239 make_cone_brep, make_sphere_brep, make_sphere_brep_framed, make_torus_brep,
240};
241#[path = "construction/solid_sweep.rs"]
242mod solid_sweep;
243pub use solid_sweep::{
244 sweep_solid_within, OutlinePiece, ScrewStep, SolidMotion, SweepClip, SweptTool, SOLID_SWEEP_REFUSAL,
245};
246#[path = "construction/solid_sweep_caps.rs"]
247mod solid_sweep_caps;
248pub use solid_sweep_caps::{sweep_solid, sweep_prism_along, sweep_solid_along, sweep_solid_clipped, sweep_solid_parts, sweep_solid_rising, FrameCurve, RisingTurn, SolidTool, SOLID_SWEEP_WHOLE_REFUSAL};
249#[path = "construction/sweep_topology.rs"]
250mod sweep_topology;
251pub(crate) use sweep_topology::is_sweep_tight_bend;
252pub use sweep_topology::{
253 extrude_profile_brep, extrude_profile_brep_draft, fit_helix_curve, helix_sample_points,
254 profile_anchor, rib_from_profile, sweep_bend_profile, sweep_closure, BendStation,
255 JointContinuity, PathJoint, SweepClosure,
256 RibExtrusion, RibNames, SweepPath, MAX_JOINT_TANGENT_BREAK, SWEEP_TIGHT_BEND_REFUSAL,
257 SWEEP_TWIST_CLOSURE_REFUSAL,
258 build_swept_envelope, recognize_swept_envelope, swept_envelope_volume, SweptEnvelope,
259 SWEEP_ENVELOPE_REFUSAL, sweep_envelope_bodies,
260 sweep_profile_along_chain, sweep_profile_along_chain_reported,
261 sweep_profile_along_chain_with_stations, sweep_profile_along_chain_with_stations_reported,
262 sweep_profile_along_path,
263 sweep_profile_along_path_anchored,
264 sweep_profile_helix,
265 sweep_profile_twisted, sweep_profile_twisted_anchored, sweep_profile_twisted_scaled,
266 ProfileAnchor, SectionPlacement,
267 StationBudget, SweepStationReport, SweptChain, SWEEP_DEFAULT_TOLERANCE, SWEEP_MAX_STATIONS,
268 SWEEP_REFINEMENT_ROUNDS,
269};
270#[path = "construction/revolve_topology.rs"]
271mod revolve_topology;
272pub use revolve_topology::{revolve_profile_brep, revolve_profile_brep_named};
273#[path = "construction/loft_topology.rs"]
274mod loft_topology;
275pub use loft_topology::{
276 loft_profile_brep, loft_profile_brep_closed, loft_profile_brep_guided,
277 loft_profile_brep_guided_frame, loft_profile_brep_tangent,
278};
279pub(crate) use loft_topology::loft_profile_brep_closed_shifted;
280#[path = "brep/transform_topology.rs"]
281mod transform_topology;
282#[path = "brep/recentre.rs"]
283mod recentre;
284pub use transform_topology::{mirror_brep, transform_brep, AffineTransform};
285#[path = "edit/split.rs"]
286mod split;
287pub use split::{
288 split_solid_by_face_surface, split_solid_by_plane, split_solid_by_surface, SplitSurface,
289};
290#[path = "props/mass_properties.rs"]
291mod mass_properties;
292pub use mass_properties::{
293 curve_arc_length, edge_arc_length, face_area, face_boundary_length, face_volume_contribution,
294 face_set_identity, mass_caller, parameter_space_area, solid_edge_length_total,
295 solid_mass_properties,
296 solid_mass_properties_full, signed_volume_against, solid_signed_volume, solid_signed_volume_for_sign, trim_polygons,
297 DensityMassProperties,
298 FaceSetIdentity, FullMassProperties, MassCaller, MassProperties, MassPropertiesCache,
299};
300#[path = "props/carrier_dimensions.rs"]
301mod carrier_dimensions;
302pub use carrier_dimensions::{curve_carrier_dimensions, surface_carrier_dimensions, CarrierDimensions};
303#[path = "meshing/tessellation.rs"]
304mod tessellation;
305pub use tessellation::{tessellate_brep, tessellate_face, TessellationOptions};
306#[path = "meshing/watertight_tessellation/mod.rs"]
307mod watertight_tessellation;
308pub use watertight_tessellation::{
309 sample_edge_polylines, sample_edges_encoded, tessellate_brep_watertight,
310 tessellate_brep_watertight_face_stride, tessellate_brep_watertight_face_stride_with_samples,
311};
312#[path = "feature_pipeline/mod.rs"]
317pub mod feature_pipeline;
318pub use feature_pipeline::execute_history_json;
319pub use feature_pipeline::{first_reference_name, reference_names};
320pub use feature_pipeline::face_transform_pivot;
324pub use feature_pipeline::{
327 clear_history_cache, execute_history, execute_history_observed, AddedSolid, Axis,
328 ComponentRecord, FeatureDescriptor, FeatureRefusal, FeatureResult, Frame, Fulfilment,
329 HistoryProgress, HistoryRequest, Rejected, RejectedKind,
330 HistoryResult, PortKind, PortRecord, ProfileLoop, ScenePoint, SketchProfile,
331};
332pub use feature_pipeline::wire_harness::{
336 bundle_diameter, Attachment as SplineAttachment, BundleStatus, PortSide, RouteResult,
337 RouteStatus,
338 WireHarnessBundle, WireHarnessConnection,
339 WireHarnessEndpoint, WireHarnessReport, WireHarnessState, BUNDLE_SOLID_PREFIX,
340 WIRE_HARNESS_FEATURE_ID, WIRE_HARNESS_FEATURE_TYPE,
341};
342pub use feature_pipeline::part_pins::{
347 declarations as declared_ports, declared_endpoints as declared_point_endpoints,
348 declared_points, endpoint_occurrence, follow_pin_edit, follow_point_edit, pin_labels,
349 pin_point_report, pins,
350 point_renames, port_group_for_unit, resolve_component_pin, resolve_part_pin,
351 unit_count as symbol_unit_count, unit_groups, DeclaredPin, DeclaredPoint, PinPoint,
352 PinPointChange, PinPointProblem, PinPointReport, PointRenames, DEFAULT_PORT_NAME,
353 DEFAULT_PORT_PURPOSE, PADS_BLOCK, SYMBOL_BLOCK,
354};
355pub use feature_pipeline::ports::{
360 address as port_address, document_is_boundary, seat_of as port_seat_of, seat_point,
361 seat_vector, seated_direction, split_address, unit_map, unseat_point, unseat_vector,
362 world_seat, PortDeclaration, PortPoint, PortPointRow, PortSeat, PortsReport, UnitProblem,
363 BOUNDARY_KEY, PORTS_BLOCK, PORTS_FEATURE_ID, PORTS_FEATURE_TYPE,
364};
365pub use feature_pipeline::pmi::{
369 balloon_head as pmi_balloon_head, clamp_text_size, format_dimension, format_number,
370 nearest_point_on_edge, nearest_point_on_solid, pmi_schema_catalogue, pmi_type,
371 nearest_displayed_point, nearest_displayed_point_on_edge, pose_apply as pmi_pose_apply, pose_unapply as pmi_pose_unapply,
372 resolve_state as pmi_resolve_state, entry_names_solid, baseline_hide_id, BalloonAnchor, BalloonAnchorMode, FcfFrame, HalfSpace as PmiHalfSpace, HeadScope as PmiHeadScope, PmiAnnotation,
373 PmiAnnotationReport, PmiCamera, PmiDisplay, PmiGeometry, PmiPlane, PmiPose, PmiProjection, PmiReport,
374 PmiState, PmiStatus, PmiTypeDef, PmiView, PmiViewReport, SolidPoses as PmiSolidPoses, ToleranceBlock, ToleranceMode, PMI_TYPES,
375};
376pub use feature_pipeline::pmi::layout::{present as pmi_present, LayoutStyle as PmiLayoutStyle, Presentation as PmiPresentation};
377pub use feature_pipeline::pmi::annotations::fcf::{characteristic as pmi_characteristic, Characteristic as PmiCharacteristic, CHARACTERISTICS as PMI_CHARACTERISTICS};
378pub use feature_pipeline::assign_sketch_loop_ids;
382pub use feature_pipeline::features::sketch3d::{
386 reference_record as sketch3d_reference_record, resolve_reference as resolve_sketch3d_reference,
387 ResolvedReference as Sketch3dResolvedReference, REFERENCE_TIP_LENGTH as SKETCH3D_REFERENCE_TIP_LENGTH,
388 common_edge_end as sketch3d_common_edge_end, curve_reference_controls as sketch3d_curve_reference_controls, REFERENCE_ANCHOR_EDGES_KEY as SKETCH3D_ANCHOR_EDGES_KEY,
389 SKETCH3D_DOC_KEY, SKETCH3D_EDIT_BUTTON, SKETCH3D_FEATURE_TYPE, SKETCH3D_REFERENCES_PARAM,
390 SKETCH3D_REFS_KEY,
391};
392pub use feature_pipeline::{flat_pattern_dxf, flat_pattern_svg, is_sheet_metal_handle};
394pub use feature_pipeline::{pattern_component_instance, pattern_parse_suppressed};
396pub use feature_pipeline::{native_import_payload, native_import_payload_with_appearance};
400pub use feature_pipeline::IsolatedSceneMetadata;
403pub use feature_pipeline::scene_metadata_colors_json;
406pub use feature_pipeline::family;
409pub use feature_pipeline::{
412 add_part_to_library, add_part_to_library_impl, install_parts_library, missing_library_parts,
413 parts_library_json, parts_library_map, parts_library_revision, refresh_library_entry,
414 refresh_library_entry_impl, same_build, follow_saved_rows, follow_saved_rows_known, kernel_source_stamp, stable_json_hash, PartsLibraryEntry, PartsLibraryMap,
415};
416pub use feature_pipeline::assembly::{
419 assembly_add_constraint_json, assembly_apply_document_json,
420 assembly_apply_inferred_constraints_json, assembly_component_entities_json, assembly_dof_json,
421 assembly_infer_constraints_json, assembly_inferable_types_json,
422 assembly_move_constraint_json, assembly_overlay_json, assembly_pose_updates_json,
423 assembly_drag_solve_json, assembly_frame_solve_json, assembly_remove_constraint_json, assembly_resolve_refs_json,
424 assembly_run_solve_json,
425 assembly_set_constraint_enabled_json, assembly_set_constraint_open_json,
426 assembly_state_json, assembly_statuses_json, assembly_update_constraint_json,
427 constraint_hidden_params, constraint_schema_catalogue,
428 assembly_add_constraint_impl, assembly_apply_document_impl, assembly_move_constraint_impl,
431 assembly_drag_solve_impl, assembly_frame_solve_impl, assembly_flip_plan_json, assembly_rebase_mechanical_impl, assembly_remove_constraint_impl, assembly_run_solve_impl,
432 assembly_set_constraint_enabled_impl, assembly_set_constraint_open_impl,
433 assembly_update_constraint_impl,
434 assembly_session_export, assembly_session_import, assembly_session_serial, RetiredSession, SessionTransfer,
435};
436pub use feature_pipeline::{AssemblyState, ConstraintEntry};
437pub use feature_pipeline::assembly::transform_to_pose_params;
440pub use feature_pipeline::feature_schema_catalogue;
443pub use feature_pipeline::feature_hidden_params;
446pub use feature_pipeline::assembly::{constraint_type, ConstraintTypeDef, CONSTRAINT_TYPES, FIXED_IS_NOT_A_CONSTRAINT};
449pub use feature_pipeline::{feature_context_applicable, SelectionProbe};
450pub use feature_pipeline::Env;
456
457pub fn eval_expression(
462 expressions: &str,
463 configurator_json: &serde_json::Value,
464 source: &str,
465) -> Result<f64, String> {
466 Env::build(expressions, configurator_json).and_then(|env| env.eval(source))
467}
468
469#[cfg(feature = "wasm-threads")]
476pub use wasm_bindgen_rayon::init_thread_pool;
477#[path = "geometry/projection.rs"]
478mod projection;
479#[path = "geometry/projection_profile.rs"]
480mod projection_profile;
481#[doc(hidden)]
482pub use projection_profile::report as projection_profile_report;
483#[path = "geometry/affine_sphere.rs"]
484mod affine_sphere;
485pub use projection::{
486 project_point_to_curve, project_point_to_surface, project_point_to_surface_seeded,
487 CurveProjection, SurfaceProjection,
488};
489#[doc(hidden)]
490pub use projection::{
491 project_point_to_surface_basin_census, project_point_to_surface_general_lanes, BasinCensus,
492 GlobalStats,
493};
494#[path = "intersect/curve_surface_intersection.rs"]
495mod curve_surface_intersection;
496pub use curve_surface_intersection::{intersect_curve_surface, CurveSurfaceIntersection};
497#[path = "intersect/exact_line_surface.rs"]
498mod exact_line_surface;
499#[path = "intersect/curve_curve_intersection.rs"]
500mod curve_curve_intersection;
501pub use curve_curve_intersection::{intersect_curves, CurveCurveIntersection};
502#[path = "intersect/surface_surface_intersection.rs"]
503mod surface_surface_intersection;
504pub use surface_surface_intersection::{
505 intersect_surfaces, intersect_surfaces_supplemental, SurfaceIntersectionCurve,
506 SurfaceIntersectionOptions,
507};
508pub(crate) use surface_surface_intersection::TRANSVERSE_SEED_CROSS;
509#[path = "intersect/tangent_curve.rs"]
510mod tangent_curve;
511#[path = "intersect/crossing_node.rs"]
512mod crossing_node;
513pub use crossing_node::{crossing_node_split_enabled, split_at_crossing_nodes};
514pub use tangent_curve::{
515 classify_tangent_contact_at, find_tangent_contact, trace_tangent_curve, TangentContact,
516 EXTENDED_RANK_FLOOR,
517};
518#[path = "brep/classification.rs"]
519mod classification;
520pub use classification::{
521 classify_point, containment_lane, horizon_cross_frame, parameter_point_in_face,
522 trim_sample_count, trim_station, ContainmentLane, PointClass, PointClassification,
523 PolygonClass, SolidClassifier, COVERING_RIM_STRIP_SWITCH, HORIZON_CONTAINMENT_SWITCH,
524 HORIZON_CROSS_FRAME_SWITCH, HORIZON_SINGLE_LOOP_SWITCH, NO_SPHERE_CHART_TRIM_SWITCH,
525 SEAM_BAND_MERGED_SWITCH,
526};
527#[doc(hidden)]
528pub use classification::parameter_point_in_face_scan;
529#[path = "geometry/spatial.rs"]
530mod spatial;
531pub use spatial::{Aabb, Bvh};
532#[path = "brep/pair_classification.rs"]
533mod pair_classification;
534pub use pair_classification::{
535 classify_surface_pair, classify_surface_pair_cached, SurfaceClassifyData,
536 SurfacePairClassification, SurfacePairRelation,
537};
538#[path = "intersect/arrangement.rs"]
539mod arrangement;
540pub use arrangement::{
541 arrange_segments, point_in_polygon, segment_intersection, ArrangementPiece, ArrangementRegion,
542 CycleUse, Segment2, Vec2,
543};
544#[path = "geometry/pcurve.rs"]
545mod pcurve;
546pub use pcurve::{
547 build_pcurve_on_surface, build_pcurve_on_surface_marched, build_pcurve_on_surface_range,
548 build_pcurve_on_surface_range_dense, build_pcurve_on_surface_stations, fit_pcurve_on_surface,
549 fit_pcurve_on_surface_marched, fit_pcurve_on_surface_range, fit_pcurve_on_surface_range_dense,
550 fit_pcurve_on_surface_stations, PcurveFit, PcurveFitExit, PcurveFitLedger, PcurveFitReport,
551 PcurveFitScope, PCURVE_OFF_BAR, PCURVE_REFINEMENT_TOLERANCE,
552};
553#[path = "csg/imprint.rs"]
554mod imprint;
555pub use imprint::{
556 build_imprints, EdgeSplitRecord, FaceImprints, FaceKey, FacePcurve, ImprintOptions,
557 ImprintPieceRecord, ImprintResultRecord, ImprintVertex, TangentSectionRecord,
558};
559#[path = "csg/feature_scale.rs"]
560mod feature_scale;
561#[path = "csg/edge_split.rs"]
562mod edge_split;
563pub use edge_split::{apply_edge_splits, apply_edge_splits_with_map};
564#[path = "csg/fragment.rs"]
565mod fragment;
566pub use fragment::{
567 fragment_face, fragment_solid, FaceFragmentRecord, FragmentCoedge, FragmentEdgeSource,
568 FragmentLoop, FragmentOrder,
569};
570#[path = "csg/boolean/mod.rs"]
571mod boolean;
572pub use boolean::{
573 boolean_operation, boolean_operation_nary, boolean_operation_nary_with_options, boolean_operation_with_diagnostics, boolean_operation_with_diagnostics_at_offset, boolean_split_operands,
574 BooleanOperation, BooleanOptions,
575};
576#[path = "csg/oracle.rs"]
577mod oracle;
578pub use oracle::{
579 boolean_residual_fusables, boolean_semantic_disagreement, boolean_semantic_disagreement_nary,
580 OracleReport, ResidualFusable, ResidualKind, SemanticDisagreement, DISAGREEMENT_THRESHOLD,
581};
582#[path = "healing/heal.rs"]
583mod heal;
584#[path = "healing/reading_memo.rs"]
587mod reading_memo;
588#[path = "healing/accept.rs"]
594mod accept;
595pub use accept::{
596 accept_sound, accept_sound_against, accept_sound_against_scoped, resolve_face_crossing, resolve_face_crossing_between,
597 take_crossing_repairs,
598 CrossingRepairRecord,
599};
600#[path = "offset/point.rs"]
605mod offset_point;
606pub use offset_point::{OffsetEvaluator, OffsetNormal, OffsetSample};
607#[path = "offset/analytic_pair.rs"]
614mod offset_analytic_pair;
615#[path = "offset/retrim.rs"]
622mod offset_retrim;
623#[path = "offset/reintersect.rs"]
631mod offset_reintersect;
632#[path = "offset/measure.rs"]
642mod offset_measure;
643pub use offset_measure::{
644 measure_edge_against_pcurve_image, measure_surface_fit_against_pointwise_offset,
645 span_midpoint_error, vertex_endpoint_gap,
646};
647#[path = "offset/offset.rs"]
648mod offset;
649pub use offset::{
650 offset_face_carrier, offset_face_carrier_measured, offset_face_carrier_sided, offset_surface,
651 offset_surface_measured, offset_surface_measured_sided, CarrierDeviation, CarrierExtension,
652 MeasuredOffsetSurface, OffsetFaceCarrier, OffsetSurfaceLane,
653};
654#[path = "offset/regularity.rs"]
660mod offset_regularity;
661#[path = "offset/fold_locus.rs"]
667mod offset_fold_locus;
668#[path = "offset/carve.rs"]
674mod offset_carve;
675#[path = "offset/thicken.rs"]
676mod thicken;
677pub use thicken::{thicken_face_sheet, thicken_trimmed_sheet};
678#[path = "healing/coalesce.rs"]
679mod coalesce;
680pub use coalesce::{concatenate_exact_curve_pieces, merge_curve_continuation_edges};
681#[path = "healing/face_merge.rs"]
682mod face_merge;
683#[allow(dead_code)]
686#[path = "healing/faceted_repair.rs"]
687mod faceted_repair;
688pub use face_merge::{merge_faces_within, merge_same_surface_faces, merge_same_surface_faces_excluding, merge_same_surface_faces_scoped};
689pub use faceted_repair::{mesh_to_faceted_brep, repair_triangle_soup, MeshRepairReport};
690#[path = "offset/offset_shell.rs"]
691mod offset_shell;
692pub use offset_shell::{
693 offset_shell, offset_shell_by_boolean, offset_shell_closed, offset_shell_with_diagnostics, offset_solid, OffsetCorners,
694 OffsetFaceRole, OffsetShellFaceImageRecord, OffsetShellResultRecord,
695};
696pub(crate) use offset_shell::{is_offset_shell_no_retained_face, is_offset_shell_open_curved_rim};
697#[path = "io/step_matrix.rs"]
698mod step_matrix;
699#[path = "io/step.rs"]
700mod step;
701pub use step::{
702 assembly_export_tree, audit_step_manifold, audit_step_pcurves, export_step,
703 export_step_assembly, export_step_assembly_report, export_step_report,
704 export_step_report_named, Mat4, StepAssemblyExport, StepColors, StepExportOccurrence,
705 StepExportProduct, StepExportReport, StepPmi, PART_ATTRIBUTES, PART_NUMBER,
706};
707#[path = "io/appearance.rs"]
711mod appearance;
712pub use appearance::{BodyAppearance, ImportedColor, COLOR_METADATA_KEY};
713#[path = "io/step_import/mod.rs"]
714mod step_import;
715pub use step_import::{
716 import_step, import_step_bodies, import_step_report, import_step_trim_readings, import_step_with_appearance,
717 occurrence_ref_parts, read_step_assembly, read_step_pmi, rewrite_occurrence_refs,
718 ImportedStep, StepAssembly, StepBodyError, StepBodyTrimReadings, StepEdgeReading, StepFaceReading, StepImportReport,
719 StepOccurrence, StepProduct, StepSuppliedTrim, StepTrimReadings, OCCURRENCE_REF_PREFIX,
720 STATED_PRECISION_INCONSISTENCY_RATIO,
721};
722#[doc(hidden)]
724pub fn io_step_text_for_tests(value: &str) -> String {
725 step::pmi::step_text(value)
726}
727#[doc(hidden)]
728pub fn io_step_decode_text_for_tests(value: &str) -> String {
729 step_import::decode_step_text_for_tests(value)
730}
731#[path = "io/iges/mod.rs"]
732mod iges;
733pub use iges::{
734 export_iges, export_iges_assembly, export_iges_bodies, import_iges, import_iges_report,
735 read_iges_assembly, IgesBody, IgesImportReport,
736};
737#[path = "io/mesh_io.rs"]
738mod mesh_io;
739pub use mesh_io::{
740 parse_stl_triangles, read_obj, read_stl, write_ascii_stl, write_binary_stl, write_obj,
741 ObjReadResult, StlError, StlFormat, StlReadResult, StlTriangles,
742};
743#[path = "io/three_mf/mod.rs"]
749mod three_mf;
750pub use three_mf::{
751 read_3mf, write_3mf, ThreeMfError, ThreeMfInstance, ThreeMfMesh, ThreeMfReadResult,
752 ThreeMfSolid, ThreeMfUnit, ThreeMfWriteReport,
753};
754#[path = "io/glb.rs"]
758mod glb;
759pub use glb::{write_glb, GlbReport, GlbSolid, GlbUpAxis, GLB_MAGIC};
760#[path = "io/snapshot.rs"]
764mod snapshot;
765pub use snapshot::{
766 restore_solids, snapshot_resident_solids, snapshot_solids, RestoredSnapshot, RestoredSolid,
767 SNAPSHOT_FORMAT_VERSION,
768};
769#[path = "solvers/linear_algebra.rs"]
770mod solver_linear_algebra;
771#[path = "solvers/sketch_solver.rs"]
772mod sketch_solver;
773pub use sketch_solver::{
774 is_sketch_origin_point_id, sketch_id_key, mint_sketch_id, solve_sketch, solve_sketch_from_json,
775 SketchSolverSettings, SolveSketchRequest, SKETCH_ORIGIN_POINT_ID,
776};
777#[path = "solvers/assembly_solver.rs"]
778mod assembly_solver;
779pub use assembly_solver::{
780 solve_assembly, AssemblyBody, AssemblyMate, AssemblySolution, AssemblySolveOptions, BodyFreedom, BodyPose,
781 LinearAlgebra, MateAlign, MateAxis, MateCurve, MateKind, MatePlane, MateResidualReport,
782 SolveStrategy, SymmetricElement,
783};
784#[path = "solvers/sketch3d_solver.rs"]
788mod sketch3d_solver;
789pub use sketch3d_solver::{
790 sketch3d_constraint_type, solve_sketch3d, solve_sketch3d_doc, solve_sketch3d_from_json,
791 Sketch3dConstraint, Sketch3dConstraintType, Sketch3dDiagnostics, Sketch3dDoc,
792 Sketch3dGeometry, Sketch3dPoint, Sketch3dSolveOptions, SolveSketch3dRequest,
793 SKETCH3D_CONSTRAINT_TYPES,
794};
795#[path = "solvers/assembly_resolve.rs"]
796mod assembly_resolve;
797pub use assembly_resolve::{
798 is_component_reference, resolve_component_point, resolve_edge_selection,
799 resolve_face_selection, resolve_named_selection, resolve_vertex_selection,
800 split_component_namespace, ResolveError, SelectionGeometry,
801};
802#[path = "edit/direct_edit.rs"]
803mod direct_edit;
804pub use direct_edit::{
805 delete_face_and_heal, delete_faces_and_heal, draft_faces, draft_faces_parted, move_faces, offset_freeform_face,
806 offset_revolution_face, offset_ruled_face, offset_sphere_face, offset_torus_face,
807 recut_moved_planes, recut_moved_planes_rigid, reblend_lost_fillets, resolve_face_by_point, rotate_faces,
808 route_reading, RouteReading,
809};
810pub use direct_edit::{face_refusal_slugs, face_transform_reason, FaceTransformReason};
811pub use direct_edit::{
812 refit_faces_as_one, refit_refusal_phrases, RefitCarrier, RefitReport, RefitSurfaceKind,
813};
814#[path = "healing/sew.rs"]
815mod sew;
816pub use sew::{sew_solid, split_pinched_vertices, SewReport};
817#[path = "meshing/mesh_weld.rs"]
818mod mesh_weld;
819pub use mesh_weld::{canonical_bits, VertexWeld};
820#[path = "meshing/mesh_segment.rs"]
821mod mesh_segment;
822pub use mesh_segment::{
823 mesh_regions_to_brep, segment_mesh_faces, MeshRegion, MeshSegmentation, RegionCarrier,
824 SegmentOptions, UNASSIGNED_REGION,
825};
826
827#[path = "meshing/spherical_union.rs"]
828mod spherical_union;
829pub use spherical_union::reconstruct_spherical_mesh_union;
830
831#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
832pub struct Vec3 {
833 pub x: f64,
834 pub y: f64,
835 pub z: f64,
836}
837
838impl Vec3 {
839 pub const ZERO: Self = Self { x: 0.0, y: 0.0, z: 0.0 };
840 pub const X: Self = Self { x: 1.0, y: 0.0, z: 0.0 };
841 pub const Y: Self = Self { x: 0.0, y: 1.0, z: 0.0 };
842 pub const Z: Self = Self { x: 0.0, y: 0.0, z: 1.0 };
843
844 pub fn normalized_or(self, fallback: Self) -> Self {
846 self.normalized().unwrap_or(fallback)
847 }
848
849 #[inline]
851 pub fn rotate_about(self, axis: Self, angle: f64) -> Self {
852 let (sin, cos) = angle.sin_cos();
853 self.scale(cos)
854 .add(axis.cross(self).scale(sin))
855 .add(axis.scale(axis.dot(self) * (1.0 - cos)))
856 }
857
858 #[inline]
860 pub fn distance_to_segment(self, start: Self, end: Self, guard: f64) -> f64 {
861 let segment = end.sub(start);
862 let length_squared = segment.dot(segment);
863 if length_squared <= guard {
864 return self.sub(start).length();
865 }
866 let parameter = (self.sub(start).dot(segment) / length_squared).clamp(0.0, 1.0);
867 self.sub(start.add(segment.scale(parameter))).length()
868 }
869
870 #[inline]
872 pub fn distance_to_segment_squared(self, start: Self, end: Self) -> f64 {
873 let segment = end.sub(start);
874 let length_squared = segment.dot(segment);
875 let parameter = if length_squared > 0.0 {
876 (self.sub(start).dot(segment) / length_squared).clamp(0.0, 1.0)
877 } else {
878 0.0
879 };
880 let residual = self.sub(start.add(segment.scale(parameter)));
881 residual.dot(residual)
882 }
883
884 pub fn new(x: f64, y: f64, z: f64) -> Self {
885 Self { x, y, z }
886 }
887 pub fn sub(self, rhs: Self) -> Self {
888 Self::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z)
889 }
890 pub fn add(self, rhs: Self) -> Self {
891 Self::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z)
892 }
893 pub fn scale(self, factor: f64) -> Self {
894 Self::new(self.x * factor, self.y * factor, self.z * factor)
895 }
896 pub fn cross(self, rhs: Self) -> Self {
897 Self::new(
898 self.y * rhs.z - self.z * rhs.y,
899 self.z * rhs.x - self.x * rhs.z,
900 self.x * rhs.y - self.y * rhs.x,
901 )
902 }
903 pub fn dot(self, rhs: Self) -> f64 {
904 self.x * rhs.x + self.y * rhs.y + self.z * rhs.z
905 }
906 pub fn length(self) -> f64 {
907 self.dot(self).sqrt()
908 }
909 pub fn length_squared(self) -> f64 {
910 self.dot(self)
911 }
912 pub fn normalized(self) -> Result<Self, String> {
913 let length = self.length();
914 if length <= 1e-12 {
915 return Err("Vec3.normalized: zero-length vector".into());
916 }
917 Ok(self.scale(1.0 / length))
918 }
919 pub fn perpendicular(self) -> Result<Self, String> {
920 let x = self.x.abs();
921 let y = self.y.abs();
922 let z = self.z.abs();
923 let axis = if x <= y && x <= z {
924 Self::new(1.0, 0.0, 0.0)
925 } else if y <= z {
926 Self::new(0.0, 1.0, 0.0)
927 } else {
928 Self::new(0.0, 0.0, 1.0)
929 };
930 self.cross(axis).normalized()
931 }
932}
933
934#[derive(Clone, Debug, Default, Deserialize, Serialize)]
935pub struct Mesh {
936 pub positions: Vec<f64>,
937 pub normals: Vec<f64>,
938 pub indices: Vec<u32>,
939 pub face_ids: Vec<u32>,
940}
941
942impl Mesh {
943 fn push_vertex(&mut self, point: Vec3, normal: Vec3) -> u32 {
944 self.positions.extend([point.x, point.y, point.z]);
945 self.normals.extend([normal.x, normal.y, normal.z]);
946 (self.positions.len() / 3 - 1) as u32
947 }
948
949 fn quad(&mut self, points: [Vec3; 4], normal: Vec3, face_id: u32) {
950 let base = self.push_vertex(points[0], normal);
951 for point in points.iter().skip(1) {
952 self.push_vertex(*point, normal);
953 }
954 self.indices
955 .extend([base, base + 1, base + 2, base, base + 2, base + 3]);
956 self.face_ids.extend([face_id, face_id]);
957 }
958
959 pub fn signed_volume(&self) -> f64 {
960 self.indices
961 .chunks_exact(3)
962 .map(|tri| {
963 let point = |index: u32| {
964 let i = index as usize * 3;
965 Vec3::new(
966 self.positions[i],
967 self.positions[i + 1],
968 self.positions[i + 2],
969 )
970 };
971 point(tri[0]).dot(point(tri[1]).cross(point(tri[2]))) / 6.0
972 })
973 .sum()
974 }
975
976 pub fn validate(&self) -> Result<(), String> {
977 if self.positions.len() % 3 != 0 || self.normals.len() != self.positions.len() {
978 return Err("invalid vertex or normal buffer".into());
979 }
980 self.validate_geometry()
981 }
982
983 pub fn validate_geometry(&self) -> Result<(), String> {
988 if self.positions.len() % 3 != 0 {
989 return Err("invalid vertex buffer".into());
990 }
991 if self.indices.len() % 3 != 0 {
992 return Err("index buffer is not triangular".into());
993 }
994 let count = self.positions.len() / 3;
995 if self.indices.iter().any(|index| *index as usize >= count) {
996 return Err("index outside vertex buffer".into());
997 }
998 if !self.positions.iter().all(|value| value.is_finite()) {
999 return Err("non-finite vertex".into());
1000 }
1001 Ok(())
1002 }
1003}
1004
1005pub fn make_box(size_x: f64, size_y: f64, size_z: f64) -> Mesh {
1006 let x = size_x.abs();
1007 let y = size_y.abs();
1008 let z = size_z.abs();
1009 let p = [
1010 Vec3::new(0.0, 0.0, 0.0),
1011 Vec3::new(x, 0.0, 0.0),
1012 Vec3::new(x, y, 0.0),
1013 Vec3::new(0.0, y, 0.0),
1014 Vec3::new(0.0, 0.0, z),
1015 Vec3::new(x, 0.0, z),
1016 Vec3::new(x, y, z),
1017 Vec3::new(0.0, y, z),
1018 ];
1019 let mut mesh = Mesh::default();
1020 mesh.quad([p[0], p[3], p[2], p[1]], Vec3::new(0.0, 0.0, -1.0), 0);
1021 mesh.quad([p[4], p[5], p[6], p[7]], Vec3::new(0.0, 0.0, 1.0), 1);
1022 mesh.quad([p[0], p[1], p[5], p[4]], Vec3::new(0.0, -1.0, 0.0), 2);
1023 mesh.quad([p[3], p[7], p[6], p[2]], Vec3::new(0.0, 1.0, 0.0), 3);
1024 mesh.quad([p[0], p[4], p[7], p[3]], Vec3::new(-1.0, 0.0, 0.0), 4);
1025 mesh.quad([p[1], p[2], p[6], p[5]], Vec3::new(1.0, 0.0, 0.0), 5);
1026 mesh
1027}
1028
1029pub fn make_cylinder(radius: f64, height: f64, segments: usize) -> Mesh {
1030 let radius = radius.abs();
1031 let height = height.abs();
1032 let segments = segments.max(3);
1033 let mut mesh = Mesh::default();
1034 for i in 0..segments {
1035 let a = std::f64::consts::TAU * i as f64 / segments as f64;
1036 let b = std::f64::consts::TAU * (i + 1) as f64 / segments as f64;
1037 let (sa, ca) = a.sin_cos();
1038 let (sb, cb) = b.sin_cos();
1039 let pa = Vec3::new(radius * ca, 0.0, -radius * sa);
1040 let pb = Vec3::new(radius * cb, 0.0, -radius * sb);
1041 let ta = Vec3::new(pa.x, height, pa.z);
1042 let tb = Vec3::new(pb.x, height, pb.z);
1043 mesh.quad(
1044 [pa, pb, tb, ta],
1045 Vec3::new((ca + cb) * 0.5, 0.0, -(sa + sb) * 0.5),
1046 0,
1047 );
1048 let bottom = mesh.push_vertex(Vec3::default(), Vec3::new(0.0, -1.0, 0.0));
1049 let bi = mesh.push_vertex(pb, Vec3::new(0.0, -1.0, 0.0));
1050 let bj = mesh.push_vertex(pa, Vec3::new(0.0, -1.0, 0.0));
1051 mesh.indices.extend([bottom, bi, bj]);
1052 mesh.face_ids.push(1);
1053 let top = mesh.push_vertex(Vec3::new(0.0, height, 0.0), Vec3::new(0.0, 1.0, 0.0));
1054 let ti = mesh.push_vertex(ta, Vec3::new(0.0, 1.0, 0.0));
1055 let tj = mesh.push_vertex(tb, Vec3::new(0.0, 1.0, 0.0));
1056 mesh.indices.extend([top, ti, tj]);
1057 mesh.face_ids.push(2);
1058 }
1059 mesh
1060}
1061
1062
1063mod abi;
1064pub use abi::*;
1065
1066
1067#[path = "healing/curve_helpers.rs"]
1068mod curve_helpers;
1069
1070#[path = "geometry/eigen2.rs"]
1071mod eigen2;
1072
1073#[path = "geometry/union_find.rs"]
1074pub mod union_find;
1075pub use union_find::UnionFind;
1076
1077#[path = "geometry/poly.rs"]
1078pub mod poly;
1079
1080pub use analytic_surface::{circumcenter, circumcenter_2d, recognize_circle, RecognizedCircle};
1081
1082#[path = "geometry/triangle.rs"]
1083mod triangle;
1084pub use triangle::closest_point_on_triangle;
1085
1086pub use tolerance::RIGID_TOL;
1087
1088impl std::ops::Index<usize> for Vec3 {
1089 type Output = f64;
1090 fn index(&self, index: usize) -> &Self::Output {
1091 match index { 0 => &self.x, 1 => &self.y, 2 => &self.z, _ => panic!("Vec3 index out of bounds: {index}") }
1092 }
1093}
1094impl std::ops::IndexMut<usize> for Vec3 {
1095 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1096 match index { 0 => &mut self.x, 1 => &mut self.y, 2 => &mut self.z, _ => panic!("Vec3 index out of bounds: {index}") }
1097 }
1098}