Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
# Cadrs CAD SDK API Documentation


This document provides detailed API documentation for the Cadrs CAD SDK.

## Core Modules


### Data Structure Module


The data_structure module provides the foundational data types and structures for CAD document management.

#### Document


```rust
pub struct Document {
    layers: LayerManager,
    blocks: BlockManager,
    entities: EntityContainer,
    current_layer: Option<LayerId>,
}
```

**Methods:**

- `new() -> Document` - Creates a new empty document
- `add_entity<E: Into<Entity>>(&mut self, entity: E) -> Result<EntityId, CadrsError>` - Adds an entity to the document
- `remove_entity(&mut self, id: EntityId) -> Result<(), CadrsError>` - Removes an entity from the document
- `get_entity(&self, id: EntityId) -> Option<&Entity>` - Retrieves an entity by ID
- `get_entity_mut(&mut self, id: EntityId) -> Option<&mut Entity>` - Retrieves a mutable reference to an entity
- `set_current_layer(&mut self, layer: &str) -> Result<(), CadrsError>` - Sets the active layer
- `get_current_layer(&self) -> Option<&Layer>` - Returns the current active layer
- `add_layer(&mut self, layer: Layer) -> Result<LayerId, CadrsError>` - Adds a new layer
- `add_block(&mut self, block: Block) -> Result<BlockId, CadrsError>` - Adds a new block definition

#### Entity


```rust
pub struct Entity {
    id: EntityId,
    layer: LayerId,
    visibility: Visibility,
    line_type: Option<LineTypeId>,
    properties: EntityProperties,
}
```

**Methods:**

- `id(&self) -> EntityId` - Returns the unique entity identifier
- `layer(&self) -> LayerId` - Returns the layer ID
- `set_layer(&mut self, layer: LayerId)` - Sets the entity layer
- `visibility(&self) -> Visibility` - Returns the visibility status
- `set_visibility(&mut self, visibility: Visibility)` - Sets the visibility
- `transform(&mut self, transform: &Transformation2D)` - Applies a 2D transformation
- `bounds(&self) -> Option<BoundingBox>` - Returns the bounding box

#### EntityId


```rust
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

pub struct EntityId(u64);
```

**Methods:**

- `new() -> Self` - Creates a new unique ID
- `as_u64(&self) -> u64` - Returns the raw u64 value

#### Layer


```rust
pub struct Layer {
    name: String,
    color: Color,
    visibility: Visibility,
    line_type: Option<LineTypeId>,
    plot_style: Option<PlotStyleId>,
    is_locked: bool,
    is_frozen: bool,
}
```

**Methods:**

- `new(name: &str) -> Self` - Creates a new layer with the given name
- `name(&self) -> &str` - Returns the layer name
- `color(&self) -> Color` - Returns the layer color
- `set_color(&mut self, color: Color)` - Sets the layer color
- `is_locked(&self) -> bool` - Checks if the layer is locked
- `set_locked(&mut self, locked: bool)` - Sets the locked state

#### Block


```rust
pub struct Block {
    name: String,
    entities: Vec<Entity>,
    origin: Point,
    attributes: Vec<BlockAttribute>,
}
```

**Methods:**

- `new(name: &str) -> Self` - Creates a new block
- `name(&self) -> &str` - Returns the block name
- `add_entity<E: Into<Entity>>(&mut self, entity: E)` - Adds an entity to the block
- `origin(&self) -> Point` - Returns the block origin
- `set_origin(&mut self, origin: Point)` - Sets the block origin
- `count(&self) -> usize` - Returns the number of entities

#### Selection


```rust
pub struct Selection {
    selected: BTreeSet<EntityId>,
    highlighted: BTreeSet<EntityId>,
}
```

**Methods:**

- `new() -> Self` - Creates an empty selection
- `select(&mut self, id: EntityId)` - Adds an entity to selection
- `deselect(&mut self, id: EntityId)` - Removes an entity from selection
- `clear(&mut self)` - Clears all selections
- `is_selected(&self, id: EntityId) -> bool` - Checks if an entity is selected
- `selected_ids(&self) -> &BTreeSet<EntityId>` - Returns all selected IDs
- `toggle(&mut self, id: EntityId)` - Toggles selection state

#### EventSystem


```rust
pub struct EventSystem {
    listeners: HashMap<EventType, Vec<Box<dyn EventListener>>>,
}
```

**Methods:**

- `new() -> Self` - Creates a new event system
- `subscribe<E: Event>(&mut self, event_type: E::EventType, listener: impl EventListener)` - Registers an event listener
- `publish<E: Event>(&self, event: E)` - Publishes an event to all listeners
- `unsubscribe(&mut self, listener_id: ListenerId)` - Removes a listener

### Geometry Module


The geometry module provides fundamental geometric primitives and operations.

#### Point


```rust
#[derive(Debug, Clone, Copy, PartialEq)]

pub struct Point {
    x: f64,
    y: f64,
}
```

**Methods:**

- `new(x: f64, y: f64) -> Self` - Creates a new point
- `origin() -> Self` - Returns the origin point (0, 0)
- `x(&self) -> f64` - Returns the x coordinate
- `y(&self) -> f64` - Returns the y coordinate
- `distance_to(&self, other: Point) -> f64` - Calculates distance to another point
- `midpoint(&self, other: Point) -> Point` - Returns the midpoint
- `lerp(&self, other: Point, t: f64) -> Point` - Linear interpolation
- `rotate(&self, angle: f64, center: Point) -> Point` - Rotates around a center point
- `transform(&self, transform: &Transformation2D) -> Point` - Applies a transformation
- `polar(&self, radius: f64, angle: f64) -> Point` - Creates a point from polar coordinates

#### Vector2D


```rust
#[derive(Debug, Clone, Copy, PartialEq)]

pub struct Vector2D {
    x: f64,
    y: f64,
}
```

**Methods:**

- `new(x: f64, y: f64) -> Self` - Creates a new vector
- `zero() -> Self` - Returns the zero vector
- `from_points(from: Point, to: Point) -> Self` - Creates a vector from two points
- `length(&self) -> f64` - Returns the vector magnitude
- `normalize(&self) -> Option<Self>` - Returns a unit vector
- `dot(&self, other: Vector2D) -> f64` - Dot product
- `cross(&self, other: Vector2D) -> f64` - Cross product (2D, returns scalar)
- `angle(&self) -> f64` - Returns the angle in radians
- `perpendicular(&self) -> Self` - Returns a perpendicular vector
- `rotate(&self, angle: f64) -> Self` - Rotates the vector

#### Line


```rust
pub struct Line {
    start: Point,
    end: Point,
}
```

**Methods:**

- `new(start: Point, end: Point) -> Self` - Creates a new line segment
- `start(&self) -> Point` - Returns the start point
- `end(&self) -> Point` - Returns the end point
- `length(&self) -> f64` - Returns the line length
- `direction(&self) -> Vector2D` - Returns the direction vector
- `midpoint(&self) -> Point` - Returns the midpoint
- `is_point_on(&self, point: Point) -> bool` - Checks if a point lies on the line
- `closest_point(&self, point: Point) -> Point` - Finds the closest point on the line
- `distance_to(&self, point: Point) -> f64` - Returns the distance to a point
- `intersection(&self, other: &Line) -> Option<Point>` - Finds intersection with another line

#### Arc


```rust
pub struct Arc {
    center: Point,
    radius: f64,
    start_angle: f64,
    end_angle: f64,
    is_counter_clockwise: bool,
}
```

**Methods:**

- `new(center: Point, radius: f64, start_angle: f64, end_angle: f64) -> Self` - Creates an arc
- `center(&self) -> Point` - Returns the center point
- `radius(&self) -> f64` - Returns the radius
- `start_angle(&self) -> f64` - Returns the start angle in radians
- `end_angle(&self) -> f64` - Returns the end angle in radians
- `length(&self) -> f64` - Calculates the arc length
- `sweep_angle(&self) -> f64` - Returns the sweep angle in radians
- `start_point(&self) -> Point` - Returns the start point
- `end_point(&self) -> Point` - Returns the end point
- `point_at_angle(&self, angle: f64) -> Point` - Returns the point at a given angle
- `is_counter_clockwise(&self) -> bool` - Checks if arc is drawn CCW
- `set_counter_clockwise(&mut self, ccw: bool)` - Sets the drawing direction

#### Circle


```rust
pub struct Circle {
    center: Point,
    radius: f64,
}
```

**Methods:**

- `new(center: Point, radius: f64) -> Self` - Creates a new circle
- `center(&self) -> Point` - Returns the center point
- `radius(&self) -> f64` - Returns the radius
- `diameter(&self) -> f64` - Returns the diameter
- `area(&self) -> f64` - Returns the area
- `circumference(&self) -> f64` - Returns the circumference
- `point_at_angle(&self, angle: f64) -> Point` - Returns a point on the circumference
- `is_point_inside(&self, point: Point) -> bool` - Checks if a point is inside

#### Ellipse


```rust
pub struct Ellipse {
    center: Point,
    major_axis: Vector2D,
    minor_radius: f64,
    start_parameter: f64,
    end_parameter: f64,
}
```

**Methods:**

- `new(center: Point, major_axis: Vector2D, minor_radius: f64) -> Self` - Creates an ellipse
- `center(&self) -> Point` - Returns the center
- `major_axis(&self) -> &Vector2D` - Returns the major axis vector
- `minor_radius(&self) -> f64` - Returns the minor radius
- `major_radius(&self) -> f64` - Returns the major radius
- `eccentricity(&self) -> f64` - Calculates the eccentricity
- `point_at_parameter(&self, param: f64) -> Point` - Returns a point at parameter value

#### Polyline


```rust
pub struct Polyline {
    vertices: Vec<PolylineVertex>,
    is_closed: bool,
}
```

**Methods:**

- `new() -> Self` - Creates an empty open polyline
- `new_closed() -> Self` - Creates a closed polyline
- `add_vertex(&mut self, vertex: PolylineVertex)` - Adds a vertex
- `add_point(&mut self, point: Point)` - Adds a point vertex
- `add_arc(&mut self, point: Point, bulge: f64)` - Adds an arc vertex with bulge factor
- `is_closed(&self) -> bool` - Checks if polyline is closed
- `set_closed(&mut self, closed: bool)` - Sets the closed state
- `vertices(&self) -> &[PolylineVertex]` - Returns all vertices
- `total_length(&self) -> f64` - Calculates the total length
- `explode(&self) -> Vec<Line>` - Converts to line segments

#### BSpline


```rust
pub struct BSpline {
    control_points: Vec<Point>,
    degree: usize,
    knot_vector: Vec<f64>,
    is_rational: bool,
    weights: Option<Vec<f64>>,
}
```

**Methods:**

- `new(control_points: Vec<Point>, degree: usize) -> Result<Self, BSplineError>` - Creates a B-spline
- `control_points(&self) -> &[Point]` - Returns control points
- `degree(&self) -> usize` - Returns the degree
- `knot_vector(&self) -> &[f64]` - Returns the knot vector
- `evaluate(&self, t: f64) -> Point` - Evaluates the curve at parameter t
- `derivative(&self, t: f64) -> Vector2D` - Returns the first derivative
- `greville_abscissae(&self) -> Vec<f64>` - Returns Greville abscissae for interpolation
- `insert_knot(&mut self, t: f64, multiplicity: usize) -> Result<(), BSplineError>` - Inserts a knot
- `elevate_degree(&mut self, amount: usize)` - Elevates the degree

#### Curve


```rust
pub trait Curve {
    fn start_point(&self) -> Point;
    fn end_point(&self) -> Point;
    fn point_at(&self, t: f64) -> Point;
    fn tangent_at(&self, t: f64) -> Vector2D;
    fn length(&self, tolerance: f64) -> f64;
    fn parameter_from_point(&self, point: Point, tolerance: f64) -> Option<f64>;
}
```

Implementations: `Line`, `Arc`, `Circle`, `Ellipse`, `Polyline`, `BSpline`, `NURBS`

#### Intersection


```rust
pub struct Intersection {
    pub points: Vec<Point>,
    pub parameters: Vec<f64>,
    pub is_tangent: bool,
}
```

**Functions:**

- `line_line(line1: &Line, line2: &Line) -> Option<Intersection>` - Intersects two lines
- `line_circle(line: &Line, circle: &Circle) -> Intersection` - Intersects line and circle
- `circle_circle(circle1: &Circle, circle2: &Circle) -> Intersection` - Intersects two circles
- `line_arc(line: &Line, arc: &Arc) -> Intersection` - Intersects line and arc
- `arc_arc(arc1: &Arc, arc2: &Arc) -> Intersection` - Intersects two arcs

### Math Module


The math module provides mathematical utilities for CAD operations.

#### Matrix3x3


```rust
pub struct Matrix3x3 {
    data: [[f64; 3]; 3],
}
```

**Methods:**

- `identity() -> Self` - Creates the identity matrix
- `zero() -> Self` - Creates a zero matrix
- `new(data: [[f64; 3]; 3]) -> Self` - Creates from array
- `rotation(angle: f64) -> Self` - Creates a rotation matrix
- `translation(dx: f64, dy: f64) -> Self` - Creates a translation matrix
- `scale(sx: f64, sy: f64) -> Self` - Creates a scaling matrix
- `determinant(&self) -> f64` - Calculates the determinant
- `inverse(&self) -> Option<Self>` - Calculates the inverse matrix
- `multiply(&self, other: &Self) -> Self` - Matrix multiplication
- `transform_point(&self, point: Point) -> Point` - Transforms a point

#### Transformation2D


```rust
pub struct Transformation2D {
    matrix: Matrix3x3,
}
```

**Methods:**

- `identity() -> Self` - Creates an identity transformation
- `translation(dx: f64, dy: f64) -> Self` - Creates a translation
- `rotation(angle: f64) -> Self` - Creates a rotation about origin
- `rotation_about(angle: f64, center: Point) -> Self` - Rotation about a point
- `scale(sx: f64, sy: f64) -> Self` - Creates a scaling transformation
- `scale_uniform(s: f64) -> Self` - Uniform scaling
- `compose(&self, other: &Self) -> Self` - Composes two transformations
- `inverse(&self) -> Option<Self>` - Calculates the inverse
- `apply(&self, point: Point) -> Point` - Applies transformation to a point

### Command Module


The command module provides a command pattern implementation for CAD operations.

#### Command


```rust
pub trait Command {
    fn execute(&mut self, context: &mut CommandContext) -> Result<CommandResult, CadrsError>;
    fn undo(&mut self, context: &mut CommandContext) -> Result<CommandResult, CadrsError>;
    fn redo(&mut self, context: &mut CommandContext) -> Result<CommandResult, CadrsError>;
    fn name(&self) -> &str;
    fn is_reversible(&self) -> bool;
}
```

#### CommandManager


```rust
pub struct CommandManager {
    history: CommandHistory,
    current_command: Option<Box<dyn Command>>,
    context: CommandContext,
}
```

**Methods:**

- `new(document: Weak<Document>) -> Self` - Creates a new command manager
- `execute(&mut self, command: impl Command) -> Result<(), CadrsError>` - Executes a command
- `undo(&mut self) -> Result<(), CadrsError>` - Undoes the last command
- `redo(&mut self) -> Result<(), CadrsError>` - Redoes the last undone command
- `is_undoable(&self) -> bool` - Checks if undo is available
- `is_redoable(&self) -> bool` - Checks if redo is available
- `clear_history(&mut self)` - Clears command history
- `current_command_name(&self) -> Option<&str>` - Returns the current command name

#### CommandHistory


```rust
pub struct CommandHistory {
    undo_stack: Vec<Box<dyn Command>>,
    redo_stack: Vec<Box<dyn Command>>,
    max_history_size: usize,
}
```

**Methods:**

- `new(max_size: usize) -> Self` - Creates history with maximum size
- `push(&mut self, command: Box<dyn Command>)` - Adds a command to history
- `undo(&mut self) -> Option<Box<dyn Command>>` - Pops the last command for undo
- `redo(&mut self) -> Option<Box<dyn Command>>` - Pops the last undone command
- `can_undo(&self) -> bool` - Checks if undo is available
- `can_redo(&self) -> bool` - Checks if redo is available
- `clear(&mut self)` - Clears all history

### Render Module


The render module provides rendering capabilities for CAD entities.

#### Renderer


```rust
pub trait Renderer {
    fn initialize(&mut self) -> Result<(), RenderError>;
    fn begin_frame(&mut self) -> Result<(), RenderError>;
    fn end_frame(&mut self) -> Result<(), RenderError>;
    fn draw_entity(&mut self, entity: &Entity) -> Result<(), RenderError>;
    fn set_viewport(&mut self, viewport: &Viewport) -> Result<(), RenderError>;
    fn clear(&mut self, color: Color) -> Result<(), RenderError>;
}
```

Implementations: `SoftwareRenderer`, `GPURenderer`, `SVGRenderer`

#### Viewport


```rust
pub struct Viewport {
    origin: Point,
    size: Size,
    zoom: f64,
    rotation: f64,
    view_matrix: Matrix3x3,
}
```

**Methods:**

- `new(origin: Point, size: Size) -> Self` - Creates a new viewport
- `set_origin(&mut self, origin: Point)` - Sets the viewport origin
- `set_size(&mut self, size: Size)` - Sets the viewport size
- `zoom(&self) -> f64` - Returns the zoom level
- `set_zoom(&mut self, zoom: f64)` - Sets the zoom level
- `zoom_extents(&mut self, bounding_box: BoundingBox)` - Zooms to fit a bounding box
- `world_to_screen(&self, point: Point) -> Point` - Converts world coordinates to screen
- `screen_to_world(&self, point: Point) -> Point` - Converts screen coordinates to world

#### SVGRenderer


```rust
pub struct SVGRenderer {
    svg: SVGDocument,
}
```

**Methods:**

- `new() -> Self` - Creates a new SVG renderer
- `set_size(&mut self, width: f64, height: f64)` - Sets the SVG dimensions
- `add_layer(&mut self, name: &str, color: Color)` - Adds a layer
- `add_entity(&mut self, entity: &Entity) -> Result<(), RenderError>` - Adds an entity
- `add_text(&mut self, text: &Text) -> Result<(), RenderError>` - Adds text
- `add_dimension(&mut self, dimension: &Dimension) -> Result<(), RenderError>` - Adds a dimension
- `save(&self, path: &Path) -> Result<(), std::io::Error>` - Saves to file
- `to_string(&self) -> String` - Returns the SVG as a string

### I/O Module


The I/O module provides file import and export capabilities.

#### Exporter


```rust
pub trait Exporter {
    fn export(&self, document: &Document, stream: &mut dyn Write) -> Result<(), IoError>;
    fn extension(&self) -> &str;
    fn format_name(&self) -> &str;
}
```

Implementations: `DXFExporter`, `IGESExporter`, `STEPExporter`, `SVGExporter`

#### Importer


```rust
pub trait Importer {
    fn import_document(&self, stream: &mut dyn Read) -> Result<Document, IoError>;
    fn extension(&self) -> &str;
    fn format_name(&self) -> &str;
    fn can_import(&self) -> bool;
}
```

Implementations: `DXFImporter`, `IGESImporter`, `STEPImporter`, `SVGImporter`

#### DXFExporter


```rust
pub struct DXFExporter;
```

**Methods:**

- `new() -> Self` - Creates a new DXF exporter
- `export(&self, document: &Document, stream: &mut dyn Write) -> Result<(), IoError>` - Exports to DXF format

#### DXFImporter


```rust
pub struct DXFImporter;
```

**Methods:**

- `new() -> Self` - Creates a new DXF importer
- `import_document(&self, stream: &mut dyn Read) -> Result<Document, IoError>` - Imports from DXF format

### Constraint Module


The constraint module provides geometric constraint solving capabilities.

#### ConstraintSolver


```rust
pub struct ConstraintSolver {
    variables: Vec<Variable>,
    constraints: Vec<Box<dyn Constraint>>,
    solver: Box<dyn SolverAlgorithm>,
}
```

**Methods:**

- `new() -> Self` - Creates a new constraint solver
- `add_variable(&mut self, name: &str, initial_value: f64) -> VariableId` - Adds a variable
- `add_constraint(&mut self, constraint: impl Constraint) -> Result<ConstraintId, ConstraintError>` - Adds a constraint
- `remove_constraint(&mut self, id: ConstraintId) -> Result<(), ConstraintError>` - Removes a constraint
- `solve(&mut self) -> Result<SolveResult, SolverError>` - Solves the constraint system
- `set_variable_value(&mut self, id: VariableId, value: f64)` - Sets a variable value
- `get_variable_value(&self, id: VariableId) -> f64` - Gets a variable value
- `add_equality(&mut self, expr1: &Expression, expr2: &Expression) -> Result<ConstraintId, ConstraintError>` - Adds equality constraint

### Dimension Module


The dimension module provides dimension annotation functionality.

#### Dimension


```rust
pub trait Dimension {
    fn dimension_type(&self) -> DimensionType;
    fn measurement(&self) -> f64;
    fn text(&self) -> &str;
    fn set_text(&mut self, text: &str);
    fn update_measurement(&mut self);
}
```

Implementations: `LinearDimension`, `AngularDimension`, `RadialDimension`, `OrdinateDimension`

#### LinearDimension


```rust
pub struct LinearDimension {
    attachment_point: AttachmentPoint,
    dimension_line_location: Point,
    text_position: Point,
    measurement: f64,
    text: String,
    tolerance: Option<Tolerance>,
}
```

**Methods:**

- `new(attachment: AttachmentPoint, location: Point) -> Self` - Creates a linear dimension
- `attachment_point(&self) -> AttachmentPoint` - Returns the attachment point
- `dimension_line_location(&self) -> Point` - Returns the dimension line location
- `set_text_position(&mut self, pos: Point)` - Sets the text position
- `measurement(&self) -> f64` - Returns the measurement value
- `tolerance(&self) -> Option<&Tolerance>` - Returns the tolerance

#### AngularDimension


```rust
pub struct AngularDimension {
    center: Point,
    start_line: Line,
    end_line: Line,
    arc_radius: f64,
    text_position: Point,
    measurement: f64,
    text: String,
}
```

**Methods:**

- `new(center: Point, start_line: Line, end_line: Line) -> Self` - Creates an angular dimension
- `center(&self) -> Point` - Returns the center point
- `arc_radius(&self) -> f64` - Returns the arc radius
- `measurement(&self) -> f64` - Returns the angle in degrees

#### RadialDimension


```rust
pub struct RadialDimension {
    center: Point,
    arc: Arc,
    text_position: Point,
    leader_length: f64,
}
```

**Methods:**

- `new(center: Point, arc: Arc) -> Self` - Creates a radial dimension
- `center(&self) -> Point` - Returns the center point
- `radius(&self) -> f64` - Returns the radius
- `diameter(&self) -> f64` - Returns the diameter

### Text Module


The text module provides text annotation capabilities.

#### Text


```rust
pub struct Text {
    position: Point,
    content: String,
    height: f64,
    rotation: f64,
    width_factor: f64,
    style: TextStyle,
    horizontal_alignment: HorizontalAlignment,
    vertical_alignment: VerticalAlignment,
}
```

**Methods:**

- `new(position: Point, content: &str) -> Self` - Creates a new text entity
- `position(&self) -> Point` - Returns the insertion point
- `content(&self) -> &str` - Returns the text content
- `set_content(&mut self, content: &str)` - Sets the text content
- `height(&self) -> f64` - Returns the text height
- `set_height(&mut self, height: f64)` - Sets the text height
- `style(&self) -> &TextStyle` - Returns the text style
- `set_style(&mut self, style: TextStyle)` - Sets the text style
- `rotation(&self) -> f64` - Returns the rotation angle in degrees
- `bounds(&self) -> BoundingBox` - Returns the bounding box

#### TextStyle


```rust
pub struct TextStyle {
    name: String,
    font: String,
    height: f64,
    width_factor: f64,
    oblique_angle: f64,
    is_upside_down: bool,
    is_backwards: bool,
}
```

**Methods:**

- `standard() -> Self` - Returns the standard text style
- `new(name: &str) -> Self` - Creates a new text style
- `name(&self) -> &str` - Returns the style name
- `font(&self) -> &str` - Returns the font name
- `set_font(&mut self, font: &str)` - Sets the font

#### MText


```rust
pub struct MText {
    position: Point,
    content: String,
    height: f64,
    width: f64,
    style: TextStyle,
    attachment: MTextAttachment,
    line_spacing: f64,
}
```

**Methods:**

- `new(position: Point, content: &str) -> Self` - Creates a new mtext entity
- `content(&self) -> &str` - Returns the full text content
- `append(&mut self, text: &str)` - Appends text to mtext
- `add_symbol(&mut self, symbol: MTextSymbol)` - Adds a special symbol
- `add_field(&mut self, field: Field)` - Adds a field

### Snap Module


The snap module provides object snapping functionality.

#### SnapPoint


```rust
pub struct SnapPoint {
    point: Point,
    snap_type: SnapType,
    source_entity: EntityId,
    display_marker: Option<Marker>,
}
```

**Methods:**

- `new(point: Point, snap_type: SnapType, source: EntityId) -> Self` - Creates a snap point
- `point(&self) -> Point` - Returns the snap point location
- `snap_type(&self) -> SnapType` - Returns the snap type
- `source_entity(&self) -> EntityId` - Returns the source entity ID

#### OSnap


```rust
pub struct OSnap {
    enabled: bool,
    snap_points: Vec<SnapPoint>,
    aperture_size: f64,
}
```

**Methods:**

- `new() -> Self` - Creates a new OSnap manager
- `enable(&mut self)` - Enables object snapping
- `disable(&mut self)` - Disables object snapping
- `is_enabled(&self) -> bool` - Checks if enabled
- `add_snap_point(&mut self, snap: SnapPoint)` - Adds a snap point
- `find_snap_points(&self, cursor: Point, tolerance: f64) -> Vec<SnapPoint>` - Finds snap points near cursor
- `set_aperture(&mut self, size: f64)` - Sets the aperture size

### Edit Module


The edit module provides entity editing capabilities.

#### Transformation


```rust
pub struct Transformation {
    translation: Option<Vector2D>,
    rotation: Option<f64>,
    scale: Option<Vector2D>,
    mirror_line: Option<Line>,
}
```

**Methods:**

- `new() -> Self` - Creates an identity transformation
- `with_translation(&mut self, translation: Vector2D) -> &mut Self` - Adds translation
- `with_rotation(&mut self, angle: f64, center: Point) -> &mut Self` - Adds rotation
- `with_scale(&mut self, scale: Vector2D, center: Point) -> &mut Self` - Adds scaling
- `with_mirror(&mut self, line: Line) -> &mut Self` - Adds mirroring
- `apply(&self, entity: &mut Entity)` - Applies transformation to an entity

#### GripEditor


```rust
pub struct GripEditor {
    grips: HashMap<EntityId, Vec<Grip>>,
    active_grip: Option<ActiveGrip>,
    grip_size: f64,
}
```

**Methods:**

- `new() -> Self` - Creates a new grip editor
- `add_entity(&mut self, entity: &Entity)` - Adds grips for an entity
- `remove_entity(&mut self, id: EntityId)` - Removes grips for an entity
- `find_grip_at(&self, point: Point, tolerance: f64) -> Option<ActiveGrip>` - Finds grip at point
- `move_grip(&mut self, grip: ActiveGrip, delta: Vector2D)` - Moves a grip
- `set_grip_size(&mut self, size: f64)` - Sets the visual grip size
- `clear(&mut self)` - Clears all grips

#### Grip


```rust
pub struct Grip {
    position: Point,
    grip_type: GripType,
    is_mandatory: bool,
}
```

**Methods:**

- `new(position: Point, grip_type: GripType) -> Self` - Creates a new grip
- `position(&self) -> Point` - Returns the grip position
- `grip_type(&self) -> GripType` - Returns the grip type

### Grid Module


The grid module provides grid functionality for drafting.

#### Grid


```rust
pub struct Grid {
    is_visible: bool,
    is_snap_enabled: bool,
    spacing: Vector2D,
    major_line_every: usize,
    origin: Point,
    limits: BoundingBox,
    sub_divisions: usize,
}
```

**Methods:**

- `new() -> Self` - Creates a default grid
- `set_visible(&mut self, visible: bool)` - Sets visibility
- `is_visible(&self) -> bool` - Checks if visible
- `enable_snap(&mut self)` - Enables snap to grid
- `disable_snap(&mut self)` - Disables snap to grid
- `is_snap_enabled(&self) -> bool` - Checks if snap is enabled
- `spacing(&self) -> Vector2D` - Returns the grid spacing
- `set_spacing(&mut self, spacing: Vector2D)` - Sets the grid spacing
- `snap(&self, point: Point) -> Point` - Snaps a point to the grid
- `set_origin(&mut self, origin: Point)` - Sets the grid origin

### Performance Module


The performance module provides utilities for optimizing CAD operations.

#### Parallel


```rust
pub struct Parallel;
```

**Methods:**

- `new() -> Self` - Creates a parallel processor
- `map<T, R, F>(&self, data: &[T], f: F) -> Vec<R>` - Parallel map operation
- `reduce<T, F>(&self, data: &[T], f: F) -> T` - Parallel reduce operation
- `filter_map<T, R, F>(&self, data: &[T], f: F) -> Vec<R>` - Parallel filter-map
- `geometry_bvh<T: Bounded>(&self, objects: &[T]) -> BVH` - Builds a BVH for geometry

#### Memory


```rust
pub struct Memory;
```

**Methods:**

- `new() -> Self` - Creates a memory manager
- `allocate(&self, size: usize) -> *mut u8` - Allocates memory
- `deallocate(&self, ptr: *mut u8)` - Deallocates memory
- `reallocate(&self, ptr: *mut u8, new_size: usize) -> *mut u8` - Reallocates memory
- `set_memory_pool(&self, pool: MemoryPool)` - Sets a custom memory pool
- `optimize_for_geometry(&self, entities: &[Entity])` - Optimizes memory for geometry entities

### Selection Module


The selection module provides entity selection functionality.

#### Selection


```rust
pub struct Selection {
    selected_entities: BTreeSet<EntityId>,
    selection_mode: SelectionMode,
    selection_window: Option<SelectionWindow>,
    cross_selection: bool,
}
```

**Methods:**

- `new() -> Self` - Creates a new selection
- `select(&mut self, id: EntityId)` - Selects an entity
- `deselect(&mut self, id: EntityId)` - Deselects an entity
- `select_all(&mut self, document: &Document)` - Selects all visible entities
- `clear(&mut self)` - Clears all selections
- `is_selected(&self, id: EntityId) -> bool` - Checks if entity is selected
- `selected_count(&self) -> usize` - Returns the count of selected entities
- `window_select(&mut self, window: SelectionWindow, add: bool)` - Performs window selection
- `set_selection_mode(&mut self, mode: SelectionMode)` - Sets the selection mode
- `add_to_selection(&mut self, id: EntityId)` - Adds to selection without clearing

### Hatch Module


The hatch module provides hatching functionality for closed areas.

#### Hatch


```rust
pub struct Hatch {
    pattern_name: String,
    pattern_scale: f64,
    pattern_angle: f64,
    boundary_curves: Vec<Box<dyn Curve>>,
    islands: Vec<HatchIsland>,
    origin_point: Point,
    is_associative: bool,
}
```

**Methods:**

- `new(pattern_name: &str) -> Self` - Creates a new hatch
- `set_pattern(&mut self, name: &str, scale: f64, angle: f64)` - Sets the hatch pattern
- `add_boundary(&mut self, curve: Box<dyn Curve>)` - Adds a boundary curve
- `set_origin(&mut self, point: Point)` - Sets the hatch origin
- `generate_pattern(&self) -> Vec<Line>` - Generates the hatch lines
- `is_point_inside(&self, point: Point) -> bool` - Tests if point is inside hatch

#### HatchPattern


```rust
pub struct HatchPattern {
    name: String,
    description: String,
    angle: f64,
    scale: f64,
    pattern_lines: Vec<PatternLine>,
}
```

**Methods:**

- `standard() -> &'static Self` - Returns the standard hatch pattern
- `dots() -> &'static Self` - Returns the dot pattern
- `angled() -> &'static Self` - Returns an angled pattern
- `cross() -> &'static Self` - Returns a cross hatch pattern

## Error Handling


### CadrsError


```rust
#[derive(Debug, Error)]

pub enum CadrsError {
    #[error("Entity not found: {0}")]
    EntityNotFound(EntityId),
    
    #[error("Layer not found: {0}")]
    LayerNotFound(String),
    
    #[error("Invalid operation: {0}")]
    InvalidOperation(String),
    
    #[error("Geometry error: {0}")]
    GeometryError(String),
    
    #[error("I/O error: {0}")]
    IoError(#[from] std::io::Error),
    
    #[error("Constraint error: {0}")]
    ConstraintError(String),
    
    #[error("Solver error: {0}")]
    SolverError(String),
    
    #[error("Render error: {0}")]
    RenderError(String),
}
```

## Usage Examples


### Basic Document Operations


```rust
use cadrs::prelude::*;

fn main() -> Result<(), CadrsError> {
    // Create a new document
    let mut doc = Document::new();
    
    // Add a layer
    let layer_id = doc.add_layer(Layer::new("MyLayer"))?;
    
    // Create entities
    let line = Line::new(Point::new(0.0, 0.0), Point::new(10.0, 10.0));
    let circle = Circle::new(Point::new(5.0, 5.0), 3.0);
    
    // Add to document
    doc.add_entity(&line)?;
    doc.add_entity(&circle)?;
    
    Ok(())
}
```

### Geometric Transformations


```rust
fn transform_example() {
    let point = Point::new(10.0, 10.0);
    let transform = Transformation2D::rotation(std::f64::consts::PI / 4.0);
    let rotated = transform.apply(point);
    
    let scale = Transformation2D::scale_uniform(2.0);
    let scaled = scale.apply(point);
}
```

### File I/O


```rust
use cadrs::io::{DXFExporter, DXFImporter, Exporter, Importer};

fn io_example() -> Result<(), CadrsError> {
    let doc = Document::new();
    
    // Export to DXF
    let exporter = DXFExporter;
    let mut output = Vec::new();
    exporter.export(&doc, &mut output)?;
    
    // Import from DXF
    let importer = DXFImporter;
    let imported_doc = importer.import_document(&mut &output[..])?;
    
    Ok(())
}
```

### Rendering with SVG


```rust
fn svg_example(document: &Document) -> Result<(), CadrsError> {
    let mut renderer = SVGRenderer::new();
    renderer.set_size(800.0, 600.0);
    
    for entity in document.entities() {
        renderer.add_entity(entity)?;
    }
    
    renderer.save(Path::new("output.svg"))?;
    Ok(())
}
```

### Command System


```rust
fn command_example() {
    let doc = Document::new();
    let manager = CommandManager::new(&doc);
    
    // Commands can be executed through the command manager
    // They support undo/redo functionality
}
```

## Feature Flags


The following feature flags control which modules are compiled:

| Flag | Description |
|------|-------------|
| `geometry` | Enable geometry primitives (default) |
| `math` | Enable mathematical utilities (default) |
| `data_structure` | Enable document management (default) |
| `io` | Enable file I/O support (default) |
| `render` | Enable rendering engine (default) |
| `api` | Enable high-level API |
| `performance` | Enable performance utilities |
| `boolean` | Enable boolean operations |
| `constraint` | Enable constraint solving |
| `gpu` | Enable GPU rendering features |

## License


MIT License - see [LICENSE](LICENSE) file for details.