dxfkit

    MoonBit ASCII DXF R12 记录读取与二维轮廓辅助检查库:原始字段保留、OCS/WCS、块阵列展开、诊断与SVG

    dxf
    cad
    laser-cutting
    cnc
    drawing
    parser
    moonbit
    Download zip
    Author
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    5 hours ago
    Downloads
    71

    #dxfkit:接口与实现边界

    MoonBit ASCII DXF R12 记录读取与二维轮廓辅助检查库。本文对应模块版本 0.2.0。通过 Mooncakes 使用时请安装与本文同版本的依赖;从 GitHub 使用时请检出对应源码提交。当前结构诊断、自交接触容差和版本迁移见本轮记录;安装、CLI和版本区别见README。

    #R12 读取和 WCS

    Report::status() 区分完成、完成且有发现、检查不完整和参数错误。Finding::diagnostic() 提供稳定类别、级别和消息,InputOrExpansion 汇总既有输入和展开警告。

    ReadDocument::read_status() 报告无扫描结果、带警告或读取完成。ReadDocument::diagnostics() 将扫描警告和其余读取/结构/配置警告按阶段归类,避免常规路径重复报告扫描警告。

    Drawing::check_with_tolerances({ curve, plane, comparison }, min_gap) 分开指定离散、WCS 平面及几何比较容差。Drawing::check_with_budgets() 同时接收展开和候选预算。Drawing::svg_with_limit(tol, max_bytes) 超限返回 SvgByteLimit,默认限额为 32 MiB UTF-8。

    ReadDocument::audit_r12_fields() 对部分常用实体、已声明表项和本地 XDATA 句柄返回原始记录下标、组码和问题类别。complete 表示声明范围内的审计执行完毕,审计结果见 findings。read_document_with_legacy_decoder 和 TagStream::with_legacy_decoder 接收可信同步回调,为未内置的旧代码页提供字符串解码。回调返回 None 后扫描器会保留降级文本并告警。

    ReadDocument::r12_semantics() 为 AC1009 返回空间折线和网格拓扑、SHAPE 参数、MVIEW、标注块和局部属性关联。entries 和 findings 均可回查 records,而 complete 表示本次遍历有没有受读取诊断或诊断预算影响。块内坐标在其所属空间中表示,需要图纸中的块变换时继续使用 expand_world()。详见实体与关联矩阵。

    • FittedMesh 分开给出控制框和已存 WCS 样点。quad(m,n) 返回样点格四角,按闭合方向接缝。只有控制框的输入仍可读取,曲面采样为空。
    • r12_cell_attributes(insert_record, row, column) 按零起始行列查询一个单元。已存 ATTRIB 的位置只加网格偏移,常量 ATTDEF 使用含块基点的完整实例变换。结果附记录下标、锚点、对齐点与文字基向量,坐标位于该 INSERT 所在空间。
    • r12_dimension_picture(record_index, tol) 返回保存的标注图块、DIMSTYLE 记录关联、ACAD/DSTYLE 覆盖及已放置的图元。支持组 12 偏移和图块里的嵌套箭头,不参与二维轮廓检查。相关案例见独立消费验证。
    • R12FittedMesh::refit(m,n) 按明确的结点和闭合约定生成 WCS 样点,返回可继续调用 quad() 的网格,原样点保持可用。
    • r12_layout_attribute(cell, shape) 接收经调用方字体整形的单行字形路径。库处理居中、基线与垂直对齐、Fit/Aligned、倾斜、镜像及所在空间的仿射变换。字体文件名只随 STYLE 传给回调。
    • r12_recompute_dimension(record, tol, definition=edited) 由当前定义点重算量值、十进制标签和基本线/弧。距离单位沿用原图,角度量值为弧度,显示标签使用度。返回结果可供应用更新自己的标注图层。
    • load_r12_truetype(bytes) 和 load_r12_shx(bytes) 将调用方提供的字体字节转成可供 r12_layout_attribute() 使用的字形路径。支持 Unicode cmap 4/12、TrueType 二次轮廓和 XY 或实际轮廓点附件,以及 SHX shapes 1.0/1.1、Unicode SHX 和受限横排/竖排 BIGFONT。bigfont_run() 和 bigfont_vertical_run() 接收调用方的双字节映射,竖排轨迹可传给 r12_layout_vertical_attribute()。r12_positioned_fonts() 按视觉顺序组合同一段落中的字体回退。库不会打开图纸中的字体路径。
    • 编辑器保存 R12DimensionBinding 后,可用 r12_refresh_bound_dimension() 从最新文档按句柄更新定义点。支持顶层线段、圆、圆弧和点的指定特征,缺失和歧义会返回错误。r12_render_dimension() 可生成尺寸线、延伸线、箭头或短划及文字参数,custom_arrows 返回本地箭头图块的 WCS 图元。直线标注可传测量后的文字宽度以获得短跨距布局。重算支持线性尺寸的十进制容差、极限值和替代单位。R12DimensionUpdate::layout_text() 按调用方测量结果返回堆叠文本位置与尺寸。r12_avoid_dimension_labels() 在 WCS XY 内避开整图的已提供障碍,返回本轮可用的位置或保留原位置并注明原因。
    • R12FittedMesh::compare_refit() 对文件保存的 WCS 样点逐索引输出误差及超差计数。它需要同一文件的控制框和采样网格。

    当前开发版默认启用ReadLimits::default();可用scan_tags_with_limits、read_document_with_limits或TagStream::with_limits指定读取预算。超限保留部分扫描结果及明确警告,不可当完整文件;流式调用者见is_limited()应停止喂入。

    结构诊断现由build_drawing统一附到Drawing.warnings,因此check、check_with_limits与analyze均会报告。Drawing::check_with_budget(opt, GeometryBudget)给拓扑/相交/净距设置共享候选访问预算;展开预算独立,CheckOptions旧字段保持兼容。Record::try_double/try_int以Ok(None)表示缺失、Err表示类型错误;require_*也拒绝缺失,宽松get_*/as_*仅供旧调用方兼容。try_int接收I16/I32,不静默截断浮点/64位值。

    新业务使用Entity::flatten_checked取得错误原因;Geometry::flatten_checked为无实体坐标语义的局部入口。旧flatten和spline_points的回退结果不应用作完整检查证据。文字标签的字高为面积尺度近似,旋转/镜像/剪切、宽高和字形未忠实渲染;AC1009 的阵列属性位置可由独立的读取 API 查询,文字标签仍为简化预览。XY数值域、各阶段预算及共用容差边界见SECURITY。

    单条多段线/样条内部或段分组达到诊断预算时会停止派生解析,并明确报告不完整;原始source/records仍保留其对应视图,不把恢复出的几何当完整验证。详细资源和模型边界见维护记录、兼容性及模型验证层次。

    ///|
    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")
    }
    }

    ReadDocument.source 保留完整源字节;records 保留扫描器输出中的控制记录、组码顺序、重复字段、未知类型及 XDATA。read_warnings 诊断读取/结构和版本范围,不把几何未实现混入读取状态。ConformanceProfile::R12 表示按 $ACADVER=AC1009 选择配置,不是全部必填字段、编码与语义均符合标准的证明。

    Ocs::from_extrusion() 检查并归一化方向;to_wcs() 保留标高。Drawing::expand_world() / expand_world_with_limits() 返回 WCS XYZ 和 InsertInstance 路径(外到内,行列从 0 开始),阵列间距随旋转、不随块缩放。LINE、POINT、3DFACE 已是 WCS,不再按其挤出方向旋转坐标。详见R12 矩阵。

    当前 Drawing::expand() 和 Entity::flatten_checked() 只把转换后落在 WCS Z=0(容差内)的轮廓交给 XY 检查;其他平面保留世界坐标并拒绝二维结论。Geometry::flatten_checked() 仍是没有实体 OCS/来源身份的局部几何接口,调用方不得把它当作 WCS 转换入口。

    #安装与兼容版本

    在 MoonBit 工程中添加固定版本依赖:

    moon add mik1e80/dxfkit@0.2.0

    包导入名为 mik1e80/dxfkit;独立使用不依赖网页或本库源码工作区。注册表消费验证命令为 node scripts/verify-consumer.cjs --registry --r12,同时断言版本、注册表来源与 R12 接口行为。

    既有 0.1.1 提供七类核心轮廓实体、受限二维 SOLID/TRACE 边界和普通 INSERT。0.2.0 新增的 R12 读取、OCS/WCS 与阵列展开使用上文的接口;逐字段输入、输出、限制与案例见交付范围,追加行为见补充几何审查。

    #为什么选择这个范围

    DXF 图纸交换与脚本处理是已有需求,Python ezdxf 是成熟参照。dxfkit 的交付目标是可复用的 MoonBit 读取与几何接口,附带可验证的检查示例。它不保证图纸可加工,也不以“生态唯一”或功能数量作为正确性的证据。

    #读取与数据模型

    let 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)

    TagScan 返回 tag、诊断与编码;Drawing 保存段、记录、子类与警告。Entities 保存已解码实体及未解码记录。未知实体不自动丢弃,但本项目不提供写回或字节级无损往返承诺。

    支持不同时期 ASCII DXF 的组码和子类写法。47 个回归文件包含 AC1006、AC1009 到 AC1032 的示例,这不表示支持这些版本的全部实体与语义。

    数值异常保留文本并警告;整数使用整数解析,64位值不再经 Double 舍入。UTF-8 和 CP1252 可解码,其他声明代码页以 Latin-1 降级并警告;UTF-8 使用宽容解码。编码探测限于文件头 1024 字节。

    #几何与离散

    bounds() 是原始解码数据的几何包围估计,不代表通过 checked 合法性验证;非法 ELLIPSE 仍可能得到包围估计。可靠几何处理须先使用 flatten_checked(),本轮不新增 bounds_checked API。

    当前 main 要求显式 SPLINE 次数(71),缺失不再默认三次;明确拒绝 Closed/Periodic 标志,以及非空但不等于控制点数的权重数组;无权重才按全 1。ELLIPSE 轴比接收 (0,1]。多段线非零宽度/厚度保留中心线并报告不完整;缺 ENDBLK 按下一块或段末恢复且警告。完整修订见本轮记录。

    核心轮廓为 LINE、CIRCLE、ARC、ELLIPSE、LWPOLYLINE、普通二维 POLYLINE、受限 SPLINE。POINT 和文字用于位置或简化预览;SOLID/TRACE 在下述受限范围内支持二维边界;HATCH、DIMENSION、3DFACE 等保留已有字段,不能据此认为它们的轮廓已参与检查。

    ELLIPSE 的 11/21/31 是相对圆心长轴向量。普通 POLYLINE 不接受拟合、空间和网格语义;损坏顶点保留记录并拒绝整条轮廓,避免拼接出新形状。裸 Geometry::Face 不携带 SOLID/TRACE/3DFACE 身份,调用其 flatten() / flatten_checked() 返回 Empty。SOLID/TRACE 应使用 Entity::flatten_checked(tol),当前 main 会转换 OCS,仅将零厚度且转换后在 WCS Z=0 检查平面的边界交给二维检查;3DFACE 仍报告二维未覆盖。

    • Geometry::flatten_checked(tol) 返回 Result[Flat, String],是曲线的 checked 入口;整图展开使用保留身份的 Entity::flatten_checked。
    • spline_points_checked(degree, knots, control_points, weights, tol) 支持连续、正权重 NURBS 的 XY 离散。
    • arc_from_bulge() 用逆时针形式描述点集;多段线连接时根据 bulge 符号选择遍历方向,并保留精确原始端点。
    • Drawing::expand(tol) 展开嵌套 INSERT,复合仿射变换并处理图层0继承;累计最大拉伸上界用于调整局部容差。
    • Drawing::declared_unit_label() 只显示单位声明,不转换坐标或阈值。

    样条通过 Boehm 节点插入分解为有理 Bézier 段,使用齐次 de Casteljau 细分。正权重下,曲线位于投影控制点的凸包中;用控制点到线段的距离判定细分,避免中点恰好落在弦上时漏掉曲线。椭圆由每段不超过90°的有理二次 Bézier 表示,复用同一离散过程。

    资源边界:样条次数不超过32,输入控制点不超过4096;递归深度16,输出最多65536点。圆弧最多4096段。checked入口达到上限且不能满足容差时返回错误,而不是宣称已满足目标。Double 运算仍有舍入误差;这些限制不构成任意数值尺度的严格精确算术保证。

    旧 flatten()、spline_points() 和 ellipse_points() 为兼容保留占位 / 空结果回退,调用方如需判断完整性应使用 checked 入口。

    #检查的实际语义

    Drawing::check(CheckOptions) 返回 Report,每条 Finding 有检查项、严重程度和文字说明。

    Report::has_incomplete_checks() 统一判断解析恢复、覆盖限制、文字未转轮廓或非法检查参数。报告结论明确标为“检查不完整”,即使同一文件中存在正常轮廓也保留这些原因;CLI --strict 因此失败。具体混合输入和自动断言见完整性约定。普通的开放轮廓几何告警不自动等于检查覆盖缺失。

    检查实际覆盖
    退化几何非正圆半径、空或单点轮廓、零长度线段
    闭合同图层开放实体的端点串链与缝隙;不等于完整拓扑证明
    自相交同一实体内非相邻折线段的真交叉
    重复路径同图层线段的共线重叠,排除同实体相邻段
    最小净距同图层不同实体的线段距离;跳过容差内的端点接触
    检查覆盖未重建语义、无可检查轮廓、不适用的 WCS 平面、预算截断、解析与离散诊断
    文字与图层未转换的文字、图层引用和关闭 / 冻结状态提示

    净距不是材料最窄厚度。它不覆盖单实体窄颈、跨图层关系,也不能代替刀具半径补偿或热 / 力学分析。曲线先离散后比较,阈值附近的结论需考虑两侧离散误差。

    关闭 / 冻结图层在部分几何检查中跳过,是本工具的筛选约定,不代表 CAM 一定按同样方式处理图层。

    参数要求 tol > 0、min_gap >= 0 且有限。min_gap = 0 不检查净距。单位沿用图纸坐标,HEADER声明仅供使用者确认。

    #流式入口

    TagStream::new() / feed(Bytes) / finish() 共用 ASCII 扫描状态机。跨块保留编码探测前缀、未完成行及组码状态。扫描警告会积累;不同调用方保留的输出也影响总内存。

    CLI stats 分块读文件、统计 tag、段、版本、编码,不保存全量 tag 或实体。scan_tags() 则会保留所有 tag;check / svg 使用全量图纸,不能作为低内存几何检查入口。

    #使用与验证

    Layer::is_enabled_for_checks() 只表示本工具默认筛选规则,旧 is_machinable() 文档弃用,保留为同义兼容接口,不判断能否加工;新代码使用前者,本版不添加会让旧调用在 --deny-warn 下失败的编译器弃用属性。Drawing::expand_with_limits(tol, ExpandLimits) 和 check_with_limits 支持图纸预算;默认展开上限为 10000 条放置记录、200000 点、100000 次访问,截断会标为不完整。Drawing::analyze(options) 使用同一 Expansion 生成 Report/SVG/单位;网页新增 analyze JSON 入口,旧 check/svg/svg_error 继续兼容。

    完整公开签名见自动生成的 pkg.generated.mbti;发布前运行 node scripts/verify-maintenance.cjs,核对格式及快照是否漂移。公开 API 审阅说明兼容接口和 checked/unchecked 边界。

    • 核心库仅依赖 MoonBit core;CLI / conformance 使用 moonbitlang/x 和 moonbitlang/async 的文件接口。
    • 库支持 wasm / wasm-gc / JS / native;文件工具支持 wasm / native。
    • CLI --strict 将警告也作为失败,便于批处理门禁;普通模式的0退出码不代表检查完全或可加工。
    • 网页使用同一库编译产物,部署前重新构建并执行回归。
    • SVG 数值使用 Double 往返表示,可含科学计数法;调用方不要依赖固定四位小数。
    • examples/library 是同模块调用包;examples/consumer 是独立模块工程,用公开 API 读取文件、提取实体、checked 离散和检查,已在仓库外以 Wasm、Native 验证。

    验证命令见 README.md。几何正确性以明确反例、解析几何和独立de Boor密集采样验证;第三方文件读取成功、测试数量或汇总点数不能单独证明正确性。

    逐实体坐标/尺寸/包围盒/误差和检查器正反例见验收矩阵。故障注入只作用于临时副本,验证列明的语义故障能被测试检出,不以“能够编译运行”替代判定正确。

    外部语料另按文件记录读取、实体字段解码和几何验证证据。现有 47 张文件均没有逐图纸独立几何真值;产生点列或能执行检查仍只记为已运行不变量回归。

    #SOLID / TRACE 的实体入口

    Entity::flatten_checked(tol) 保留实体身份。SOLID/TRACE 的局部角点同 Z、零厚度时按 0→1→3→2 生成边界,再转换 OCS 并判断检查平面;标准三角形只输出一次重复的第三/第四点。原始 Face.corners 保持文件顺序,3DFACE 不统一重排。

    此前这些类型仅保留元数据的边界已调整,详见历史追加审查和当前 R12 迁移说明。裸 Geometry::Face 没有实体身份,其 flatten / checked 仍返回 Empty。非默认 OCS 本身不再是拒绝原因;转换后不适用 XY 检查平面或不支持的厚度仍报告不完整。省略第四角点的恢复会报告不完整,部分第四坐标拒绝。

    #暂未实现

    二进制DXF、文件写回、通用编辑、全部R12必填字段和引用约束验证、完整HATCH边界、完整 CAD 标注样式、从 R12 文件恢复未保存的实体关联、厂商专用竖排 BIGFONT 指令、自动断行和全局最优布局、CFF 和字体指令执行、通用三维几何检查、刀路生成和参数化草图约束求解。OCS/WCS 与 INSERT 行列几何已实现,不再列作全未支持;受限实体和适用平面见矩阵。

    #来源

    样条格式参考 Autodesk SPLINE 文档;能力与公式参考 ezdxf;标准样条算法为节点插入、de Casteljau及de Boor。第三方版权、完整许可及已记录的参考关系见 THIRD_PARTY_NOTICES.md。

    INSERT 非默认 OCS 现进入三维变换链。倾斜几何保留在 expand_world,二维入口依据转换后的平面诊断,禁止静默丢掉 Z。二维检查对关联属性保留覆盖提示。AC1009 单元内属性位置可另用 r12_cell_attributes() 查询。

    Aabb2

    pub(all) struct Aabb2 {
    min : Vec2
    max : Vec2
    }

    平面轴对齐包围盒。

    空盒用 min > max 表示——Aabb2::empty() 给的是 min = +∞, max = -∞, 这样第一个点一并进来就自然变成「只包含那一个点」的盒子, 不用额外记「有没有点」的状态。

    Aabb2::center

    fn Aabb2::center(self : Aabb2) -> Vec2

    中心。空盒返回原点。

    Aabb2::contains

    fn Aabb2::contains(self : Aabb2, p : Vec2, tol : Double) -> Bool

    按容差判断点是否落在盒子里。

    Aabb2::empty

    fn Aabb2::empty() -> Aabb2

    空盒:min 是正无穷、max 是负无穷。往里并第一个点就会得到正确的盒子。

    Aabb2::expand

    fn Aabb2::expand(self : Aabb2, p : Vec2) -> Aabb2

    并进一个点。

    Aabb2::intersects

    fn Aabb2::intersects(self : Aabb2, other : Aabb2, tol : Double) -> Bool

    两个盒子是否相交(按容差)。

    加工检查里用来做线段求交的粗筛:两个包围盒不相交,它们里面的 线段一定不相交,可以整块跳过。这是把 O(n²) 降到能跑的关键。

    Aabb2::is_empty

    fn Aabb2::is_empty(self : Aabb2) -> Bool

    是不是空盒(一个点都没并进来过)。

    Aabb2::size

    fn Aabb2::size(self : Aabb2) -> Vec2

    宽高。空盒返回零。

    Aabb2::union

    fn Aabb2::union(self : Aabb2, other : Aabb2) -> Aabb2

    并进另一个盒子。

    Aabb3

    pub(all) struct Aabb3 {
    min : Vec3
    max : Vec3
    }

    三维轴对齐包围盒。约定和 Aabb2 完全一样。

    Aabb3::empty

    fn Aabb3::empty() -> Aabb3

    Aabb3::expand

    fn Aabb3::expand(self : Aabb3, p : Vec3) -> Aabb3

    Aabb3::is_empty

    fn Aabb3::is_empty(self : Aabb3) -> Bool

    Aabb3::size

    fn Aabb3::size(self : Aabb3) -> Vec3

    三个方向的尺寸。空盒返回零向量。

    Block

    pub(all) struct Block {
    name : String
    base : Vec3
    entities : Array[Entity]
    }

    一个块定义。

    Blocks

    pub(all) struct Blocks {
    blocks : Array[Block]
    warnings : Array[String]
    }

    BLOCKS 段里解析出来的块定义。

    BulgeArc

    pub(all) struct BulgeArc {
    center : Vec2
    radius : Double
    start_angle : Double
    end_angle : Double
    }

    bulge 换算出来的圆弧参数。

    CheckOptions

    pub(all) struct CheckOptions {
    tol : Double
    min_gap : Double
    }

    检查参数。

    CheckStatus

    pub(all) enum CheckStatus {
    Complete
    CompleteWithFindings
    Incomplete
    InvalidOptions
    }

    Describes the result of a check over the selected scope.

    CheckTolerances

    pub(all) struct CheckTolerances {
    curve : Double
    plane : Double
    comparison : Double
    }

    Curve sampling, projection onto Z=0, and endpoint/check comparisons have independent tolerances. The original CheckOptions API keeps its behavior.

    ConformanceProfile

    pub(all) enum ConformanceProfile {
    R12
    BestEffort
    } derive(Eq)

    AC1009 selects the R12 record-preservation profile; other versions are best effort. This is not certification of every mandatory field in the Autodesk standard.

    ConformanceProfile::equal

    automatically derived

    ConformanceProfile::not_equal

    automatically derived

    Diagnostic

    pub(all) struct Diagnostic {
    code : DiagnosticCode
    severity : Severity
    message : String
    }

    DiagnosticCode

    pub(all) enum DiagnosticCode {
    InvalidOptions
    InputOrExpansion
    IncompleteCoverage
    UnsupportedText
    DegenerateGeometry
    LayerState
    BranchedContour
    OpenContour
    SelfIntersection
    OverlappingPaths
    InsufficientClearance
    ScanWarning
    DocumentWarning
    OtherCheck
    }

    Stable categories for integrations. Individual legacy messages may change.

    Drawing

    pub(all) struct Drawing {
    version : String
    sections : Array[Section]
    warnings : Array[String]
    }

    解析出来的图纸骨架:只有结构,没有语义。

    Drawing::analyze

    fn Drawing::analyze(self : Drawing, opt : CheckOptions) -> DrawingAnalysis

    Drawing::blocks

    fn Drawing::blocks(self : Drawing) -> Blocks

    图纸的 BLOCKS 段。没有 BLOCKS 段时是空表。

    Drawing::check

    fn Drawing::check(self : Drawing, opt : CheckOptions) -> Report

    加工前检查。

    tol 既是离散容差、也是判定尺度(重合、闭合都拿它比)。

    Drawing::check_with_budget

    fn Drawing::check_with_budget(self : Drawing, opt : CheckOptions, budget : GeometryBudget) -> Report

    Expansion still uses its independent defaults; a partial check is explicit.

    Drawing::check_with_budgets

    fn Drawing::check_with_budgets(self : Drawing, opt : CheckOptions, expansion : ExpandLimits, geometry : GeometryBudget) -> Report

    Apply caller-selected expansion and candidate budgets in a single check.

    Drawing::check_with_limits

    fn Drawing::check_with_limits(self : Drawing, opt : CheckOptions, limits : ExpandLimits) -> Report

    按显式图纸预算检查;预算截断原因进入检查不完整报告。

    Drawing::check_with_tolerances

    fn Drawing::check_with_tolerances(self : Drawing, tolerances : CheckTolerances, min_gap : Double) -> Report

    Drawing::declared_unit_label

    fn Drawing::declared_unit_label(self : Drawing) -> String

    仅显示HEADER中的单位声明,不改变坐标或自动换算检查阈值。

    Drawing::entities

    fn Drawing::entities(self : Drawing) -> Entities

    图纸的 ENTITIES 段解析成实体。没有 ENTITIES 段时是空表。

    Drawing::expand

    fn Drawing::expand(self : Drawing, tol : Double) -> Expansion

    The checker uses WCS XY at Z=0; XYZ results remain available in expand_world.

    Drawing::expand_with_limits

    fn Drawing::expand_with_limits(self : Drawing, tol : Double, limits : ExpandLimits) -> Expansion

    Drawing::expand_world

    fn Drawing::expand_world(self : Drawing, tol : Double) -> WorldExpansion

    Expand blocks, arrays and OCS coordinates; retain XYZ and instance provenance.

    Drawing::expand_world_with_limits

    fn Drawing::expand_world_with_limits(self : Drawing, tol : Double, limits : ExpandLimits) -> WorldExpansion

    All array cells and empty block visits share one drawing-wide resource budget.

    Drawing::section

    fn Drawing::section(self : Drawing, name : String) -> Section?

    取一个段。

    Drawing::svg_with_limit

    fn Drawing::svg_with_limit(self : Drawing, tol : Double, max_bytes : Int) -> Result[String, SvgError]

    The limit counts UTF-8 bytes in the serialized SVG, including markup.

    Drawing::to_svg

    fn Drawing::to_svg(self : Drawing, tol : Double) -> String

    图纸 → SVG 字符串(一条 XML 文本)。

    tol 是离散容差,和检查用的一个口径。

    DrawingAnalysis

    pub(all) struct DrawingAnalysis {
    report : Report
    svg : String
    unit : String
    }

    同一 Drawing、同一展开结果生成报告和 SVG。

    Encoding

    pub(all) enum Encoding {
    Utf8
    Cp1252
    Other(Int)
    }

    文件用的编码。

    Encoding::is_fallback

    fn Encoding::is_fallback(self : Encoding) -> Bool

    这个编码是不是只能降级处理。

    Encoding::to_display

    fn Encoding::to_display(self : Encoding) -> String

    编码的中文名,出错信息里用。

    Entities

    pub(all) struct Entities {
    entities : Array[Entity]
    warnings : Array[String]
    }

    一个段里解析出来的实体。

    Entity

    pub(all) struct Entity {
    common : EntityCommon
    geom : Geometry
    }

    一条实体。

    Entity::bounds

    fn Entity::bounds(self : Entity) -> Aabb2?

    实体的二维包围盒。Unknown 返回 None。

    Entity::flatten_checked

    fn Entity::flatten_checked(self : Entity, tol : Double) -> Result[Flat, String]

    保留实体身份的离散入口。SOLID/TRACE 与 3DFACE 的存储顺序不同, 不改写原始 Face 角点,也不把仅有 Geometry 的 Face 统一重排。

    Entity::handle

    fn Entity::handle(self : Entity) -> String

    Entity::is_decoded

    fn Entity::is_decoded(self : Entity) -> Bool

    这条实体的几何认不认得出来。

    Unknown 是「解析器不认识」,不等于坏记录。检查环节要单独 报告有一批实体没被解码——图上那些东西也可能要切。

    Entity::kind

    fn Entity::kind(self : Entity) -> String

    Entity::layer

    fn Entity::layer(self : Entity) -> String

    EntityCommon

    pub(all) struct EntityCommon {
    kind : String
    layer : String
    handle : String
    record : Record
    }

    实体的公共部分:每条实体都有的东西。

    ExpandLimits

    pub(all) struct ExpandLimits {
    max_placed : Int
    max_points : Int
    max_visits : Int
    }

    Expansion

    pub(all) struct Expansion {
    placed : Array[Placed]
    warnings : Array[String]
    }

    Finding

    pub(all) struct Finding {
    check : String
    severity : Severity
    message : String
    }

    一条发现。

    Finding::diagnostic

    fn Finding::diagnostic(self : Finding) -> Diagnostic

    Flat

    pub(all) enum Flat {
    Outline(points~ : Array[Vec2], closed~ : Bool)
    Dot(at~ : Vec2)
    Label(at~ : Vec2, height~ : Double, value~ : String)
    Empty
    }

    离散之后的形状。

    Geometry

    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
    }

    实体的几何。只认本项目要处理的形状,其余落在 Unknown。

    Geometry::bounds

    fn Geometry::bounds(self : Geometry) -> Aabb2?

    几何的二维包围盒(丢掉 z——加工是二维的)。 Unknown 没有几何,返回 None。

    Geometry::flatten

    fn Geometry::flatten(self : Geometry, tol : Double) -> Flat

    把实体几何离散成折线。容差是弦高。

    Geometry::flatten_checked

    fn Geometry::flatten_checked(self : Geometry, tol : Double) -> Result[Flat, String]

    检查和展开使用此入口:达到上限或无法处理时返回错误,不把占位点当成正确曲线。

    GeometryBudget

    pub(all) struct GeometryBudget {
    max_candidates : Int
    }

    Shared candidate-visit budget for topology, intersections and gap checks.

    GeometryBudget::default

    pub(all) struct Header {
    vars : Array[HeaderVar]
    }

    HEADER 段。

    Header::extmax

    fn Header::extmax(self : Header) -> Vec3?

    图纸范围的右上角($EXTMAX)。

    Header::extmin

    fn Header::extmin(self : Header) -> Vec3?

    图纸范围的左下角($EXTMIN)。

    Header::get

    fn Header::get(self : Header, name : String) -> HeaderVar?

    取一个变量的原始值。

    Header::get_int

    fn Header::get_int(self : Header, name : String, default : Int) -> Int

    取一个变量的第一个值(数值)。没有就用默认值。

    注意 HEADER 变量的值有时是字符串有时是数字($ACADVER 是字符串, $INSUNITS 是整数),所以两个取值函数都要有。

    Header::get_point

    fn Header::get_point(self : Header, name : String) -> Vec3?

    取一个变量表示的三维点($EXTMIN / $EXTMAX 这类)。

    值不够三个时返回 None——宁可说「不知道」,也不要拿 x 当 z 用。

    Header::get_string

    fn Header::get_string(self : Header, name : String) -> String

    取一个变量的第一个值(字符串)。

    Header::insunits

    fn Header::insunits(self : Header) -> Int

    图纸单位。

    $INSUNITS 的值是个编号:0 = 没指定、1 = 英寸、4 = 毫米、6 = 米。 0 是最危险的值——没指定单位意味着图纸上的「1」到底是 1 毫米还是 1 英寸无从判断,差 25.4 倍。加工检查会把这一条报出来。

    HeaderVar

    pub(all) struct HeaderVar {
    name : String
    values : Array[Tag]
    }

    一个 HEADER 变量。

    InsertInstance

    pub(all) struct InsertInstance {
    handle : String
    block : String
    row : Int
    column : Int
    }

    A zero-based array cell in the outer-to-inner INSERT instance path.

    Layer

    pub(all) struct Layer {
    name : String
    color : Int
    linetype : String
    frozen : Bool
    locked : Bool
    lineweight : Int
    }

    一个图层。

    Layer::color_index

    fn Layer::color_index(self : Layer) -> Int

    图层实际的颜色索引(取绝对值)。

    Layer::is_enabled_for_checks

    fn Layer::is_enabled_for_checks(self : Layer) -> Bool

    是否按本工具默认规则参与部分几何检查,不表示 CAM 或机床行为。

    Layer::is_machinable

    fn Layer::is_machinable(self : Layer) -> Bool

    兼容旧接口;仅表示本工具检查筛选规则,不表示能否加工。 文档弃用:新代码使用 Layer::is_enabled_for_checks();本版保留同义行为。 未添加编译器 deprecated 属性,以免兼容调用在 --deny-warn 下成为错误。

    Layer::is_off

    fn Layer::is_off(self : Layer) -> Bool

    图层是不是关着的。

    DXF 用颜色的符号表示开关,不是单独一个标志位—— 这一点不看规范很难猜到。

    Ocs

    pub struct Ocs {
    x_axis : Vec3
    y_axis : Vec3
    normal : Vec3
    }

    DXF Arbitrary Axis Algorithm basis. Coordinates are expressed in WCS.

    Ocs::from_extrusion

    fn Ocs::from_extrusion(normal : Vec3) -> Result[Ocs, String]

    Normalize a finite, nonzero extrusion vector without squaring huge values.

    Ocs::to_wcs

    fn Ocs::to_wcs(self : Ocs, p : Vec3) -> Vec3

    Transform an OCS position, including its elevation, to WCS.

    Placed

    pub(all) struct Placed {
    entity : Entity
    layer : String
    flat : Flat
    }

    A checked XY outline and its original entity. Use expand_world for XYZ data.

    PolyVertex

    pub(all) struct PolyVertex {
    at : Vec3
    bulge : Double
    }

    多段线的一个顶点。

    R12Attribute

    pub(all) struct R12Attribute {
    tag : String
    value : String
    prompt : String?
    flags : Int
    style : String
    anchor : Vec3
    alignment : Vec3?
    normal : Vec3
    thickness : Double
    height : Double
    rotation : Double
    width_scale : Double
    oblique : Double
    generation_flags : Int
    horizontal : Int
    vertical : Int
    }

    R12CellAttribute

    pub(all) struct R12CellAttribute {
    source_record : Int
    definition_record : Int
    from_constant_definition : Bool
    data : R12Attribute
    anchor : Vec3
    alignment : Vec3?
    baseline : Vec3
    up : Vec3
    }

    One stored or constant attribute positioned at a requested INSERT cell. The basis vectors include the applicable parent scale and text rotation, leaving glyph generation and justification to the caller.

    R12DimStyleOverride

    pub(all) struct R12DimStyleOverride {
    group : Int
    value : Tag
    }

    One per-entity DIMSTYLE override and its original XDATA value.

    R12Dimension

    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?
    }

    R12DimensionAnchor

    pub(all) struct R12DimensionAnchor {
    slot : R12DimensionSlot
    handle : String
    point : R12FeaturePoint
    }

    R12DimensionArc

    pub(all) struct R12DimensionArc {
    center : Vec3
    start : Vec3
    normal : Vec3
    sweep : Double
    }

    An annotation arc in the DIMENSION plane, with WCS center and start and a positive counterclockwise sweep around normal.

    R12DimensionBinding

    pub(all) struct R12DimensionBinding {
    dimension_handle : String
    anchors : Array[R12DimensionAnchor]
    }

    Save this binding in the application and reuse it after each edit.

    R12DimensionLabelBox

    pub(all) struct R12DimensionLabelBox {
    center : Vec2
    size : Vec2
    }

    A measured dimension label in the WCS XY plane. Input order is priority.

    R12DimensionLabelPart

    pub(all) enum R12DimensionLabelPart {
    LabelText(String)
    ToleranceStack(upper~ : String, lower~ : String?, height_factor~ : Double, limits~ : Bool)
    }

    Structured label content. Limits omit the nominal value. A symmetric tolerance has only one row. The scale is relative to the main text height.

    R12DimensionLabelPosition

    pub(all) enum R12DimensionLabelPosition {
    LabelPlaced(Vec2)
    LabelBlocked(Vec2)
    LabelSearchLimited(Vec2)
    }

    R12DimensionPicture

    pub(all) struct R12DimensionPicture {
    block_record : Int
    style_record : R12Link
    overrides : Array[R12DimStyleOverride]
    world : WorldExpansion
    }

    Saved annotation primitives and references for one DIMENSION in its containing space. Primitive coordinates include the group 12 translation.

    R12DimensionSlot

    pub(all) enum R12DimensionSlot {
    DefinitionPoint
    ExtensionStart
    ExtensionEnd
    PickOrVertex
    ArcPoint
    }

    Fields of a dimension that can track an edited drawing feature.

    R12DimensionTextFragment

    pub(all) struct R12DimensionTextFragment {
    text : String
    at : Vec2
    height : Double
    }

    Position of the lower-left corner of the measured text box, relative to the center of the complete label. Units are drawing units.

    R12DimensionTextLayout

    pub(all) struct R12DimensionTextLayout {
    fragments : Array[R12DimensionTextFragment]
    size : Vec2
    }

    R12DimensionUpdate

    pub(all) struct R12DimensionUpdate {
    value : Double
    angular : Bool
    label : String?
    label_parts : Array[R12DimensionLabelPart]
    text_at : Vec3
    lines : Array[(Vec3, Vec3)]
    arc : R12DimensionArc?
    }

    Recomputed annotation geometry and decimal label. value is in drawing units for distances and radians for angles, before display formatting.

    R12DimensionUpdate::layout_text

    fn R12DimensionUpdate::layout_text(self : R12DimensionUpdate, height : Double, measure : (String, Double) -> Double) -> Result[R12DimensionTextLayout, String]

    Lay out nominal and tolerance text, centered vertically. The callback returns the width of a text fragment at the requested height.

    R12EntitySemantics

    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)
    }

    R12FeaturePoint

    pub(all) enum R12FeaturePoint {
    FeatureStart
    FeatureEnd
    FeatureMidpoint
    FeatureCenter
    FeatureLocation
    FeatureAngle(Double)
    }

    Stable entity-handle target chosen by the editor. R12 DXF itself does not preserve a reference from each DIMENSION point to its edited entity.

    R12FieldAudit

    pub(all) struct R12FieldAudit {
    findings : Array[R12FieldFinding]
    complete : Bool
    }

    R12FieldFinding

    pub(all) struct R12FieldFinding {
    record_index : Int
    kind : String
    group : Int
    issue : R12FieldIssue
    }

    R12FieldIssue

    pub(all) enum R12FieldIssue {
    MissingField
    RepeatedField
    InvalidField
    MissingBlock
    AmbiguousBlock
    MissingTableEntry
    AmbiguousTableEntry
    MissingLocalHandle
    AmbiguousLocalHandle
    }

    R12FittedMesh

    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
    }

    The stored sampled surface and editable control frame are separate grids. Both use M-major order. An empty samples array means that the exporter supplied only a control frame.

    R12FittedMesh::compare_refit

    fn R12FittedMesh::compare_refit(self : R12FittedMesh, tol : Double, max_points? : Int) -> Result[R12MeshComparison, String]

    Compare a preserved CAD sample grid to a refit of the same resolution. This API requires the exporter to retain both the frame and samples.

    R12FittedMesh::quad

    fn R12FittedMesh::quad(self : R12FittedMesh, m : Int, n : Int) -> (Vec3, Vec3, Vec3, Vec3)?

    Returns the four WCS vertices of a stored sampled quad. Closed directions wrap once. A frame-only mesh has no sampled quads.

    R12FittedMesh::refit

    fn R12FittedMesh::refit(self : R12FittedMesh, sample_m : Int, sample_n : Int, max_points? : Int) -> Result[R12FittedMesh, String]

    Re-evaluate the control frame on an M-major WCS grid without modifying the saved samples. Open B-splines use clamped uniform knots and closed directions use periodic knots. A closed Bézier axis uses cubic spans with three controls per span and an implicit return to control zero.

    R12FontStyle

    pub(all) struct R12FontStyle {
    name : String
    font_file : String
    big_font_file : String
    flags : Int
    }

    The DXF text style passed to a caller-supplied font shaper. File names are metadata. The library never opens a path obtained from DXF.

    R12GlyphLayout

    pub(all) struct R12GlyphLayout {
    visible : Bool
    paths : Array[Array[Vec3]]
    }

    Positioned font paths in the attribute's containing space. Invisible attributes return visible=false and an empty list without shaping text.

    R12GlyphRun

    pub(all) struct R12GlyphRun {
    paths : Array[Array[Vec2]]
    advance : Double
    ascent : Double
    descent : Double
    }

    A shaped single-line run in units where one cap height is 1.0. Include kerning, glyph positioning, and holes in paths. Ascent and descent are distances from the baseline, and paths retain their provider's ordering.
    pub(all) enum R12Link {
    Resolved(Int)
    Missing
    Ambiguous
    }

    A named local reference. Indices address ReadDocument::records.

    R12MeshComparison

    pub(all) struct R12MeshComparison {
    distances : Array[Double]
    max_error : Double
    worst_index : Int
    outside_tolerance : Int
    }

    Point-by-point comparison in the stored M-major order. distances[i] compares input sample i to the reconstructed sample with the same index.

    R12MeshFit

    pub(all) enum R12MeshFit {
    QuadraticBSpline
    CubicBSpline
    Bezier
    }

    R12PositionedFontRun

    pub(all) struct R12PositionedFontRun {
    font : R12TrueType
    glyphs : Array[R12PositionedGlyph]
    }

    One shaped span in visual order, paired with the exact font face used to shape it.

    R12PositionedGlyph

    pub(all) struct R12PositionedGlyph {
    glyph_id : Int
    x_advance : Double
    y_advance : Double
    x_offset : Double
    y_offset : Double
    }

    A glyph placement from an OpenType shaper, in font design units. The array order is the shaper's visual order; glyphs are not remapped via cmap.

    R12SemanticEntry

    pub(all) struct R12SemanticEntry {
    record_index : Int
    entity : R12EntitySemantics
    }

    R12SemanticFinding

    pub(all) struct R12SemanticFinding {
    record_index : Int
    message : String
    }

    R12SemanticReport

    pub(all) struct R12SemanticReport {
    entries : Array[R12SemanticEntry]
    findings : Array[R12SemanticFinding]
    complete : Bool
    }

    R12ShxFont

    pub struct R12ShxFont {
    // private fields
    }

    Decoder for AutoCAD-86 SHX stroke fonts.

    R12ShxFont::bigfont_run

    fn R12ShxFont::bigfont_run(self : R12ShxFont, primary : R12ShxFont, text : String, packed_code : (Char) -> Int?, max_work? : Int) -> Result[R12GlyphRun, String]

    Use the STYLE's primary font and its BIGFONT together. The caller maps Unicode characters to this BIGFONT's packed code-page values.

    R12ShxFont::bigfont_vertical_run

    fn R12ShxFont::bigfont_vertical_run(self : R12ShxFont, primary : R12ShxFont, text : String, packed_code : (Char) -> Int?, max_work? : Int) -> Result[R12VerticalGlyphRun, String]

    Compose one vertical BIGFONT column using a caller-supplied code-page map. Characters outside the map use upright glyphs from the primary SHX face.

    R12ShxFont::glyph_run

    fn R12ShxFont::glyph_run(self : R12ShxFont, text : String, map? : (Char) -> Int, max_work? : Int) -> Result[R12GlyphRun, String]

    Read horizontal strokes. The optional encoding map translates Unicode scalar values to legacy shape numbers, leaving code-page selection to the caller.

    R12StyledDimension

    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
    }

    Supported R12 styling in WCS. Color values retain BYBLOCK and BYLAYER.

    R12StyledDimension::r12_dimension_obstacles

    fn R12StyledDimension::r12_dimension_obstacles(self : R12StyledDimension) -> Result[Array[Aabb2], String]

    Reserve one rendered dimension's lines, ticks, arrows and arc in WCS XY. Use only dimensions in the target drawing plane. The arc reserves a conservative full-circle box, as do the bounds of custom arrow primitives.

    R12TrueType

    pub struct R12TrueType {
    glyphs : Int
    horizontal_metrics : Int
    long_offsets : Bool
    cap : Double
    ascent : Double
    descent : Double
    // private fields
    }

    Immutable decoder for a single TrueType sfnt face. Font paths are never opened.

    R12TrueType::glyph_run

    fn R12TrueType::glyph_run(self : R12TrueType, text : String, tol? : Double, max_work? : Int) -> Result[R12GlyphRun, String]

    Decode Unicode glyph outlines in cap-height units. Hinting, kerning and shaping of complex scripts are outside the horizontal cmap decoder.

    R12TrueType::positioned_run

    fn R12TrueType::positioned_run(self : R12TrueType, glyphs : Array[R12PositionedGlyph], tol? : Double, max_work? : Int) -> Result[R12GlyphRun, String]

    Convert a positioned run (for example HarfBuzz output scaled to units per em) into normalized outlines usable by the R12 layout API.

    R12VerticalGlyphRun

    pub(all) struct R12VerticalGlyphRun {
    paths : Array[Array[Vec2]]
    advance : Double
    width : Double
    }

    An upright BIGFONT column. Paths advance down (negative Y) in cap-height units. The reported width is the maximum nominal cell width.

    R12ViewportView

    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]
    }

    Ordered ACAD/MVIEW v16 data from a paper-space viewport. The camera and editor settings are exposed without projecting model-space geometry.

    RawRecord

    pub(all) struct RawRecord {
    section : String
    kind : String
    tags : Array[Tag]
    }

    Ordered original tags for one group-0 record, including control records and XDATA.

    ReadDocument

    pub(all) struct ReadDocument {
    source : Bytes
    scan : TagScan
    records : Array[RawRecord]
    drawing : Drawing
    profile : ConformanceProfile
    read_warnings : Array[String]
    }

    Lossless source bytes plus parsed records. Reading and geometry have separate diagnostics.

    ReadDocument::audit_r12_fields

    fn ReadDocument::audit_r12_fields(self : ReadDocument) -> R12FieldAudit

    Check selected R12 geometry fields, declared table names, and local XDATA handle references. MissingLocalHandle describes this file only; external Xref databases are never opened.

    ReadDocument::diagnostics

    fn ReadDocument::diagnostics(self : ReadDocument) -> Array[Diagnostic]

    These categories identify the public stage at which a warning is exposed. DocumentWarning collects structural, derived-input and profile warnings.

    ReadDocument::r12_cell_attributes

    fn ReadDocument::r12_cell_attributes(self : ReadDocument, insert_record : Int, row : Int, column : Int) -> Result[Array[R12CellAttribute], String]

    Resolve a single zero-based INSERT cell without materializing the entire array. Coordinates are in the INSERT's containing space. Attached ATTRIB points already describe the first cell and only receive the grid offset. Constant ATTDEF points are transformed from the block definition.

    ReadDocument::r12_dimension_picture

    fn ReadDocument::r12_dimension_picture(self : ReadDocument, record_index : Int, tol : Double, limits? : ExpandLimits) -> Result[R12DimensionPicture, String]

    Read the local DIMSTYLE and expand the saved picture block separately from manufacturing contours. Expansion honors the normal geometry limits. Nested INSERTs in the picture, such as arrow blocks, follow the same limits.

    ReadDocument::r12_layout_attribute

    fn ReadDocument::r12_layout_attribute(self : ReadDocument, attribute : R12CellAttribute, shape : (R12FontStyle, String) -> R12GlyphRun?, max_points? : Int) -> Result[R12GlyphLayout, String]

    Lay out user-supplied glyphs for an R12 cell attribute. The shaper receives the original text and resolved STYLE metadata, including vertical flags. The font shaper owns the glyph orientation within the run. Nonzero extrusion thickness is outside this planar API.

    ReadDocument::r12_layout_vertical_attribute

    fn ReadDocument::r12_layout_vertical_attribute(self : ReadDocument, attribute : R12CellAttribute, shape : (R12FontStyle, String) -> R12VerticalGlyphRun?, max_points? : Int) -> Result[R12GlyphLayout, String]

    Place a vertical BIGFONT column using the attribute's OCS-derived basis. Horizontal Fit and Aligned would rescale a column by its width and are excluded.

    ReadDocument::r12_recompute_dimension

    fn ReadDocument::r12_recompute_dimension(self : ReadDocument, record_index : Int, tol : Double, definition? : R12Dimension, precision? : Int) -> Result[R12DimensionUpdate, String]

    Recompute from definition points without relying on the saved picture. Override the definition data to recompute after edits. The original record supplies the OCS and the per-entity DIMSTYLE overrides.

    ReadDocument::r12_refresh_bound_dimension

    fn ReadDocument::r12_refresh_bound_dimension(self : ReadDocument, binding : R12DimensionBinding, tol : Double, precision? : Int) -> Result[R12DimensionUpdate, String]

    Resolve the latest entity positions by handle, then recompute. Missing, ambiguous, or incompatible records fail without a stale-coordinate fallback.

    ReadDocument::r12_render_dimension

    fn ReadDocument::r12_render_dimension(self : ReadDocument, record_index : Int, update : R12DimensionUpdate, label_width? : Double) -> Result[R12StyledDimension, String]

    Style the latest recomputation without changing the drawing. A supplied label width cuts a gap or moves text and arrows on short linear spans.

    ReadDocument::r12_semantics

    fn ReadDocument::r12_semantics(self : ReadDocument) -> R12SemanticReport

    Read additional R12 entity data and local associations. This pass never expands INSERTs or changes which entities the XY checker accepts.

    ReadDocument::read_status

    fn ReadDocument::read_status(self : ReadDocument) -> ReadStatus

    Status of the record reader, separately from geometry coverage.

    ReadLimits

    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
    }

    Parsing budgets include malformed input; exhaustion stops with an explicit warning.

    ReadLimits::default

    fn ReadLimits::default() -> ReadLimits

    ReadStatus

    pub(all) enum ReadStatus {
    ReadComplete
    ReadWithWarnings
    ReadFailed
    }

    Record

    pub(all) struct Record {
    kind : String
    common : Array[Tag]
    subclasses : Array[Subclass]
    }

    一条记录:组码 0 开头的一串 tag。

    Record::all_of

    fn Record::all_of(self : Record, code : Int) -> Array[Tag]

    某个组码出现的所有 tag,按顺序。

    Record::count_code

    fn Record::count_code(self : Record, code : Int) -> Int

    一个组码在记录里出现了几次。

    LWPOLYLINE 的顶点就是同一组码重复出现(每个顶点一对 10/20), 靠这个数出有几个顶点。

    Record::effective_classes

    fn Record::effective_classes(self : Record) -> Array[String]

    这条记录在语义上有哪些类。

    新版本总是从 AcDbEntity 起头(实体通用字段),后面跟着自己那个类; 老版本只合成出「自己那个类」,补上 AcDbEntity 让两边形状一致。

    Record::get

    fn Record::get(self : Record, code : Int) -> Tag?

    在记录里找一个组码(公共部分 + 所有子类,按顺序)。

    只看组码、不看子类——需要区分同名组码时用 get_in。 这个函数适合那些含义到处都一样的组码(图层 8、线型 6 之类)。

    Record::get_double

    fn Record::get_double(self : Record, code : Int, default : Double) -> Double

    取一个组码的浮点值。没有就用给的默认值。

    默认值由调用方给而不是固定 0.0:坐标缺省成 0 是合理的, 但半径缺省成 0 就变成了「一个退化的圆」,性质完全不同。

    Record::get_in

    fn Record::get_in(self : Record, subclass : String, code : Int) -> Tag?

    在指定的子类里找组码。

    这是「组码含义随子类变」的正面用法:明确说出我要的是哪个类的字段。

    Record::get_int

    fn Record::get_int(self : Record, code : Int, default : Int) -> Int

    取一个组码的整数值。

    Record::get_string

    fn Record::get_string(self : Record, code : Int) -> String

    取一个组码的字符串值。没有就是空串。

    Record::has_subclass

    fn Record::has_subclass(self : Record, name : String) -> Bool

    表里的组码 70 在 AcDbSymbolTable 子类里是「表里有多少项」, 在具体记录的子类里另有含义。取字段时要指定子类。

    Record::is_legacy

    fn Record::is_legacy(self : Record) -> Bool

    这条记录是不是老格式(一个 100 标记都没有)。

    老格式的字段全在公共部分里,取字段照样用 get,不影响。

    Record::point

    fn Record::point(self : Record, n : Int) -> Vec3?

    取一条记录里第 n 个点(10/20/30 是第 0 个,11/21/31 是第 1 个)。

    缺 z 按 0 处理——平面图里点就在 z=0 平面上,缺 z 是常态。 缺 x 或 y 返回 None——那说明记录坏了,交给调用方决定怎么办 (本文件的选择是跳过并警告,而不是拿原点补)。

    Record::require_double

    fn Record::require_double(self : Record, code : Int) -> Result[Double, String]

    Record::require_int

    fn Record::require_int(self : Record, code : Int) -> Result[Int, String]

    Record::subclass_names

    fn Record::subclass_names(self : Record) -> Array[String]

    记录的子类名列表。

    老记录没有 100,这里按记录类型合成一个——CIRCLE 记录的字段 在语义上就属于 AcDbCircle。合成之后,报告和检查逻辑看到的记录形状 在新旧版本之间是一致的。

    合成表只列我们要解码的实体。认不出的记录类型返回空数组, 上层按「老格式实体」处理即可——它们的字段全在公共部分,本来就取得出来。

    Record::try_double

    fn Record::try_double(self : Record, code : Int) -> Result[Double?, String]

    Missing fields return None; type errors/nonfinite numbers return Err. Legacy get/as APIs remain permissive for compatibility.

    Record::try_int

    fn Record::try_int(self : Record, code : Int) -> Result[Int?, String]

    Report

    pub(all) struct Report {
    findings : Array[Finding]
    }

    检查报告。

    Report::count

    fn Report::count(self : Report, severity : Severity) -> Int

    统计某个严重程度的条数。

    Report::has_fatal

    fn Report::has_fatal(self : Report) -> Bool

    有没有致命问题。

    Report::has_incomplete_checks

    fn Report::has_incomplete_checks(self : Report) -> Bool

    是否存在输入恢复、覆盖限制、未转轮廓文字或无效检查参数。 只描述本次所选检查的完整性,不表示完整 DXF 兼容或可加工性。 保留 Finding 原来的分类,避免调用方依赖解析文字来判断完整性。

    Report::status

    fn Report::status(self : Report) -> CheckStatus

    Report::to_text

    fn Report::to_text(self : Report) -> String

    报告 → 纯文本:每条发现一行 [严重程度] [检查项] 说明, 末尾是统计和结论。CLI 和网页版都从这里取排版——两边永远不会打架。

    Report::verdict

    fn Report::verdict(self : Report) -> String

    一句话结论。检查项有限,没问题不等于万事大吉——措辞上 不替用户打包票。

    Section

    pub(all) struct Section {
    name : String
    records : Array[Record]
    }

    一个段。

    Severity

    pub(all) enum Severity {
    Info
    Warn
    Fatal
    }

    发现的严重程度。

    Subclass

    pub(all) struct Subclass {
    name : String
    tags : Array[Tag]
    }

    记录里的一段:由一个 100 子类标记开头的那些 tag。

    老版本(R10/R12)没有 100 标记,整条记录算作一个子类, 名字用记录类型名(见 subclass.mbt 的合成逻辑)。

    SvgError

    pub(all) enum SvgError {
    InvalidPreviewGeometry
    SvgByteLimit
    }

    Tables

    pub(all) struct Tables {
    layers : Array[Layer]
    linetypes : Array[String]
    text_styles : Array[String]
    block_records : Array[String]
    }

    TABLES 段。

    Tables::layer

    fn Tables::layer(self : Tables, name : String) -> Layer?

    按名字找图层。

    Tag

    pub(all) struct Tag {
    code : Int
    value : TagValue
    }

    一个 tag:组码 + 值。

    Tag::is_record_start

    fn Tag::is_record_start(self : Tag) -> Bool

    组码是不是标志一条新记录(0)。

    组码 0 的值就是记录类型名——CIRCLE / LINE / SECTION / EOF。 整个文件的骨架就是靠它切出来的。

    Tag::is_subclass_marker

    fn Tag::is_subclass_marker(self : Tag) -> Bool

    组码是不是子类标记(100)。

    这是 DXF 最特别的地方:100 的值是一个类名(AcDbEntity / AcDbCircle…), 它一出现,后面组码的含义就换成那个类的定义了。 同一个组码 70 在 AcDbSymbolTable 里是「最大条目数」,在图层记录里是「标志位」。

    Tag::new

    fn Tag::new(code : Int, value : TagValue) -> Tag

    Tag::to_display

    fn Tag::to_display(self : Tag) -> String

    记录的显示用名字(组码 + 值),出错信息里用。

    TagScan

    pub(all) struct TagScan {
    tags : Array[Tag]
    warnings : Array[String]
    encoding : Encoding
    }

    一次扫描的结果。

    警告而不是异常:DXF 大量来自第三方导出器,坏文件比想象中多, 「读了 90% 然后告诉你哪里坏了」比「抛异常什么都没读出来」有用得多。

    TagStream

    pub(all) struct TagStream {
    // private fields
    }

    Byte-linear streaming scanner with a bounded encoding prefix and growing line. Caller-owned input bytes are not freed by scanner limits.

    TagStream::encoding

    fn TagStream::encoding(self : TagStream) -> Encoding?

    TagStream::feed

    fn TagStream::feed(self : TagStream, chunk : Bytes) -> Array[Tag]

    TagStream::finish

    fn TagStream::finish(self : TagStream) -> Array[Tag]

    TagStream::is_limited

    fn TagStream::is_limited(self : TagStream) -> Bool

    Further feeds after exhaustion are ignored; partial tags are not a complete file.

    TagStream::new

    fn TagStream::new() -> TagStream

    TagStream::warnings

    fn TagStream::warnings(self : TagStream) -> Array[String]

    TagStream::with_legacy_decoder

    fn TagStream::with_legacy_decoder(limits : ReadLimits, decoder : (Int, Bytes) -> String?) -> TagStream

    The callback only receives unsupported legacy string values. Returning None preserves the fallback and emits a warning; the callback is trusted code.

    TagStream::with_limits

    fn TagStream::with_limits(limits : ReadLimits) -> TagStream

    TagType

    pub(all) enum TagType {
    Str
    I16
    I32
    I64
    F64
    Bool
    Bin
    }

    组码对应的数据类型。

    TagValue

    pub(all) enum TagValue {
    Str(String)
    I16(Int)
    I32(Int)
    I64(Int64)
    F64(Double)
    Bool(Bool)
    Bin(Bytes)
    }

    一个 tag 的值。

    有意做成强类型而不是「一律存字符串」:二进制格式里值本来就是分类型的, 而且取用时不用每次都重新解析文本(一张图几万个 tag,省下来的是实打实的)。

    TagValue::as_bool

    fn TagValue::as_bool(self : TagValue) -> Bool

    取布尔。整数非零为真。

    TagValue::as_double

    fn TagValue::as_double(self : TagValue) -> Double

    取浮点数。整数会转成浮点,其它类型返回 0。

    坐标组码理论上都是 F64,但现实里见过把整数写在坐标位上的文件, 所以整数也认。

    TagValue::as_int

    fn TagValue::as_int(self : TagValue) -> Int

    取整数。浮点会截断,其它类型返回 0。

    TagValue::as_string

    fn TagValue::as_string(self : TagValue) -> String

    取字符串。不是字符串时返回空串。

    Vec2

    pub(all) struct Vec2 {
    x : Double
    y : Double
    }

    平面上的一个点 / 向量。

    Vec2::add

    fn Vec2::add(self : Vec2, other : Vec2) -> Vec2

    Vec2::angle

    fn Vec2::angle(self : Vec2) -> Double

    极角,返回弧度,范围 (-π, π]。

    Vec2::approx_eq

    fn Vec2::approx_eq(self : Vec2, other : Vec2, tol : Double) -> Bool

    按容差判断是不是同一个点。

    Vec2::cross

    fn Vec2::cross(self : Vec2, other : Vec2) -> Double

    二维叉乘,返回一个标量(三维叉乘的结果是向量,二维退化成标量)。

    符号有几何含义:正表示 other 在 self 的逆时针一侧, 负表示顺时针一侧,零表示共线。判断点在直线的哪一侧、判断多边形绕向, 用的都是它。

    Vec2::distance

    fn Vec2::distance(self : Vec2, other : Vec2) -> Double

    两点距离。

    Vec2::dot

    fn Vec2::dot(self : Vec2, other : Vec2) -> Double

    点乘。

    Vec2::length

    fn Vec2::length(self : Vec2) -> Double

    模长。

    Vec2::new

    fn Vec2::new(x : Double, y : Double) -> Vec2

    Vec2::normalize

    fn Vec2::normalize(self : Vec2) -> Vec2

    单位化。零向量原样返回——退化几何(长度为零的线段)在真实图纸里存在, 不该让它把整个流程搞崩,交给检查环节去报。

    Vec2::perp

    fn Vec2::perp(self : Vec2) -> Vec2

    逆时针转 90 度的法向量。

    算「点在直线的哪一侧」和「线段往哪边偏移」时用。

    Vec2::rotate

    fn Vec2::rotate(self : Vec2, rad : Double) -> Vec2

    逆时针旋转 rad 弧度。

    Vec2::scale

    fn Vec2::scale(self : Vec2, k : Double) -> Vec2

    Vec2::sub

    fn Vec2::sub(self : Vec2, other : Vec2) -> Vec2

    self - other。

    Vec2::zero

    fn Vec2::zero() -> Vec2

    Vec3

    pub(all) struct Vec3 {
    x : Double
    y : Double
    z : Double
    }

    三维空间里的一个点 / 向量。

    DXF 的坐标组码都是三个一起出现(10/20/30 是 x/y/z), 所以解析出来的点一律是三维的,哪怕 z 恰好是 0。

    Vec3::cross

    fn Vec3::cross(self : Vec3, other : Vec3) -> Vec3

    Vec3::dot

    fn Vec3::dot(self : Vec3, other : Vec3) -> Double

    Vec3::is_zero

    fn Vec3::is_zero(self : Vec3, tol : Double) -> Bool

    按容差判断是不是零向量。

    Vec3::length

    fn Vec3::length(self : Vec3) -> Double

    Vec3::new

    fn Vec3::new(x : Double, y : Double, z : Double) -> Vec3

    Vec3::normalize

    fn Vec3::normalize(self : Vec3) -> Vec3

    单位化。零向量原样返回,理由和 Vec2::normalize 一样。

    Vec3::sub

    fn Vec3::sub(self : Vec3, other : Vec3) -> Vec3

    Vec3::xy

    fn Vec3::xy(self : Vec3) -> Vec2

    丢掉 z,投影到平面上。加工检查是二维的,用这个把三维点降下来。

    Vec3::zero

    fn Vec3::zero() -> Vec3

    WorldExpansion

    pub(all) struct WorldExpansion {
    placed : Array[WorldPlaced]
    warnings : Array[String]
    }

    WorldExpansion::r12_dimension_obstacles

    fn WorldExpansion::r12_dimension_obstacles(self : WorldExpansion, plane_tol : Double, max_boxes? : Int) -> Result[Array[Aabb2], String]

    Reserve WCS XY wire edges and dots from a world expansion. Faces reserve their full projected bounds. Text boxes should be measured by the caller and appended. The expansion's diagnostics remain applicable.

    WorldFlat

    pub(all) enum WorldFlat {
    Outline3(points~ : Array[Vec3], closed~ : Bool)
    Dot3(at~ : Vec3)
    Label3(at~ : Vec3, height~ : Double, value~ : String)
    Face3(corners~ : Array[Vec3])
    Empty3
    }

    WCS results preserve Z. Empty3 retains the entity record, not a geometry claim.

    WorldPlaced

    pub(all) struct WorldPlaced {
    entity : Entity
    layer : String
    flat : WorldFlat
    instances : Array[InsertInstance]
    }

    angle_span

    fn angle_span(from : Double, to : Double) -> Double

    从 from 逆时针转到 to 跨过的角度,结果落在 [0, 2π)。

    arc_from_bulge

    fn arc_from_bulge(a : Vec2, b : Vec2, bulge : Double) -> BulgeArc

    bulge → 圆弧参数。

    返回值一律描述逆时针弧(和 ezdxf 的 bulge_to_arc 同款约定): bulge 为负时起止角已经对调,从 start_angle 逆时针走到 end_angle 覆盖的就是这段弧的点集。离散只关心点集,遍历方向在这里就消化掉。

    两个公式都是从源码核对的:圆心在弦中垂线上, r = 弦长·(1+b²)/(4b)(带符号——负 bulge 会自然镜像到另一侧), 方向角 = 弦方向 + π/2 − 2·atan(b)。

    arc_points

    fn arc_points(center : Vec2, radius : Double, start_angle : Double, end_angle : Double, tol : Double) -> Array[Vec2]

    圆弧 → 折线点列(含首尾两点)。

    build_drawing

    fn build_drawing(scan : TagScan) -> Drawing

    把 tag 流切成图纸骨架。

    绝不 panic:坏结构变成警告。「读了 90% 然后告诉你哪里坏了」 比「抛异常什么都没读出来」有用得多——真实世界的 DXF 大量来自第三方 导出器,损坏的文件比想象中多。

    circle_points

    fn circle_points(center : Vec2, radius : Double, tol : Double) -> Array[Vec2]

    整圆 → 折线点列,从 0°(正 x 方向)起步。

    不重复首点——闭合性用外层的 closed 标志表达, 和多段线顶点的表示一致。

    code_type

    fn code_type(code : Int) -> TagType

    查一个组码对应什么类型。

    区间照抄 ezdxf 的 lldxf/types.py(已核对)。没列到的组码一律当字符串—— 这不只是兜底:DXF 里「名字」类的字段散落在各个区间之外, 而字符串是唯一能安全容纳未知内容的类型。

    decide_encoding

    fn decide_encoding(data : Bytes) -> Encoding

    从文件开头判断该用什么编码。

    仅探测前1024字节;声明不在这个范围时会使用回退编码。

    decode_text

    fn decode_text(data : Bytes, enc : Encoding) -> String

    按指定编码把字节解成字符串。

    遇到不认识的代码页不静默乱码:降级成 Latin-1 并让调用方拿到一条警告。 乱码最坏的地方是它看起来「有内容」——用户会以为是文件本身有问题, 而不是工具不支持这个编码。

    ellipse_points

    fn ellipse_points(center : Vec3, major : Vec3, ratio : Double, start_param : Double, end_param : Double, tol : Double) -> Array[Vec2]

    椭圆(弧)→ 折线点列。

    点 = 圆心 + 长轴·cos p + 短轴·sin p——p 是参数,不是极角, 椭圆上等参数的点和等角度的点不是一回事。取到整椭圆时不重复首点。

    find_header_var

    fn find_header_var(sections : Array[Section], name : String) -> String?

    从 HEADER 段读一个变量。

    HEADER 变量没有 0 分隔,是成对挂在 SECTION 记录里的: 9 / $ACADVER 后面紧跟一个 tag 就是它的值。

    is_binary_code

    fn is_binary_code(code : Int) -> Bool

    是不是二进制块组码。

    is_handle_code

    fn is_handle_code(code : Int) -> Bool

    是不是句柄组码(5 / 105)。

    句柄是对象在文件内的唯一编号(十六进制字符串),330 之类的引用指向它。 105 是 DIMSTYLE 专用的句柄组码——同一个含义用了两个码,是历史包袱。

    is_point_code

    fn is_point_code(code : Int) -> Bool

    是不是坐标组码(10-39)。

    DXF 的坐标是成组出现的:10/20/30 是一个点的 x/y/z, 11/21/31 是第二个点,以此类推。规律是「个位数定轴、十位数定第几个点」。

    is_pointer_code

    fn is_pointer_code(code : Int) -> Bool

    是不是对象引用组码(软指针 / 硬指针)。

    值是另一个对象的句柄。330 是「所有者」,360 之类是硬引用。 靠这些把文件里散落的记录连成一张引用图。

    is_xdata_code

    fn is_xdata_code(code : Int) -> Bool

    是不是扩展数据(XDATA)组码(1000-1071)。

    第三方程序把自己的信息挂在实体上用的。解析时可以整段跳过, 但要原样保留——否则读一遍写回去就把别人的数据弄丢了。

    load_r12_shx

    fn load_r12_shx(data : Bytes) -> Result[R12ShxFont, String]

    load_r12_truetype

    fn load_r12_truetype(data : Bytes) -> Result[R12TrueType, String]

    Decode TrueType outlines with Unicode cmap 4/12 and horizontal metrics.

    normalize_angle

    fn normalize_angle(rad : Double) -> Double

    把角度(弧度)归一到 [0, 2π)。

    DXF 里圆弧的起止角是度数、逆时针、而且可以大于 360 (370 度这种写法真实存在),所以算圆弧跨度之前必须归一到同一圈里, 否则 370 - 10 会算成 360 度而不是 0 度。

    parse_blocks

    fn parse_blocks(section : Section) -> Blocks

    解析 BLOCKS 段:每个 BLOCK 到 ENDBLK 之间的记录就是块的内容, 走和 ENTITIES 段同一套翻译(parse_records)。

    parse_entities

    fn parse_entities(section : Section) -> Entities

    解析一个段里的实体。

    入口是 ENTITIES 段;将来块定义(BLOCKS 段)里的实体也走这里。

    parse_header

    fn parse_header(section : Section) -> Header

    从 HEADER 段解析出变量表。

    走法:碰到 9 就开一个新变量,把后面所有不是 9 的 tag 全收进去, 直到下一个 9 或者段结束。不能按「两个两个一组」扫——坐标类的变量 有三个值,按对扫会把 y/z 丢掉,$EXTMIN 就只剩一个 x 了。

    parse_tables

    fn parse_tables(section : Section) -> Tables

    解析 TABLES 段。

    只认这四张表——别的一律跳过,但跳过是按结构跳的(认 TABLE/ENDTAB 的层次),不是按关键字。否则遇到没见过的表名会把它的内容当成外层记录。

    point_code_parts

    fn point_code_parts(code : Int) -> (Int, Int)?

    把坐标组码拆成 (第几个点, 哪个轴)。

    轴用 0/1/2 表示 x/y/z。不是坐标组码时返回 None。

    例:10 → (0, 0)、21 → (1, 1)、32 → (2, 2)。

    polyline_points

    fn polyline_points(vertices : Array[PolyVertex], closed : Bool, tol : Double) -> Array[Vec2]

    多段线顶点序列 → 折线点列(bulge 段换成圆弧点)。

    闭合的不重复首点;放开的一个不少,第一个点还是第一个顶点。

    r12_avoid_dimension_labels

    fn r12_avoid_dimension_labels(labels : Array[R12DimensionLabelBox], obstacles : Array[Aabb2], step : Double, clearance? : Double, rings? : Int, max_checks? : Int) -> Result[Array[R12DimensionLabelPosition], String]

    Search nearby anchors for a drawing's dimension labels. Supply the WCS XY boxes of every obstacle to reserve. Accepted and pending labels also reserve space. Result order corresponds to input order.

    r12_positioned_fonts

    fn r12_positioned_fonts(runs : Array[R12PositionedFontRun], tol? : Double, max_work? : Int) -> Result[R12GlyphRun, String]

    Join fallback spans in visual order under one outline budget. Each face uses its own cap-height normalization and shares the horizontal baseline.

    read_document

    fn read_document(source : Bytes) -> ReadDocument

    Preserve unrecognized fields and record types within the scanning budgets. source also retains comments, formatting and bytes after EOF that the scanner ignores. A budget-limited records prefix must not be treated as the complete file.

    read_document_with_legacy_decoder

    fn read_document_with_legacy_decoder(source : Bytes, limits : ReadLimits, decoder : (Int, Bytes) -> String?) -> ReadDocument

    Read using a trusted callback for unsupported legacy string values.

    read_document_with_limits

    fn read_document_with_limits(source : Bytes, limits : ReadLimits) -> ReadDocument

    Raw source is caller-owned; budgets bound scanning and derived representations.

    scan_tags

    fn scan_tags(data : Bytes) -> TagScan

    把 ASCII DXF 的字节流切成 tag。

    碰到 EOF 就停——真实的 DXF 文件在 EOF 之后还可能有垃圾字节 (实测 ezdxf 的语料里就有 R12_with_trash_beyond_EOF.dxf), 那些不是数据,继续解会把噪声当成 tag。

    这是整份扫描的入口;分块扫描走 stream.mbt 的 TagStream。 两个入口共用同一套状态机(这里就是它的一次性封装), 行为不会有两套。

    scan_tags_with_limits

    fn scan_tags_with_limits(data : Bytes, limits : ReadLimits) -> TagScan

    Explicit bounded scan; exhaustion leaves a diagnostic and a partial tag prefix.

    severity_label

    fn severity_label(sev : Severity) -> String

    严重程度的中文标签。

    spline_points

    fn spline_points(degree : Int, knots : Array[Double], control_points : Array[Vec3], weights : Array[Double], tol : Double) -> Array[Vec2]

    样条 → 折线点列(xy 投影)。

    参数域是 [U[p], U[n+1]]——首尾各 p 个钳制节点的写法,端点正好是 首末控制点。在这个区间里自适应细分;数据不自洽的退回单点。

    spline_points_checked

    fn spline_points_checked(degree : Int, knots : Array[Double], control_points : Array[Vec3], weights : Array[Double], tol : Double) -> Result[Array[Vec2], String]

    将连续、正权重 NURBS 曲线投影到 XY 并离散。 无效节点、非正权重、非有限坐标、断裂曲线或资源上限返回错误。

    unit_name

    fn unit_name(code : Int) -> String

    单位编号的中文名。

    unit_to_mm

    fn unit_to_mm(code : Int) -> Double?

    一个单位编号对应多少毫米。没指定(0)或认不出时返回 None—— 不猜,猜错了尺寸差几百倍。