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/sweep_topology.rs"]
242mod sweep_topology;
243pub(crate) use sweep_topology::is_sweep_tight_bend;
244pub use sweep_topology::{
245 extrude_profile_brep, extrude_profile_brep_draft, fit_helix_curve, helix_sample_points,
246 profile_anchor, rib_from_profile, sweep_bend_profile, sweep_closure, BendStation,
247 JointContinuity, PathJoint, SweepClosure,
248 RibExtrusion, RibNames, SweepPath, MAX_JOINT_TANGENT_BREAK, SWEEP_TIGHT_BEND_REFUSAL,
249 SWEEP_TWIST_CLOSURE_REFUSAL,
250 build_swept_envelope, recognize_swept_envelope, swept_envelope_volume, SweptEnvelope,
251 SWEEP_ENVELOPE_REFUSAL, sweep_envelope_bodies,
252 sweep_profile_along_chain, sweep_profile_along_chain_reported,
253 sweep_profile_along_chain_with_stations, sweep_profile_along_chain_with_stations_reported,
254 sweep_profile_along_path,
255 sweep_profile_along_path_anchored,
256 sweep_profile_helix,
257 sweep_profile_twisted, sweep_profile_twisted_anchored, ProfileAnchor, SectionPlacement,
258 StationBudget, SweepStationReport, SweptChain, SWEEP_DEFAULT_TOLERANCE, SWEEP_MAX_STATIONS,
259 SWEEP_REFINEMENT_ROUNDS,
260};
261#[path = "construction/revolve_topology.rs"]
262mod revolve_topology;
263pub use revolve_topology::{revolve_profile_brep, revolve_profile_brep_named};
264#[path = "construction/loft_topology.rs"]
265mod loft_topology;
266pub use loft_topology::{
267 loft_profile_brep, loft_profile_brep_closed, loft_profile_brep_guided,
268 loft_profile_brep_guided_frame, loft_profile_brep_tangent,
269};
270pub(crate) use loft_topology::loft_profile_brep_closed_shifted;
271#[path = "brep/transform_topology.rs"]
272mod transform_topology;
273#[path = "brep/recentre.rs"]
274mod recentre;
275pub use transform_topology::{mirror_brep, transform_brep, AffineTransform};
276#[path = "edit/split.rs"]
277mod split;
278pub use split::{
279 split_solid_by_face_surface, split_solid_by_plane, split_solid_by_surface, SplitSurface,
280};
281#[path = "props/mass_properties.rs"]
282mod mass_properties;
283pub use mass_properties::{
284 curve_arc_length, edge_arc_length, face_area, face_boundary_length, face_volume_contribution,
285 face_set_identity, mass_caller, parameter_space_area, solid_edge_length_total,
286 solid_mass_properties,
287 solid_mass_properties_full, signed_volume_against, solid_signed_volume, solid_signed_volume_for_sign, trim_polygons,
288 DensityMassProperties,
289 FaceSetIdentity, FullMassProperties, MassCaller, MassProperties, MassPropertiesCache,
290};
291#[path = "props/carrier_dimensions.rs"]
292mod carrier_dimensions;
293pub use carrier_dimensions::{curve_carrier_dimensions, surface_carrier_dimensions, CarrierDimensions};
294#[path = "meshing/tessellation.rs"]
295mod tessellation;
296pub use tessellation::{tessellate_brep, tessellate_face, TessellationOptions};
297#[path = "meshing/watertight_tessellation/mod.rs"]
298mod watertight_tessellation;
299pub use watertight_tessellation::{
300 sample_edge_polylines, sample_edges_encoded, tessellate_brep_watertight,
301 tessellate_brep_watertight_face_stride, tessellate_brep_watertight_face_stride_with_samples,
302};
303#[path = "feature_pipeline/mod.rs"]
308pub mod feature_pipeline;
309pub use feature_pipeline::execute_history_json;
310pub use feature_pipeline::{first_reference_name, reference_names};
311pub use feature_pipeline::face_transform_pivot;
315pub use feature_pipeline::{
318 clear_history_cache, execute_history, execute_history_observed, AddedSolid, Axis,
319 ComponentRecord, FeatureDescriptor, FeatureRefusal, FeatureResult, Frame, Fulfilment,
320 HistoryProgress, HistoryRequest, Rejected, RejectedKind,
321 HistoryResult, PortKind, PortRecord, ProfileLoop, ScenePoint, SketchProfile,
322};
323pub use feature_pipeline::wire_harness::{
327 bundle_diameter, Attachment as SplineAttachment, BundleStatus, PortSide, RouteResult,
328 RouteStatus,
329 WireHarnessBundle, WireHarnessConnection,
330 WireHarnessEndpoint, WireHarnessReport, WireHarnessState, BUNDLE_SOLID_PREFIX,
331 WIRE_HARNESS_FEATURE_ID, WIRE_HARNESS_FEATURE_TYPE,
332};
333pub use feature_pipeline::part_pins::{
338 declarations as declared_ports, declared_endpoints as declared_point_endpoints,
339 declared_points, endpoint_occurrence, follow_pin_edit, follow_point_edit, pin_labels,
340 pin_point_report, pins,
341 point_renames, port_group_for_unit, resolve_component_pin, resolve_part_pin,
342 unit_count as symbol_unit_count, unit_groups, DeclaredPin, DeclaredPoint, PinPoint,
343 PinPointChange, PinPointProblem, PinPointReport, PointRenames, DEFAULT_PORT_NAME,
344 DEFAULT_PORT_PURPOSE, PADS_BLOCK, SYMBOL_BLOCK,
345};
346pub use feature_pipeline::ports::{
351 address as port_address, document_is_boundary, seat_of as port_seat_of, seat_point,
352 seat_vector, seated_direction, split_address, unit_map, unseat_point, unseat_vector,
353 world_seat, PortDeclaration, PortPoint, PortPointRow, PortSeat, PortsReport, UnitProblem,
354 BOUNDARY_KEY, PORTS_BLOCK, PORTS_FEATURE_ID, PORTS_FEATURE_TYPE,
355};
356pub use feature_pipeline::pmi::{
360 balloon_head as pmi_balloon_head, clamp_text_size, format_dimension, format_number,
361 nearest_point_on_edge, nearest_point_on_solid, pmi_schema_catalogue, pmi_type,
362 nearest_displayed_point, nearest_displayed_point_on_edge, pose_apply as pmi_pose_apply, pose_unapply as pmi_pose_unapply,
363 resolve_state as pmi_resolve_state, entry_names_solid, baseline_hide_id, BalloonAnchor, BalloonAnchorMode, FcfFrame, HalfSpace as PmiHalfSpace, HeadScope as PmiHeadScope, PmiAnnotation,
364 PmiAnnotationReport, PmiCamera, PmiDisplay, PmiGeometry, PmiPlane, PmiPose, PmiProjection, PmiReport,
365 PmiState, PmiStatus, PmiTypeDef, PmiView, PmiViewReport, SolidPoses as PmiSolidPoses, ToleranceBlock, ToleranceMode, PMI_TYPES,
366};
367pub use feature_pipeline::pmi::layout::{present as pmi_present, LayoutStyle as PmiLayoutStyle, Presentation as PmiPresentation};
368pub use feature_pipeline::pmi::annotations::fcf::{characteristic as pmi_characteristic, Characteristic as PmiCharacteristic, CHARACTERISTICS as PMI_CHARACTERISTICS};
369pub use feature_pipeline::assign_sketch_loop_ids;
373pub use feature_pipeline::features::sketch3d::{
377 reference_record as sketch3d_reference_record, resolve_reference as resolve_sketch3d_reference,
378 ResolvedReference as Sketch3dResolvedReference, REFERENCE_TIP_LENGTH as SKETCH3D_REFERENCE_TIP_LENGTH,
379 SKETCH3D_DOC_KEY, SKETCH3D_EDIT_BUTTON, SKETCH3D_FEATURE_TYPE, SKETCH3D_REFERENCES_PARAM,
380 SKETCH3D_REFS_KEY,
381};
382pub use feature_pipeline::{flat_pattern_dxf, flat_pattern_svg, is_sheet_metal_handle};
384pub use feature_pipeline::{pattern_component_instance, pattern_parse_suppressed};
386pub use feature_pipeline::{native_import_payload, native_import_payload_with_appearance};
390pub use feature_pipeline::IsolatedSceneMetadata;
393pub use feature_pipeline::scene_metadata_colors_json;
396pub use feature_pipeline::family;
399pub use feature_pipeline::{
402 add_part_to_library, add_part_to_library_impl, install_parts_library, missing_library_parts,
403 parts_library_json, parts_library_map, parts_library_revision, refresh_library_entry,
404 refresh_library_entry_impl, same_build, follow_saved_rows, follow_saved_rows_known, kernel_source_stamp, stable_json_hash, PartsLibraryEntry, PartsLibraryMap,
405};
406pub use feature_pipeline::assembly::{
409 assembly_add_constraint_json, assembly_apply_document_json,
410 assembly_apply_inferred_constraints_json, assembly_component_entities_json, assembly_dof_json,
411 assembly_infer_constraints_json, assembly_inferable_types_json,
412 assembly_move_constraint_json, assembly_overlay_json, assembly_pose_updates_json,
413 assembly_drag_solve_json, assembly_frame_solve_json, assembly_remove_constraint_json, assembly_resolve_refs_json,
414 assembly_run_solve_json,
415 assembly_set_constraint_enabled_json, assembly_set_constraint_open_json,
416 assembly_state_json, assembly_statuses_json, assembly_update_constraint_json,
417 constraint_hidden_params, constraint_schema_catalogue,
418 assembly_add_constraint_impl, assembly_apply_document_impl, assembly_move_constraint_impl,
421 assembly_drag_solve_impl, assembly_frame_solve_impl, assembly_flip_plan_json, assembly_rebase_mechanical_impl, assembly_remove_constraint_impl, assembly_run_solve_impl,
422 assembly_set_constraint_enabled_impl, assembly_set_constraint_open_impl,
423 assembly_update_constraint_impl,
424 assembly_session_export, assembly_session_import, assembly_session_serial, RetiredSession, SessionTransfer,
425};
426pub use feature_pipeline::{AssemblyState, ConstraintEntry};
427pub use feature_pipeline::assembly::transform_to_pose_params;
430pub use feature_pipeline::feature_schema_catalogue;
433pub use feature_pipeline::feature_hidden_params;
436pub use feature_pipeline::assembly::{constraint_type, ConstraintTypeDef, CONSTRAINT_TYPES, FIXED_IS_NOT_A_CONSTRAINT};
439pub use feature_pipeline::{feature_context_applicable, SelectionProbe};
440pub use feature_pipeline::Env;
446
447pub fn eval_expression(
452 expressions: &str,
453 configurator_json: &serde_json::Value,
454 source: &str,
455) -> Result<f64, String> {
456 Env::build(expressions, configurator_json).and_then(|env| env.eval(source))
457}
458
459#[cfg(feature = "wasm-threads")]
466pub use wasm_bindgen_rayon::init_thread_pool;
467#[path = "geometry/projection.rs"]
468mod projection;
469#[path = "geometry/projection_profile.rs"]
470mod projection_profile;
471#[doc(hidden)]
472pub use projection_profile::report as projection_profile_report;
473#[path = "geometry/affine_sphere.rs"]
474mod affine_sphere;
475pub use projection::{
476 project_point_to_curve, project_point_to_surface, project_point_to_surface_seeded,
477 CurveProjection, SurfaceProjection,
478};
479#[doc(hidden)]
480pub use projection::{
481 project_point_to_surface_basin_census, project_point_to_surface_general_lanes, BasinCensus,
482 GlobalStats,
483};
484#[path = "intersect/curve_surface_intersection.rs"]
485mod curve_surface_intersection;
486pub use curve_surface_intersection::{intersect_curve_surface, CurveSurfaceIntersection};
487#[path = "intersect/exact_line_surface.rs"]
488mod exact_line_surface;
489#[path = "intersect/curve_curve_intersection.rs"]
490mod curve_curve_intersection;
491pub use curve_curve_intersection::{intersect_curves, CurveCurveIntersection};
492#[path = "intersect/surface_surface_intersection.rs"]
493mod surface_surface_intersection;
494pub use surface_surface_intersection::{
495 intersect_surfaces, intersect_surfaces_supplemental, SurfaceIntersectionCurve,
496 SurfaceIntersectionOptions,
497};
498pub(crate) use surface_surface_intersection::TRANSVERSE_SEED_CROSS;
499#[path = "intersect/tangent_curve.rs"]
500mod tangent_curve;
501pub use tangent_curve::{
502 classify_tangent_contact_at, find_tangent_contact, trace_tangent_curve, TangentContact,
503 EXTENDED_RANK_FLOOR,
504};
505#[path = "brep/classification.rs"]
506mod classification;
507pub use classification::{
508 classify_point, containment_lane, horizon_cross_frame, parameter_point_in_face,
509 trim_sample_count, trim_station, ContainmentLane, PointClass, PointClassification,
510 PolygonClass, SolidClassifier, COVERING_RIM_STRIP_SWITCH, HORIZON_CONTAINMENT_SWITCH,
511 HORIZON_CROSS_FRAME_SWITCH, HORIZON_SINGLE_LOOP_SWITCH, NO_SPHERE_CHART_TRIM_SWITCH,
512 SEAM_BAND_MERGED_SWITCH,
513};
514#[doc(hidden)]
515pub use classification::parameter_point_in_face_scan;
516#[path = "geometry/spatial.rs"]
517mod spatial;
518pub use spatial::{Aabb, Bvh};
519#[path = "brep/pair_classification.rs"]
520mod pair_classification;
521pub use pair_classification::{
522 classify_surface_pair, classify_surface_pair_cached, SurfaceClassifyData,
523 SurfacePairClassification, SurfacePairRelation,
524};
525#[path = "intersect/arrangement.rs"]
526mod arrangement;
527pub use arrangement::{
528 arrange_segments, point_in_polygon, segment_intersection, ArrangementPiece, ArrangementRegion,
529 CycleUse, Segment2, Vec2,
530};
531#[path = "geometry/pcurve.rs"]
532mod pcurve;
533pub use pcurve::{
534 build_pcurve_on_surface, build_pcurve_on_surface_marched, build_pcurve_on_surface_range,
535 build_pcurve_on_surface_range_dense, build_pcurve_on_surface_stations, fit_pcurve_on_surface,
536 fit_pcurve_on_surface_marched, fit_pcurve_on_surface_range, fit_pcurve_on_surface_range_dense,
537 fit_pcurve_on_surface_stations, PcurveFit, PcurveFitExit, PcurveFitLedger, PcurveFitReport,
538 PcurveFitScope, PCURVE_OFF_BAR, PCURVE_REFINEMENT_TOLERANCE,
539};
540#[path = "csg/imprint.rs"]
541mod imprint;
542pub use imprint::{
543 build_imprints, EdgeSplitRecord, FaceImprints, FaceKey, FacePcurve, ImprintOptions,
544 ImprintPieceRecord, ImprintResultRecord, ImprintVertex, TangentSectionRecord,
545};
546#[path = "csg/edge_split.rs"]
547mod edge_split;
548pub use edge_split::{apply_edge_splits, apply_edge_splits_with_map};
549#[path = "csg/fragment.rs"]
550mod fragment;
551pub use fragment::{
552 fragment_face, fragment_solid, FaceFragmentRecord, FragmentCoedge, FragmentEdgeSource,
553 FragmentLoop, FragmentOrder,
554};
555#[path = "csg/boolean/mod.rs"]
556mod boolean;
557pub use boolean::{
558 boolean_operation, boolean_operation_nary, boolean_operation_nary_with_options, boolean_operation_with_diagnostics, boolean_operation_with_diagnostics_at_offset, boolean_split_operands,
559 BooleanOperation, BooleanOptions,
560};
561#[path = "csg/oracle.rs"]
562mod oracle;
563pub use oracle::{
564 boolean_residual_fusables, boolean_semantic_disagreement, boolean_semantic_disagreement_nary,
565 OracleReport, ResidualFusable, ResidualKind, SemanticDisagreement, DISAGREEMENT_THRESHOLD,
566};
567#[path = "healing/heal.rs"]
568mod heal;
569#[path = "healing/reading_memo.rs"]
572mod reading_memo;
573#[path = "healing/accept.rs"]
579mod accept;
580pub use accept::{
581 accept_sound, accept_sound_against, accept_sound_against_scoped, resolve_face_crossing, resolve_face_crossing_between,
582 take_crossing_repairs,
583 CrossingRepairRecord,
584};
585#[path = "offset/point.rs"]
590mod offset_point;
591pub use offset_point::{OffsetEvaluator, OffsetNormal, OffsetSample};
592#[path = "offset/analytic_pair.rs"]
599mod offset_analytic_pair;
600#[path = "offset/retrim.rs"]
607mod offset_retrim;
608#[path = "offset/reintersect.rs"]
616mod offset_reintersect;
617#[path = "offset/measure.rs"]
627mod offset_measure;
628pub use offset_measure::{
629 measure_edge_against_pcurve_image, measure_surface_fit_against_pointwise_offset,
630 span_midpoint_error, vertex_endpoint_gap,
631};
632#[path = "offset/offset.rs"]
633mod offset;
634pub use offset::{
635 offset_face_carrier, offset_face_carrier_measured, offset_face_carrier_sided, offset_surface,
636 offset_surface_measured, offset_surface_measured_sided, CarrierDeviation, CarrierExtension,
637 MeasuredOffsetSurface, OffsetFaceCarrier, OffsetSurfaceLane,
638};
639#[path = "offset/regularity.rs"]
645mod offset_regularity;
646#[path = "offset/fold_locus.rs"]
652mod offset_fold_locus;
653#[path = "offset/carve.rs"]
659mod offset_carve;
660#[path = "offset/thicken.rs"]
661mod thicken;
662pub use thicken::{thicken_face_sheet, thicken_trimmed_sheet};
663#[path = "healing/coalesce.rs"]
664mod coalesce;
665pub use coalesce::{concatenate_exact_curve_pieces, merge_curve_continuation_edges};
666#[path = "healing/face_merge.rs"]
667mod face_merge;
668#[allow(dead_code)]
671#[path = "healing/faceted_repair.rs"]
672mod faceted_repair;
673pub use face_merge::{merge_faces_within, merge_same_surface_faces, merge_same_surface_faces_excluding, merge_same_surface_faces_scoped};
674pub use faceted_repair::{mesh_to_faceted_brep, repair_triangle_soup, MeshRepairReport};
675#[path = "offset/offset_shell.rs"]
676mod offset_shell;
677pub use offset_shell::{
678 offset_shell, offset_shell_by_boolean, offset_shell_closed, offset_shell_with_diagnostics, offset_solid, OffsetCorners,
679 OffsetFaceRole, OffsetShellFaceImageRecord, OffsetShellResultRecord,
680};
681pub(crate) use offset_shell::{is_offset_shell_no_retained_face, is_offset_shell_open_curved_rim};
682#[path = "io/step_matrix.rs"]
683mod step_matrix;
684#[path = "io/step.rs"]
685mod step;
686pub use step::{
687 assembly_export_tree, audit_step_manifold, audit_step_pcurves, export_step,
688 export_step_assembly, export_step_assembly_report, export_step_report,
689 export_step_report_named, Mat4, StepAssemblyExport, StepColors, StepExportOccurrence,
690 StepExportProduct, StepExportReport, StepPmi, PART_ATTRIBUTES, PART_NUMBER,
691};
692#[path = "io/appearance.rs"]
696mod appearance;
697pub use appearance::{BodyAppearance, ImportedColor, COLOR_METADATA_KEY};
698#[path = "io/step_import/mod.rs"]
699mod step_import;
700pub use step_import::{
701 import_step, import_step_bodies, import_step_report, import_step_trim_readings, import_step_with_appearance,
702 occurrence_ref_parts, read_step_assembly, read_step_pmi, rewrite_occurrence_refs,
703 ImportedStep, StepAssembly, StepBodyError, StepBodyTrimReadings, StepEdgeReading, StepFaceReading, StepImportReport,
704 StepOccurrence, StepProduct, StepSuppliedTrim, StepTrimReadings, OCCURRENCE_REF_PREFIX,
705 STATED_PRECISION_INCONSISTENCY_RATIO,
706};
707#[doc(hidden)]
709pub fn io_step_text_for_tests(value: &str) -> String {
710 step::pmi::step_text(value)
711}
712#[doc(hidden)]
713pub fn io_step_decode_text_for_tests(value: &str) -> String {
714 step_import::decode_step_text_for_tests(value)
715}
716#[path = "io/iges/mod.rs"]
717mod iges;
718pub use iges::{export_iges, import_iges};
719#[path = "io/mesh_io.rs"]
720mod mesh_io;
721pub use mesh_io::{
722 parse_stl_triangles, read_obj, read_stl, write_ascii_stl, write_binary_stl, write_obj,
723 ObjReadResult, StlError, StlFormat, StlReadResult, StlTriangles,
724};
725#[path = "io/three_mf/mod.rs"]
731mod three_mf;
732pub use three_mf::{
733 read_3mf, write_3mf, ThreeMfError, ThreeMfInstance, ThreeMfMesh, ThreeMfReadResult,
734 ThreeMfSolid, ThreeMfUnit, ThreeMfWriteReport,
735};
736#[path = "io/glb.rs"]
740mod glb;
741pub use glb::{write_glb, GlbReport, GlbSolid, GlbUpAxis, GLB_MAGIC};
742#[path = "io/snapshot.rs"]
746mod snapshot;
747pub use snapshot::{
748 restore_solids, snapshot_resident_solids, snapshot_solids, RestoredSnapshot, RestoredSolid,
749 SNAPSHOT_FORMAT_VERSION,
750};
751#[path = "solvers/linear_algebra.rs"]
752mod solver_linear_algebra;
753#[path = "solvers/sketch_solver.rs"]
754mod sketch_solver;
755pub use sketch_solver::{
756 is_sketch_origin_point_id, sketch_id_key, mint_sketch_id, solve_sketch, solve_sketch_from_json,
757 SketchSolverSettings, SolveSketchRequest, SKETCH_ORIGIN_POINT_ID,
758};
759#[path = "solvers/assembly_solver.rs"]
760mod assembly_solver;
761pub use assembly_solver::{
762 solve_assembly, AssemblyBody, AssemblyMate, AssemblySolution, AssemblySolveOptions, BodyFreedom, BodyPose,
763 LinearAlgebra, MateAlign, MateAxis, MateCurve, MateKind, MatePlane, MateResidualReport,
764 SolveStrategy, SymmetricElement,
765};
766#[path = "solvers/sketch3d_solver.rs"]
770mod sketch3d_solver;
771pub use sketch3d_solver::{
772 sketch3d_constraint_type, solve_sketch3d, solve_sketch3d_doc, solve_sketch3d_from_json,
773 Sketch3dConstraint, Sketch3dConstraintType, Sketch3dDiagnostics, Sketch3dDoc,
774 Sketch3dGeometry, Sketch3dPoint, Sketch3dSolveOptions, SolveSketch3dRequest,
775 SKETCH3D_CONSTRAINT_TYPES,
776};
777#[path = "solvers/assembly_resolve.rs"]
778mod assembly_resolve;
779pub use assembly_resolve::{
780 is_component_reference, resolve_component_point, resolve_edge_selection,
781 resolve_face_selection, resolve_named_selection, resolve_vertex_selection,
782 split_component_namespace, ResolveError, SelectionGeometry,
783};
784#[path = "edit/direct_edit.rs"]
785mod direct_edit;
786pub use direct_edit::{
787 delete_face_and_heal, delete_faces_and_heal, draft_faces, draft_faces_parted, move_faces, offset_freeform_face,
788 offset_revolution_face, offset_ruled_face, offset_sphere_face, offset_torus_face,
789 recut_moved_planes, recut_moved_planes_rigid, resolve_face_by_point, rotate_faces,
790 route_reading, RouteReading,
791};
792pub use direct_edit::{face_refusal_slugs, face_transform_reason, FaceTransformReason};
793pub use direct_edit::{
794 refit_faces_as_one, refit_refusal_phrases, RefitCarrier, RefitReport, RefitSurfaceKind,
795};
796#[path = "healing/sew.rs"]
797mod sew;
798pub use sew::{sew_solid, split_pinched_vertices, SewReport};
799#[path = "meshing/mesh_weld.rs"]
800mod mesh_weld;
801pub use mesh_weld::{canonical_bits, VertexWeld};
802#[path = "meshing/mesh_segment.rs"]
803mod mesh_segment;
804pub use mesh_segment::{
805 mesh_regions_to_brep, segment_mesh_faces, MeshRegion, MeshSegmentation, RegionCarrier,
806 SegmentOptions, UNASSIGNED_REGION,
807};
808
809#[path = "meshing/spherical_union.rs"]
810mod spherical_union;
811pub use spherical_union::reconstruct_spherical_mesh_union;
812
813#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
814pub struct Vec3 {
815 pub x: f64,
816 pub y: f64,
817 pub z: f64,
818}
819
820impl Vec3 {
821 pub const ZERO: Self = Self { x: 0.0, y: 0.0, z: 0.0 };
822 pub const X: Self = Self { x: 1.0, y: 0.0, z: 0.0 };
823 pub const Y: Self = Self { x: 0.0, y: 1.0, z: 0.0 };
824 pub const Z: Self = Self { x: 0.0, y: 0.0, z: 1.0 };
825
826 pub fn normalized_or(self, fallback: Self) -> Self {
828 self.normalized().unwrap_or(fallback)
829 }
830
831 #[inline]
833 pub fn rotate_about(self, axis: Self, angle: f64) -> Self {
834 let (sin, cos) = angle.sin_cos();
835 self.scale(cos)
836 .add(axis.cross(self).scale(sin))
837 .add(axis.scale(axis.dot(self) * (1.0 - cos)))
838 }
839
840 #[inline]
842 pub fn distance_to_segment(self, start: Self, end: Self, guard: f64) -> f64 {
843 let segment = end.sub(start);
844 let length_squared = segment.dot(segment);
845 if length_squared <= guard {
846 return self.sub(start).length();
847 }
848 let parameter = (self.sub(start).dot(segment) / length_squared).clamp(0.0, 1.0);
849 self.sub(start.add(segment.scale(parameter))).length()
850 }
851
852 #[inline]
854 pub fn distance_to_segment_squared(self, start: Self, end: Self) -> f64 {
855 let segment = end.sub(start);
856 let length_squared = segment.dot(segment);
857 let parameter = if length_squared > 0.0 {
858 (self.sub(start).dot(segment) / length_squared).clamp(0.0, 1.0)
859 } else {
860 0.0
861 };
862 let residual = self.sub(start.add(segment.scale(parameter)));
863 residual.dot(residual)
864 }
865
866 pub fn new(x: f64, y: f64, z: f64) -> Self {
867 Self { x, y, z }
868 }
869 pub fn sub(self, rhs: Self) -> Self {
870 Self::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z)
871 }
872 pub fn add(self, rhs: Self) -> Self {
873 Self::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z)
874 }
875 pub fn scale(self, factor: f64) -> Self {
876 Self::new(self.x * factor, self.y * factor, self.z * factor)
877 }
878 pub fn cross(self, rhs: Self) -> Self {
879 Self::new(
880 self.y * rhs.z - self.z * rhs.y,
881 self.z * rhs.x - self.x * rhs.z,
882 self.x * rhs.y - self.y * rhs.x,
883 )
884 }
885 pub fn dot(self, rhs: Self) -> f64 {
886 self.x * rhs.x + self.y * rhs.y + self.z * rhs.z
887 }
888 pub fn length(self) -> f64 {
889 self.dot(self).sqrt()
890 }
891 pub fn length_squared(self) -> f64 {
892 self.dot(self)
893 }
894 pub fn normalized(self) -> Result<Self, String> {
895 let length = self.length();
896 if length <= 1e-12 {
897 return Err("Vec3.normalized: zero-length vector".into());
898 }
899 Ok(self.scale(1.0 / length))
900 }
901 pub fn perpendicular(self) -> Result<Self, String> {
902 let x = self.x.abs();
903 let y = self.y.abs();
904 let z = self.z.abs();
905 let axis = if x <= y && x <= z {
906 Self::new(1.0, 0.0, 0.0)
907 } else if y <= z {
908 Self::new(0.0, 1.0, 0.0)
909 } else {
910 Self::new(0.0, 0.0, 1.0)
911 };
912 self.cross(axis).normalized()
913 }
914}
915
916#[derive(Clone, Debug, Default, Deserialize, Serialize)]
917pub struct Mesh {
918 pub positions: Vec<f64>,
919 pub normals: Vec<f64>,
920 pub indices: Vec<u32>,
921 pub face_ids: Vec<u32>,
922}
923
924impl Mesh {
925 fn push_vertex(&mut self, point: Vec3, normal: Vec3) -> u32 {
926 self.positions.extend([point.x, point.y, point.z]);
927 self.normals.extend([normal.x, normal.y, normal.z]);
928 (self.positions.len() / 3 - 1) as u32
929 }
930
931 fn quad(&mut self, points: [Vec3; 4], normal: Vec3, face_id: u32) {
932 let base = self.push_vertex(points[0], normal);
933 for point in points.iter().skip(1) {
934 self.push_vertex(*point, normal);
935 }
936 self.indices
937 .extend([base, base + 1, base + 2, base, base + 2, base + 3]);
938 self.face_ids.extend([face_id, face_id]);
939 }
940
941 pub fn signed_volume(&self) -> f64 {
942 self.indices
943 .chunks_exact(3)
944 .map(|tri| {
945 let point = |index: u32| {
946 let i = index as usize * 3;
947 Vec3::new(
948 self.positions[i],
949 self.positions[i + 1],
950 self.positions[i + 2],
951 )
952 };
953 point(tri[0]).dot(point(tri[1]).cross(point(tri[2]))) / 6.0
954 })
955 .sum()
956 }
957
958 pub fn validate(&self) -> Result<(), String> {
959 if self.positions.len() % 3 != 0 || self.normals.len() != self.positions.len() {
960 return Err("invalid vertex or normal buffer".into());
961 }
962 self.validate_geometry()
963 }
964
965 pub fn validate_geometry(&self) -> Result<(), String> {
970 if self.positions.len() % 3 != 0 {
971 return Err("invalid vertex buffer".into());
972 }
973 if self.indices.len() % 3 != 0 {
974 return Err("index buffer is not triangular".into());
975 }
976 let count = self.positions.len() / 3;
977 if self.indices.iter().any(|index| *index as usize >= count) {
978 return Err("index outside vertex buffer".into());
979 }
980 if !self.positions.iter().all(|value| value.is_finite()) {
981 return Err("non-finite vertex".into());
982 }
983 Ok(())
984 }
985}
986
987pub fn make_box(size_x: f64, size_y: f64, size_z: f64) -> Mesh {
988 let x = size_x.abs();
989 let y = size_y.abs();
990 let z = size_z.abs();
991 let p = [
992 Vec3::new(0.0, 0.0, 0.0),
993 Vec3::new(x, 0.0, 0.0),
994 Vec3::new(x, y, 0.0),
995 Vec3::new(0.0, y, 0.0),
996 Vec3::new(0.0, 0.0, z),
997 Vec3::new(x, 0.0, z),
998 Vec3::new(x, y, z),
999 Vec3::new(0.0, y, z),
1000 ];
1001 let mut mesh = Mesh::default();
1002 mesh.quad([p[0], p[3], p[2], p[1]], Vec3::new(0.0, 0.0, -1.0), 0);
1003 mesh.quad([p[4], p[5], p[6], p[7]], Vec3::new(0.0, 0.0, 1.0), 1);
1004 mesh.quad([p[0], p[1], p[5], p[4]], Vec3::new(0.0, -1.0, 0.0), 2);
1005 mesh.quad([p[3], p[7], p[6], p[2]], Vec3::new(0.0, 1.0, 0.0), 3);
1006 mesh.quad([p[0], p[4], p[7], p[3]], Vec3::new(-1.0, 0.0, 0.0), 4);
1007 mesh.quad([p[1], p[2], p[6], p[5]], Vec3::new(1.0, 0.0, 0.0), 5);
1008 mesh
1009}
1010
1011pub fn make_cylinder(radius: f64, height: f64, segments: usize) -> Mesh {
1012 let radius = radius.abs();
1013 let height = height.abs();
1014 let segments = segments.max(3);
1015 let mut mesh = Mesh::default();
1016 for i in 0..segments {
1017 let a = std::f64::consts::TAU * i as f64 / segments as f64;
1018 let b = std::f64::consts::TAU * (i + 1) as f64 / segments as f64;
1019 let (sa, ca) = a.sin_cos();
1020 let (sb, cb) = b.sin_cos();
1021 let pa = Vec3::new(radius * ca, 0.0, -radius * sa);
1022 let pb = Vec3::new(radius * cb, 0.0, -radius * sb);
1023 let ta = Vec3::new(pa.x, height, pa.z);
1024 let tb = Vec3::new(pb.x, height, pb.z);
1025 mesh.quad(
1026 [pa, pb, tb, ta],
1027 Vec3::new((ca + cb) * 0.5, 0.0, -(sa + sb) * 0.5),
1028 0,
1029 );
1030 let bottom = mesh.push_vertex(Vec3::default(), Vec3::new(0.0, -1.0, 0.0));
1031 let bi = mesh.push_vertex(pb, Vec3::new(0.0, -1.0, 0.0));
1032 let bj = mesh.push_vertex(pa, Vec3::new(0.0, -1.0, 0.0));
1033 mesh.indices.extend([bottom, bi, bj]);
1034 mesh.face_ids.push(1);
1035 let top = mesh.push_vertex(Vec3::new(0.0, height, 0.0), Vec3::new(0.0, 1.0, 0.0));
1036 let ti = mesh.push_vertex(ta, Vec3::new(0.0, 1.0, 0.0));
1037 let tj = mesh.push_vertex(tb, Vec3::new(0.0, 1.0, 0.0));
1038 mesh.indices.extend([top, ti, tj]);
1039 mesh.face_ids.push(2);
1040 }
1041 mesh
1042}
1043
1044
1045mod abi;
1046pub use abi::*;
1047
1048
1049#[path = "healing/curve_helpers.rs"]
1050mod curve_helpers;
1051
1052#[path = "geometry/eigen2.rs"]
1053mod eigen2;
1054
1055#[path = "geometry/union_find.rs"]
1056pub mod union_find;
1057pub use union_find::UnionFind;
1058
1059#[path = "geometry/poly.rs"]
1060pub mod poly;
1061
1062pub use analytic_surface::{circumcenter, circumcenter_2d, recognize_circle, RecognizedCircle};
1063
1064#[path = "geometry/triangle.rs"]
1065mod triangle;
1066pub use triangle::closest_point_on_triangle;
1067
1068pub use tolerance::RIGID_TOL;
1069
1070impl std::ops::Index<usize> for Vec3 {
1071 type Output = f64;
1072 fn index(&self, index: usize) -> &Self::Output {
1073 match index { 0 => &self.x, 1 => &self.y, 2 => &self.z, _ => panic!("Vec3 index out of bounds: {index}") }
1074 }
1075}
1076impl std::ops::IndexMut<usize> for Vec3 {
1077 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1078 match index { 0 => &mut self.x, 1 => &mut self.y, 2 => &mut self.z, _ => panic!("Vec3 index out of bounds: {index}") }
1079 }
1080}