MoonBit ASCII DXF R12 记录读取与二维轮廓辅助检查库:原始字段保留、OCS/WCS、块阵列展开、诊断与SVG
///|
test "R12 document and WCS API" {
let doc = @dxfkit.read_document(
b"0\nSECTION\n2\nHEADER\n9\n$ACADVER\n1\nAC1009\n0\nENDSEC\n0\nSECTION\n2\nENTITIES\n0\nPOINT\n10\n2\n20\n3\n30\n4\n0\nENDSEC\n0\nEOF\n",
)
assert_true(doc.profile is @dxfkit.R12)
assert_eq(doc.read_warnings.length(), 0)
let world = doc.drawing.expand_world(0.01)
match world.placed[0].flat {
@dxfkit.Dot3(at~) => assert_eq(at.z, 4.0)
_ => fail("expected WCS point")
}
}moon add mik1e80/dxfkit@0.2.0let scan = @dxfkit.scan_tags(bytes)
let drawing = @dxfkit.build_drawing(scan)
let entities = drawing.entities()
let report = drawing.check({ tol: 0.05, min_gap: 0.5 })
println(report.to_text())
let svg = drawing.to_svg(0.05)| 检查 | 实际覆盖 |
|---|---|
| 退化几何 | 非正圆半径、空或单点轮廓、零长度线段 |
| 闭合 | 同图层开放实体的端点串链与缝隙;不等于完整拓扑证明 |
| 自相交 | 同一实体内非相邻折线段的真交叉 |
| 重复路径 | 同图层线段的共线重叠,排除同实体相邻段 |
| 最小净距 | 同图层不同实体的线段距离;跳过容差内的端点接触 |
| 检查覆盖 | 未重建语义、无可检查轮廓、不适用的 WCS 平面、预算截断、解析与离散诊断 |
| 文字与图层 | 未转换的文字、图层引用和关闭 / 冻结状态提示 |
pub(all) enum CheckStatus {
Complete
CompleteWithFindings
Incomplete
InvalidOptions
}pub(all) struct CheckTolerances {
curve : Double
plane : Double
comparison : Double
}pub(all) enum DiagnosticCode {
InvalidOptions
InputOrExpansion
IncompleteCoverage
UnsupportedText
DegenerateGeometry
LayerState
BranchedContour
OpenContour
SelfIntersection
OverlappingPaths
InsufficientClearance
ScanWarning
DocumentWarning
OtherCheck
}fn Drawing::check_with_budget(self : Drawing, opt : CheckOptions, budget : GeometryBudget) -> Reportfn Drawing::check_with_budgets(self : Drawing, opt : CheckOptions, expansion : ExpandLimits, geometry : GeometryBudget) -> Reportfn Drawing::check_with_tolerances(self : Drawing, tolerances : CheckTolerances, min_gap : Double) -> Reportfn Drawing::expand_world_with_limits(self : Drawing, tol : Double, limits : ExpandLimits) -> WorldExpansionpub(all) enum Encoding {
Utf8
Cp1252
Other(Int)
}pub(all) struct ExpandLimits {
max_placed : Int
max_points : Int
max_visits : Int
}pub(all) enum Geometry {
Line(start~ : Vec3, end~ : Vec3)
Point(at~ : Vec3)
Circle(center~ : Vec3, radius~ : Double)
Arc(center~ : Vec3, radius~ : Double, start_angle~ : Double, end_angle~ : Double)
Ellipse(center~ : Vec3, major~ : Vec3, ratio~ : Double, start_param~ : Double, end_param~ : Double)
Polyline(vertices~ : Array[PolyVertex], closed~ : Bool)
Text(at~ : Vec3, height~ : Double, value~ : String, rotation~ : Double)
Insert(at~ : Vec3, block~ : String, scale~ : Vec3, rotation~ : Double)
Face(corners~ : Array[Vec3])
Dimension(at~ : Vec3, block~ : String, measurement~ : Double)
Spline(degree~ : Int, knots~ : Array[Double], control_points~ : Array[Vec3], weights~ : Array[Double])
Hatch(at~ : Vec3, solid~ : Bool, pattern~ : String, paths~ : Int)
Unknown
}pub(all) struct GeometryBudget {
max_candidates : Int
}pub(all) struct InsertInstance {
handle : String
block : String
row : Int
column : Int
}pub(all) struct Layer {
name : String
color : Int
linetype : String
frozen : Bool
locked : Bool
lineweight : Int
}pub(all) struct R12CellAttribute {
source_record : Int
definition_record : Int
from_constant_definition : Bool
data : R12Attribute
anchor : Vec3
alignment : Vec3?
baseline : Vec3
up : Vec3
}pub(all) struct R12Dimension {
block_name : String
block : R12Link
style : String
flags : Int
definition : Vec3
text_midpoint : Vec3
block_offset : Vec3?
extension_start : Vec3?
extension_end : Vec3?
pick_or_vertex : Vec3?
arc_point : Vec3?
leader_length : Double?
rotation : Double?
horizontal_direction : Double?
oblique : Double?
text_rotation : Double?
text : String?
}pub(all) struct R12DimensionAnchor {
slot : R12DimensionSlot
handle : String
point : R12FeaturePoint
}pub(all) struct R12DimensionBinding {
dimension_handle : String
anchors : Array[R12DimensionAnchor]
}pub(all) enum R12DimensionLabelPart {
LabelText(String)
ToleranceStack(upper~ : String, lower~ : String?, height_factor~ : Double, limits~ : Bool)
}pub(all) struct R12DimensionPicture {
block_record : Int
style_record : R12Link
overrides : Array[R12DimStyleOverride]
world : WorldExpansion
}pub(all) enum R12DimensionSlot {
DefinitionPoint
ExtensionStart
ExtensionEnd
PickOrVertex
ArcPoint
}pub(all) struct R12DimensionUpdate {
value : Double
angular : Bool
label : String?
label_parts : Array[R12DimensionLabelPart]
text_at : Vec3
lines : Array[(Vec3, Vec3)]
arc : R12DimensionArc?
}fn R12DimensionUpdate::layout_text(self : R12DimensionUpdate, height : Double, measure : (String, Double) -> Double) -> Result[R12DimensionTextLayout, String]pub(all) enum R12EntitySemantics {
SpatialLine(start~ : Vec3, end~ : Vec3)
SpatialPolyline(points~ : Array[Vec3], closed~ : Bool)
PolygonMesh(points~ : Array[Vec3], m~ : Int, n~ : Int, closed_m~ : Bool, closed_n~ : Bool)
FittedMesh(R12FittedMesh)
Polyface(points~ : Array[Vec3], faces~ : Array[Array[Int]])
Symbol(name~ : String, insertion~ : Vec3, size~ : Double, rotation~ : Double, x_scale~ : Double, oblique~ : Double, thickness~ : Double, extrusion~ : Vec3)
Viewport(center~ : Vec3, width~ : Double, height~ : Double, status~ : Int, id~ : Int, view~ : R12ViewportView?)
Dimension(R12Dimension)
FaceEdges(corners~ : Array[Vec3], invisible_mask~ : Int)
AttributeDefinition(data~ : R12Attribute, block_record~ : Int?)
Attribute(data~ : R12Attribute, insert_record~ : Int?, definition~ : R12Link)
}pub(all) enum R12FeaturePoint {
FeatureStart
FeatureEnd
FeatureMidpoint
FeatureCenter
FeatureLocation
FeatureAngle(Double)
}pub(all) struct R12FieldFinding {
record_index : Int
kind : String
group : Int
issue : R12FieldIssue
}pub(all) enum R12FieldIssue {
MissingField
RepeatedField
InvalidField
MissingBlock
AmbiguousBlock
MissingTableEntry
AmbiguousTableEntry
MissingLocalHandle
AmbiguousLocalHandle
}pub struct R12FittedMesh {
fit : R12MeshFit
controls : Array[Vec3]
samples : Array[Vec3]
m : Int
n : Int
sample_m : Int
sample_n : Int
closed_m : Bool
closed_n : Bool
}fn R12FittedMesh::compare_refit(self : R12FittedMesh, tol : Double, max_points? : Int) -> Result[R12MeshComparison, String]fn R12FittedMesh::refit(self : R12FittedMesh, sample_m : Int, sample_n : Int, max_points? : Int) -> Result[R12FittedMesh, String]pub(all) struct R12FontStyle {
name : String
font_file : String
big_font_file : String
flags : Int
}pub(all) enum R12Link {
Resolved(Int)
Missing
Ambiguous
}pub(all) struct R12MeshComparison {
distances : Array[Double]
max_error : Double
worst_index : Int
outside_tolerance : Int
}pub(all) struct R12PositionedGlyph {
glyph_id : Int
x_advance : Double
y_advance : Double
x_offset : Double
y_offset : Double
}pub(all) struct R12SemanticReport {
entries : Array[R12SemanticEntry]
findings : Array[R12SemanticFinding]
complete : Bool
}pub struct R12ShxFont {
// private fields
}fn R12ShxFont::bigfont_run(self : R12ShxFont, primary : R12ShxFont, text : String, packed_code : (Char) -> Int?, max_work? : Int) -> Result[R12GlyphRun, String]fn R12ShxFont::bigfont_vertical_run(self : R12ShxFont, primary : R12ShxFont, text : String, packed_code : (Char) -> Int?, max_work? : Int) -> Result[R12VerticalGlyphRun, String]fn R12ShxFont::glyph_run(self : R12ShxFont, text : String, map? : (Char) -> Int, max_work? : Int) -> Result[R12GlyphRun, String]pub(all) struct R12StyledDimension {
dimension_lines : Array[(Vec3, Vec3)]
extension_lines : Array[(Vec3, Vec3)]
arrows : Array[(Vec3, Vec3, Vec3)]
ticks : Array[(Vec3, Vec3)]
custom_arrows : Array[WorldPlaced]
arc : R12DimensionArc?
label : String?
text_at : Vec3
text_height : Double
dimension_color : Int
extension_color : Int
text_color : Int
}fn R12StyledDimension::r12_dimension_obstacles(self : R12StyledDimension) -> Result[Array[Aabb2], String]pub struct R12TrueType {
glyphs : Int
horizontal_metrics : Int
long_offsets : Bool
cap : Double
ascent : Double
descent : Double
// private fields
}fn R12TrueType::glyph_run(self : R12TrueType, text : String, tol? : Double, max_work? : Int) -> Result[R12GlyphRun, String]fn R12TrueType::positioned_run(self : R12TrueType, glyphs : Array[R12PositionedGlyph], tol? : Double, max_work? : Int) -> Result[R12GlyphRun, String]pub(all) struct R12ViewportView {
target : Vec3
direction : Vec3
twist : Double
height : Double
center : Vec2
lens_length : Double
front_clip_z : Double
back_clip_z : Double
mode : Int
circle_zoom : Int
fast_zoom : Int
ucs_icon : Int
snap_on : Int
grid_on : Int
snap_style : Int
snap_iso_pair : Int
snap_angle : Double
snap_base : Vec2
snap_spacing : Vec2
grid_spacing : Vec2
hide_plot : Int
frozen_layers : Array[String]
}fn ReadDocument::r12_cell_attributes(self : ReadDocument, insert_record : Int, row : Int, column : Int) -> Result[Array[R12CellAttribute], String]fn ReadDocument::r12_dimension_picture(self : ReadDocument, record_index : Int, tol : Double, limits? : ExpandLimits) -> Result[R12DimensionPicture, String]fn ReadDocument::r12_layout_attribute(self : ReadDocument, attribute : R12CellAttribute, shape : (R12FontStyle, String) -> R12GlyphRun?, max_points? : Int) -> Result[R12GlyphLayout, String]fn ReadDocument::r12_layout_vertical_attribute(self : ReadDocument, attribute : R12CellAttribute, shape : (R12FontStyle, String) -> R12VerticalGlyphRun?, max_points? : Int) -> Result[R12GlyphLayout, String]fn ReadDocument::r12_recompute_dimension(self : ReadDocument, record_index : Int, tol : Double, definition? : R12Dimension, precision? : Int) -> Result[R12DimensionUpdate, String]fn ReadDocument::r12_refresh_bound_dimension(self : ReadDocument, binding : R12DimensionBinding, tol : Double, precision? : Int) -> Result[R12DimensionUpdate, String]fn ReadDocument::r12_render_dimension(self : ReadDocument, record_index : Int, update : R12DimensionUpdate, label_width? : Double) -> Result[R12StyledDimension, String]pub(all) struct ReadLimits {
max_file_bytes : Int
max_line_bytes : Int
max_tags : Int
max_records : Int
max_warnings : Int
max_string_bytes : Int
}pub(all) struct TagStream {
// private fields
}fn TagStream::with_legacy_decoder(limits : ReadLimits, decoder : (Int, Bytes) -> String?) -> TagStreampub(all) enum TagValue {
Str(String)
I16(Int)
I32(Int)
I64(Int64)
F64(Double)
Bool(Bool)
Bin(Bytes)
}pub(all) struct Vec2 {
x : Double
y : Double
}pub(all) struct Vec3 {
x : Double
y : Double
z : Double
}fn WorldExpansion::r12_dimension_obstacles(self : WorldExpansion, plane_tol : Double, max_boxes? : Int) -> Result[Array[Aabb2], String]pub(all) struct WorldPlaced {
entity : Entity
layer : String
flat : WorldFlat
instances : Array[InsertInstance]
}fn angle_span(from : Double, to : Double) -> Doublefn is_handle_code(code : Int) -> Boolfn is_point_code(code : Int) -> Boolfn is_pointer_code(code : Int) -> Boolfn is_xdata_code(code : Int) -> Boolfn normalize_angle(rad : Double) -> Doublefn point_code_parts(code : Int) -> (Int, Int)?fn r12_avoid_dimension_labels(labels : Array[R12DimensionLabelBox], obstacles : Array[Aabb2], step : Double, clearance? : Double, rings? : Int, max_checks? : Int) -> Result[Array[R12DimensionLabelPosition], String]fn r12_positioned_fonts(runs : Array[R12PositionedFontRun], tol? : Double, max_work? : Int) -> Result[R12GlyphRun, String]fn read_document_with_legacy_decoder(source : Bytes, limits : ReadLimits, decoder : (Int, Bytes) -> String?) -> ReadDocumentInstall
Download zipMoonBit ASCII DXF R12 记录读取与二维轮廓辅助检查库:原始字段保留、OCS/WCS、块阵列展开、诊断与SVG