feat(junction): add structure and standards contract
This commit is contained in:
1 parent
8d6f531377
commit
61cf276745
13 files changed
+843
-1
No files matched your search
@@ -272,3 +272,20 @@ readLayer('layers/intersection_surface.geojson')
|
||||
// Correct: project compiler-owned properties from their published layer.
|
||||
readLayer('layers/road_surface.geojson')
|
||||
```
|
||||
|
||||
## 14. Junction structure and standards profile
|
||||
|
||||
Stage-0 JunctionTools structure is compiler-owned and versioned independently
|
||||
of the direct-edit document. `buildJunctionStructure(input)` must return
|
||||
`junction-structure/v1` with unique stable object keys, readable labels, and
|
||||
explicit arm/corner/facility references; it must reject duplicate keys,
|
||||
unknown references, and an effective arm count that differs from the supplied
|
||||
arms. It must not infer missing arms from an internal `2x1`/`2x2` layout.
|
||||
|
||||
`CN_URBAN_DEFAULT_PROFILE` is the immutable `cn-urban-default` profile. Use
|
||||
`cloneProfile()` before applying project-specific changes and
|
||||
`validateStandardsProfile()` at the boundary. Rules distinguish recommended,
|
||||
warning, and blocking/invariant fields; a profile is metadata and rule
|
||||
configuration, not a client-side save decision. Keep the compiler as the sole
|
||||
producer of structure and diagnostics so the client cannot reclassify a
|
||||
junction from node counts.
|
||||
@@ -0,0 +1,4 @@
|
||||
{"file":".trellis/spec/backend/direct-edit-api.md","reason":"Validation must preserve the solver/API invariant and revision semantics."}
|
||||
{"file":".trellis/spec/frontend/direct-edit-client.md","reason":"Checks preview, baseline and handle ownership regressions."}
|
||||
{"file":".trellis/spec/frontend/quality-guidelines.md","reason":"Provides client test and quality expectations."}
|
||||
{"file":".trellis/spec/guides/cross-layer-thinking-guide.md","reason":"Checks that compiler-owned classification and diagnostics are not duplicated in the UI."}
|
||||
@@ -0,0 +1,137 @@
|
||||
# JunctionTools 行业规范化设计
|
||||
|
||||
## 边界与职责
|
||||
|
||||
JunctionTools 是编译结果的局部编辑工作区,不是另一套地图或另一套几何引擎。它只显示当前路口及关联道路,所有几何推导和拓扑判断仍由编译器完成。
|
||||
|
||||
| 层 | 责任 | 不负责 |
|
||||
| --- | --- | --- |
|
||||
| 编译层 | 识别有效道路臂与形态、生成核心/角部/设施几何、构造结构摘要、执行几何与规范校验 | 组件状态、选择样式、表单布局 |
|
||||
| 服务/API 层 | 以同一 revision 提供结构、诊断、手柄、局部预览与保存;返回稳定对象键和可读标签 | 由客户端重新计算拓扑或范围 |
|
||||
| 客户端 | 局部画布、对象选择、表单、全局/局部覆盖、诊断解释和参考层呈现 | 根据节点数分类、猜测引用 GeoJSON `type` 语义、绕过校验保存 |
|
||||
|
||||
现有 direct-edit revision、草稿、预览、放弃、保存和冲突保护是底座。新结构只能旁路扩展这些协议,不能另建一条无版本保护的保存路径。
|
||||
|
||||
## 规范化对象合约
|
||||
|
||||
每次状态/预览响应在现有路口描述之上提供只读 `junctionStructure`。其对象键内部稳定但不作为默认 UI 标题;所有对象均附带 `label`、`geometryRef`、`editable` 和 `validationRefs`。
|
||||
|
||||
```ts
|
||||
type JunctionStructure = {
|
||||
junctionKey: string;
|
||||
label: string;
|
||||
shape: {
|
||||
kind: 'cross' | 'offset-cross' | 't-junction' | 'multi-arm' | 'unsupported';
|
||||
label: string;
|
||||
effectiveArmCount: number;
|
||||
throughPairCount: number;
|
||||
};
|
||||
arms: RoadArm[];
|
||||
corners: JunctionCorner[];
|
||||
facilities: Crossing | StopLine | IslandOrMedian | SidewalkTurn | Signal[];
|
||||
standards: StandardsEvaluation;
|
||||
reference?: ReferenceComparison;
|
||||
};
|
||||
|
||||
type RoadArm = {
|
||||
key: string;
|
||||
label: string;
|
||||
heading: number;
|
||||
directionality: 'one-way' | 'two-way' | 'unknown';
|
||||
carriageway: { laneCount?: number; effectiveWidthMeters?: number };
|
||||
pedestrian?: { connected: boolean; bicycleConnected?: boolean };
|
||||
geometryRef: string;
|
||||
overrideState: OverrideState;
|
||||
};
|
||||
|
||||
type OverrideState = {
|
||||
mode: 'global' | 'local';
|
||||
inheritedFrom?: string;
|
||||
resetToGlobalAvailable: boolean;
|
||||
};
|
||||
```
|
||||
|
||||
`Corner` 通过相邻道路臂键表达归属,而不是以四角索引假定十字路口;`Crossing` 和 `StopLine` 都显式关联道路臂和彼此的对象键;`Signal` 只表达现有设施和关联关系。没有输入证据的道路臂、岛、横道、停止线或信号不得在 T 字、多臂或单行道路中被虚构。
|
||||
|
||||
### 全局与局部覆盖
|
||||
|
||||
参数定义为 `scope=global | object`,并记录生效来源。全局写入影响集合中的所有适用对象;局部写入只影响选定对象。用户选择“单独调整”才创建局部值,选择“恢复全局”删除局部覆盖并立即以全局值预览。
|
||||
|
||||
不能机械地把任意全局参数复制到所有对象。编译层应只暴露对该对象和路口形态有效的参数,例如 T 字没有第四角的局部圆角;单行道路没有假想的对向车道宽度。
|
||||
|
||||
## 工作区信息架构
|
||||
|
||||
```text
|
||||
┌ 标题(可读路口名)· 实际形态 · 中国城市道路 · 参考模式 · 草稿状态 ┐
|
||||
├ 道路臂 / 角部 / 设施 ┬ 当前路口局部画布 ┬ 参数与诊断 ┤
|
||||
│ 可读名称、类型、状态 │ 道路标签、方向、选区、手柄、参考叠加、诊断定位 │ 对象名、作用域、字段、恢复全局、规则 │
|
||||
├──────────────────────────────────────────────────────────────────────────┤
|
||||
│ 撤销 · 重做 · 重置当前对象 · 放弃草稿 · 应用预览 · 保存 │
|
||||
└──────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
- 顶栏只保留决策性状态;内部 node/cluster ID 可以在调试信息中出现,绝不占主标题。
|
||||
- 左栏以“道路臂、角部、过街与控制设施”分组,条目使用道路名;无法取得名称时使用稳定的“道路 1、道路 2”并在画布同色标注。
|
||||
- 中央画布是隔离的局部范围。对象呈现必须支持 `default`、`hover`、`selected`、`warning`、`blocking` 和 `disabled`,并能显示代表同一对象的多个几何片段。
|
||||
- 选择来源无差别:列表点击、地图点击、诊断“定位”或手柄聚焦都写入唯一 `selectedObjectKey`。右栏订阅该键,不根据最近修改的字段猜测上下文。
|
||||
- 参数输入使用支持单位、步进上下键、范围和无效态的现有成熟组件。拖动产生的预览与表单使用同一约束值及同一正方向;如果没有安全的手柄,保留表单但明确原因。
|
||||
|
||||
## 标准档与校验合约
|
||||
|
||||
标准档是版本化数据,不是散落在组件中的魔法常量。
|
||||
|
||||
```ts
|
||||
type StandardsProfile = {
|
||||
id: string;
|
||||
label: string;
|
||||
jurisdiction: string;
|
||||
version: string;
|
||||
sources: Array<{ title: string; edition?: string; clause?: string; url?: string }>;
|
||||
applicability: { roadClasses: string[]; designSpeedsKph?: number[]; shapeKinds: string[] };
|
||||
rules: Array<{
|
||||
id: string;
|
||||
objectKinds: string[];
|
||||
recommended?: Range;
|
||||
warning?: Range;
|
||||
blocking?: Range | GeometryInvariant;
|
||||
level: 'guidance' | 'hard-invariant';
|
||||
}>;
|
||||
projectOverrides?: Record<string, unknown>;
|
||||
};
|
||||
```
|
||||
|
||||
首个档案 `cn-urban-default` 记录来源、适用道路等级、设计速度和项目覆盖项。内容按三种层次执行:
|
||||
|
||||
1. **设计建议**:推荐范围和警告范围,允许保存,例如舒适圆角、优选横道尺度。
|
||||
2. **规范下限/项目约束**:由配置给出阻塞范围,例如适用车道宽度、有效步行带和停止线净距。
|
||||
3. **几何不变量**:不依赖地域数值,始终阻塞,例如自交、反向停止线、横道未覆盖可用车行道、步行路径断裂、对不存在道路臂的设施生成。
|
||||
|
||||
校验响应必须包含 `ruleId`、严重度、对象键、可读信息、受影响几何和建议动作。客户端以这些字段高亮对象和表单字段;禁止只返回 node/segment ID 或不可操作的 alert。
|
||||
|
||||
## 数据流
|
||||
|
||||
```text
|
||||
OSM + area config + direct-edit revision + optional reference GeoJSON
|
||||
-> junction topology / effective-arm classification
|
||||
-> geometry plan + junctionStructure + profile evaluation
|
||||
-> compiled layers, handles, diagnostics, reference comparison
|
||||
-> /api/state and preview/save responses
|
||||
-> isolated JunctionTools canvas + selectedObjectKey + parameter editor
|
||||
-> constraint patch -> preview -> validation -> revision-protected save
|
||||
```
|
||||
|
||||
结构摘要与诊断必须来自同一编译快照,避免画布显示一个形态、右栏使用另一个草稿状态。预览失败或 `blocking` 时仍返回足够的对象和几何引用,使用户能定位问题,但不得生成可保存的成功 revision。
|
||||
|
||||
## GeoJSON 参考层
|
||||
|
||||
现有 `convertGeoJson()` 的 GCJ-02 到 WGS84 转换、`referenceFile` 和 `inspectReference()` 是唯一入口。参考比较对象记录:原始/转换后的坐标状态、来源文件、可见性、透明度、空间匹配置信度、中心偏移、边界框差、面积差、主方向差和未匹配原因。
|
||||
|
||||
匹配规则以相交、距离、包络和方向等空间证据为基础。原始 `properties.type` 只可作为调试计数,不能决定其属于路面、人行道、横道或导流岛。未来的建议工作流为“识别高置信度差异 -> 展示建议与依据 -> 用户接受为草稿”;参考数据不能直接覆写当前几何。
|
||||
|
||||
## 兼容、渐进发布与回退
|
||||
|
||||
- 没有标准档、结构摘要或参考文件时,现有 JunctionTools 保持原有编辑能力和普通路口文案。
|
||||
- Stage 1 的结构和诊断先只读旁路发布;每项硬阻塞在具有 fixture、明确来源和回归测试前不接入保存门禁。
|
||||
- 参考层失败时仅关闭叠加和比较,不改变编译几何、草稿或保存行为。
|
||||
- 每一类高级设施都以可关闭的对象分组接入;关闭后保留道路臂、角部、横道、停止线和信号的既有能力。
|
||||
- 保存协议与 revision 冲突处理不变;任何新字段缺失时客户端要有兼容降级,不阻断旧区域配置。
|
||||
@@ -0,0 +1,5 @@
|
||||
{"file":".trellis/spec/backend/direct-edit-api.md","reason":"Defines the pure solver, preview/save, revision and invariant contract that all JunctionTools data must preserve."}
|
||||
{"file":".trellis/spec/backend/road-revision-storage.md","reason":"Defines immutable active-revision storage and snapshot compatibility requirements."}
|
||||
{"file":".trellis/spec/frontend/direct-edit-client.md","reason":"Defines client ownership for handles, previews, drafts and drag direction semantics."}
|
||||
{"file":".trellis/spec/frontend/type-safety.md","reason":"Defines typed boundary expectations for new state and API projections."}
|
||||
{"file":".trellis/spec/guides/cross-layer-thinking-guide.md","reason":"Applies to the compiler-service-client structure and diagnostic contract."}
|
||||
@@ -0,0 +1,127 @@
|
||||
# JunctionTools 行业规范化实施计划
|
||||
|
||||
## 实施原则
|
||||
|
||||
按“先理解、再选择、后编辑、最后扩展设施”推进。每一阶段都应可独立验证、单独回退,且只在该阶段通过质量门禁后提交。除已稳定的 direct-edit 参数外,不提前把未完成验证的规范规则变成保存门禁。
|
||||
|
||||
## Stage 0:数据契约、规范来源与回归基线
|
||||
|
||||
**交付物**
|
||||
|
||||
- 定义 `junctionStructure`、对象键、`selectedObjectKey`、覆盖状态、诊断和参考比较的 TypeScript/服务端契约。
|
||||
- 创建 `cn-urban-default` 的版本、来源、适用条件、项目覆盖规则和“建议/警告/硬不变量”分层;数值不明的条目先以配置占位和 fixture 表达,不散落硬编码。
|
||||
- 盘点现有 simple/complex 编译输出、direct-edit 约束、信号与参考 GeoJSON 的字段归属,明确复用点和兼容字段。
|
||||
- 固化最小真实样例:普通四臂、T 字、偏置十字、多臂、单行/单车道道路以及带/不带参考 GeoJSON 的样例。为每类保存基线形态、有效道路臂和设施计数。
|
||||
|
||||
**验收与测试**
|
||||
|
||||
- 契约单测覆盖对象键稳定性、T 字不产生第四臂、单行道路不产生假想对向车行道。
|
||||
- fixture 断言内部 `2×1/2×2` 布局不会作为最终形态文案。
|
||||
- 输出一份规范来源清单,明确哪些规则是项目建议、哪些是保存不变量。
|
||||
|
||||
**提交边界**:`test(junction): add standards fixtures and structure contract`。仅新增契约/fixture/测试,不改用户可见保存行为。
|
||||
|
||||
## Stage 1:统一只读结构与标准面板
|
||||
|
||||
**交付物**
|
||||
|
||||
- 编译层从 simple 与 complex 结果构造同一 `junctionStructure`,发布道路臂、角部、横道、停止线、已存在信号和形态摘要。
|
||||
- 服务端将结构、当前标准档和 `pass/warning/blocking` 诊断纳入 state、预览响应与 debug 投影。
|
||||
- JunctionTools 顶栏、左侧对象树和右侧只读标准面板接入结构,使用可读道路名或“道路 1/2”回退,不显示内部 ID。
|
||||
- 诊断可定位到一个对象并在局部画布中高亮;字段级问题先能聚焦再谈阻塞保存。
|
||||
|
||||
**验收与测试**
|
||||
|
||||
- simple、complex、T 字、偏置和多臂 fixture 的对象清单、数量和标签通过单测。
|
||||
- 客户端单测验证列表、地图与参数上下文共用同一 `selectedObjectKey`。
|
||||
- 手工验证独立工作区不渲染无关主地图要素,信号存在时可见。
|
||||
|
||||
**提交边界**:`feat(junction): expose unified structure and standards diagnostics`。问题可通过关闭新面板或回退结构字段恢复旧工作区。
|
||||
|
||||
## Stage 2:选择模型与全局/局部覆盖交互
|
||||
|
||||
**交付物**
|
||||
|
||||
- 完成左栏、中心局部画布、右栏和底栏的信息架构;地图点击、列表、手柄和诊断定位严格映射到同一对象。
|
||||
- 为道路臂、角部和设施实现“使用全局值 -> 单独调整 -> 恢复全局值”的通用交互及可读影响范围。
|
||||
- 完成当前对象重置、全草稿放弃、撤销/重做与选择切换后的草稿一致性;区分进入时基线和预览基线。
|
||||
- 将手柄方向、表单单位、上下键步进和范围提示统一到现有 direct-edit 约束。
|
||||
|
||||
**验收与测试**
|
||||
|
||||
- 点击同一对象的多个几何片段仍进入同一个表单;选择切换不能遗留旧对象字段。
|
||||
- 只修改局部覆盖时只影响选定对象;恢复全局后重新继承全局预览。
|
||||
- 重置当前对象与放弃草稿分别恢复正确范围,版本冲突路径保持现有行为。
|
||||
- 覆盖现有“拖左向右”方向回归的四个方位及复杂路口样例。
|
||||
|
||||
**提交边界**:`feat(junction): add object selection and scoped overrides`。可回退为现有参数面板,不改底层几何。
|
||||
|
||||
## Stage 3:已稳定道路、角部与过街参数的规范化编辑
|
||||
|
||||
**交付物**
|
||||
|
||||
- 将现有进口宽度、进口退让(替代不清晰的 `cutback` 文案)、角部圆角、斑马线退让/尺寸、停止线偏移接入对象表单和地图手柄。
|
||||
- 为车道/道路臂宽度、横道全宽覆盖、停止线-横道方向/净距、角部净空、步行连续性和核心/角部多边形有效性提供校验器。
|
||||
- 将明确的几何不变量设为 `blocking`;项目建议和适用规范范围按 `pass/warning` 表达。阻塞时高亮实际字段与几何,不弹出孤立 alert。
|
||||
|
||||
**验收与测试**
|
||||
|
||||
- 每条规则至少有通过、警告、阻塞 fixture;阻塞保存、警告可预览保存、诊断可定位。
|
||||
- T 字、单行和单车道 fixture 证明无虚构设施/对向道路假设。
|
||||
- 保存、预览、撤销/重做、草稿放弃、版本冲突和现有普通路口回归通过。
|
||||
|
||||
**提交边界**:`feat(junction): validate stable geometry controls`。如配置或校验发现问题,先将规则降为诊断,保留硬几何不变量。
|
||||
|
||||
## Stage 4:参考 GeoJSON 叠加与差异比较
|
||||
|
||||
**交付物**
|
||||
|
||||
- 接入原始与转换后坐标信息、显示/隐藏、透明度和空间匹配比较。
|
||||
- 呈现中心、bbox、面积、方向和未匹配原因,且明确参考数据只读。
|
||||
- 为高置信度空间匹配设计建议对象,但本阶段不得写入草稿或自动修改几何。
|
||||
|
||||
**验收与测试**
|
||||
|
||||
- GCJ-02 转换、缺失文件、不同 geometry 类型、匹配/未匹配和关闭参考层都有测试。
|
||||
- 叠加开关不改变编译输出、revision 或保存请求;原始 `type` 不出现在可编辑字段中。
|
||||
|
||||
**提交边界**:`feat(junction): add reference geometry comparison`。出错时完全关闭参考层即可回退。
|
||||
|
||||
## Stage 5:高级设施和形态适配
|
||||
|
||||
**交付物**
|
||||
|
||||
- 基于真实样例逐项接入导流岛、中央分隔、非机动车过街、无障碍连续路径和信号几何关联。
|
||||
- 每项设施必须有对象模型、可读标签、选择/高亮、覆盖语义、适用形态和独立的几何校验;不得由 `2×1/2×2` 或道路数量硬编码决定。
|
||||
- 建立“形态适配矩阵”:T 字、十字、偏置十字、多臂、单行和单车道下哪些设施可出现、不可出现或需手动确认。
|
||||
|
||||
**验收与测试**
|
||||
|
||||
- 每种新设施至少一个真实 OSM fixture、一个不适用形态 fixture 和一个保存/回退案例。
|
||||
- 信号仅作为已有对象与几何关联展示,未实现相位编辑前不承诺控制逻辑。
|
||||
|
||||
**提交边界**:每一设施类别独立提交,例如 `feat(junction): add median and island facilities`,避免把未成熟设施与基本编辑器绑定。
|
||||
|
||||
## 每阶段质量门禁
|
||||
|
||||
1. 运行相关 Node/编译单测与客户端单测,增加 fixture 前先说明其覆盖的形态和不变量。
|
||||
2. 运行 `npm run test`、`npm run test:client:unit -- --run`、`npm run test:client`、`npm run format:check`、`npm run build`。
|
||||
3. 对会影响交互或地图图层的阶段再运行 `npm run test:e2e`,并人工检查局部画布、对象高亮、手柄方向、上下键、草稿/放弃/冲突和普通/复杂路口回归。
|
||||
4. 每阶段提交前执行 Trellis 全面检查;只提交该阶段的代码、测试与文档,`test-results/` 保持未跟踪。
|
||||
|
||||
## 风险与回退点
|
||||
|
||||
| 风险 | 控制方式 | 回退 |
|
||||
| --- | --- | --- |
|
||||
| 规范数值被误认为全国统一法定阈值 | profile 必须记录来源、版本、适用条件和项目覆盖项 | 将规则留为建议/警告,移除保存门禁 |
|
||||
| 新结构与旧草稿不一致 | 同一编译快照生成 structure、diagnostics、handles 和 preview | 客户端降级到既有描述/参数面板 |
|
||||
| 复杂形态生成虚构对象 | effective-arm 分类为唯一输入,fixture 覆盖 T 字/单行/多臂 | 对不支持形态回退普通路口渲染 |
|
||||
| 参考数据错误影响成果 | 参考层只读、独立开关、绝不直接写草稿 | 完全隐藏参考层,不影响 native 输出 |
|
||||
| 高级设施超出可靠输入 | 每类设施单独交付,先建立真实样例和适配矩阵 | 关闭该设施分组,保留基础对象 |
|
||||
|
||||
## 启动前检查
|
||||
|
||||
- [ ] PRD、设计和实施计划已由用户按最新版本确认。
|
||||
- [ ] 为当前执行阶段建立真实的 `implement.jsonl` 与 `check.jsonl` 上下文条目。
|
||||
- [ ] 读取后端与前端相关规范,并将 Stage 0 的相关文件与测试范围列入任务上下文。
|
||||
- [ ] 不在用户确认前执行 `task.py start`、修改产品代码或创建实现提交。
|
||||
@@ -0,0 +1,88 @@
|
||||
# JunctionTools 行业规范化
|
||||
|
||||
## 目标与用户价值
|
||||
|
||||
将 JunctionTools 从当前的局部参数面板演进为一个独立、可视化、面向中国城市道路场景的路口编辑器。它必须用用户能辨识的道路、角部和设施对象表达简单与复杂路口,并在编辑前后明确展示几何后果和规范风险。
|
||||
|
||||
用户应当能够在一个只显示当前路口及关联道路的工作区中,理解系统识别出的路口形态、选择一个具体对象、用地图手柄或表单编辑它,并知道当前值是推荐、需复核还是不可保存。编辑不要求理解 OSM node ID、segment ID、内部 cluster 或模板名。
|
||||
|
||||
## 已确认的产品原则
|
||||
|
||||
- 默认规范档为“中国城市道路”。MUTCD/FHWA、NACTO 仅是后续可切换的参考档,不能改变默认输出规则。
|
||||
- `2×1`、`2×2` 是内部节点布局;前台只显示实际形态,例如 T 字、十字、偏置十字或多臂非规则路口。
|
||||
- 简单路口、复杂路口、T 字、十字、偏置十字和多臂路口使用同一个对象模型和同一套编辑器信息架构。
|
||||
- 默认参数是全局值。只有用户明确展开某道路臂、角部或设施后,才创建局部覆盖;局部覆盖可恢复为全局值。
|
||||
- 编译层是拓扑识别、几何生成和规范校验的唯一权威。前端不根据节点数量推断形态,不复制几何算法。
|
||||
- 参考 GeoJSON 是只读校准和对照资料,不能直接覆盖 OSM/native 结果。其 `properties.type=1..5` 业务语义未知,不能展示为可编辑业务字段。
|
||||
- 保留现有可用能力:独立路口视图、预览、地图对象选择、表单编辑、拖拽、草稿、撤销/重做、放弃草稿、保存和版本冲突保护。
|
||||
|
||||
## 范围
|
||||
|
||||
### 统一路口结构
|
||||
|
||||
系统为每个可编辑路口提供稳定的只读 `junctionStructure` 摘要,并为以下对象提供可读名称、稳定内部键、关联几何、可编辑状态和诊断:
|
||||
|
||||
| 对象 | 用户可见含义 | 编辑/校验责任 |
|
||||
| --- | --- | --- |
|
||||
| 道路臂 | 从路口离开的有效进口/出口道路,而非每条车行道或 OSM 段 | 名称、方向、车道/有效宽度、单行/双向、步行与非机动车状态 |
|
||||
| 角部 | 两条相邻道路臂之间的转弯区域 | 圆角、步行道转角、相邻导流岛、可行转弯空间 |
|
||||
| 过街设施 | 对应一个道路臂或角部的人行横道与无障碍连续空间 | 横道跨度、深度、退让、通行连续性 |
|
||||
| 停止线 | 保护某一过街设施的车辆控制线 | 与横道的相对关系、位置和方向 |
|
||||
| 导流岛/中央分隔 | 已识别或后续显式配置的分隔和安全岛 | 可用宽度、避让、与过街和转弯空间的关系 |
|
||||
| 人行道转角 | 步行路径在角部的连续连接 | 连续性、最小可通行带、与圆角/岛的冲突 |
|
||||
| 信号设施 | 已有信号灯及其关联停止线/过街设施 | 位置可见性和几何关联;不编辑相位配时 |
|
||||
|
||||
### 工作区与交互
|
||||
|
||||
- 独立 JunctionTools 页面/全屏工作区只渲染当前路口、有效道路臂和关联设施;主地图其他元素不得干扰编辑。
|
||||
- 顶部显示可读路口标题、实际形态、规范档、参考模式和草稿状态,不显示用户无法辨识的路口编号。
|
||||
- 左侧按“道路臂、角部、过街与控制设施”列出对象;选中项必须在中心画布中高亮,中心点选对象也必须将右侧表单切换到同一对象。两者一一对应。
|
||||
- 中间画布显示局部道路、可读道路编号/名称、选区、方向、必要的数值标注及可拖拽手柄。手柄方向必须与表单正方向一致。
|
||||
- 右侧只显示当前对象的参数、全局或局部覆盖状态、恢复全局操作、推荐/警告/阻塞诊断和定位动作。全局参数的影响范围必须明确写出。
|
||||
- 底部固定提供撤销、重做、重置当前对象、放弃草稿、应用预览与保存。重置恢复进入该工具时的基线;放弃草稿恢复全部基线。
|
||||
|
||||
### 规范校验
|
||||
|
||||
第一阶段必须建立下列硬约束与可追踪诊断。具体数值按道路等级、设计速度、地方项目配置由规范档提供,不能把单个演示值冒充全国法定结论。
|
||||
|
||||
| 规则 | 最低要求 | 保存语义 |
|
||||
| --- | --- | --- |
|
||||
| 车道/道路臂有效宽度 | 不低于适用规范档的最小值;单行和单车道不假定有对向车行道 | 低于物理/配置下限阻塞;偏离推荐值警告 |
|
||||
| 斑马线覆盖 | 过街跨度覆盖有效车行道及要求的连续步行连接,不被道路边界或岛切断 | 缺口或不连续阻塞 |
|
||||
| 停止线与斑马线 | 停止线位于车辆来向一侧,与横道保持适用净距,二者不重叠或反向 | 方向错误、重叠或越界阻塞 |
|
||||
| 角部圆角 | 不得吞没行人过街带、步行转角或相邻设施的净空 | 相交/净空不足阻塞;不舒适尺度警告 |
|
||||
| 行人连续性 | 每个已配置的过街路径在路缘、角部、岛和对侧人行道之间可连续通过 | 断裂阻塞 |
|
||||
| 核心与角部面 | 核心面、圆角面、路面/人行道面不得自交、倒置或产生不可用的退化面 | 阻塞 |
|
||||
| 形态适配 | T 字和多臂路口只生成真实存在的道路臂、角部和设施 | 虚构道路臂或设施阻塞 |
|
||||
|
||||
诊断分为三类:`pass` 表示符合项目推荐范围;`warning` 允许预览和保存但需保留原因;`blocking` 禁止保存。属于设计建议的规则不得伪装成保存门禁;几何无效和上述明确不变量必须阻塞保存。
|
||||
|
||||
### 参考 GeoJSON 对照
|
||||
|
||||
- 显示原始文件、原坐标系、转换后的坐标状态和可读来源说明。
|
||||
- 允许显示/隐藏、透明度调节以及与当前编译结果的叠加比较。
|
||||
- 只按空间匹配结果组织参考要素,比较中心、边界框、面积和方向差异;不得按原始 `type` 猜测道路面、横道、岛或人行道。
|
||||
- 后续可根据高置信度匹配提出“建议值”,但须由用户接受,绝不直接写入草稿或原始配置。
|
||||
|
||||
## 非范围
|
||||
|
||||
- 不修改 OSM 拓扑,不创建或删除道路、节点或任意自由多边形。
|
||||
- 不在本任务中实现信号相位、配时、联锁或交通仿真。
|
||||
- 不承诺同时满足所有地方强制条文,也不将参考规范档包装为法定审查工具。
|
||||
- 不从参考 GeoJSON 自动拟合或覆写完整道路边界。
|
||||
- 不在同一阶段一次性实现所有高级设施;导流岛、中央分隔、非机动车过街、无障碍细部和信号关联按阶段交付。
|
||||
|
||||
## 验收标准
|
||||
|
||||
1. 打开任一路口后,用户能看到实际形态、有效道路臂数量、规范档、设施摘要和草稿状态,主文案不暴露内部 ID。
|
||||
2. 道路臂、角部、横道、停止线和信号设施在列表、画布和右侧表单中严格一一对应;选中、聚焦和诊断定位一致。
|
||||
3. 全局值、局部覆盖和恢复全局有明确状态与可逆操作;重置当前对象和放弃草稿都恢复正确基线。
|
||||
4. T 字、十字、偏置十字和多臂真实 OSM 样例均按有效道路臂渲染,绝不凭内部节点布局补出不存在的道路臂、角部或设施。
|
||||
5. 对车道/道路臂宽度、横道覆盖、停止线-横道关系、圆角、行人连续性和多边形有效性至少各有一个可重复的通过、警告或阻塞测试。
|
||||
6. 阻塞诊断阻止保存并将对应对象高亮;警告不会破坏预览/保存链路,且会保留到诊断记录。
|
||||
7. 参考层可安全叠加、隐藏并显示可读差异;关闭、缺失或匹配失败时不会改变 native 输出或现有编辑功能。
|
||||
8. 现有普通路口、复杂路口切换、手柄方向、信号显示、草稿放弃、版本冲突以及页面回归均通过现有和新增自动化测试。
|
||||
|
||||
## 规划结论与未决项
|
||||
|
||||
当前没有阻塞产品决策。数值规则将以带来源、版本、适用条件和项目覆盖项的配置交付;第一阶段的目标是可解释且可测试的项目规范校验,不声称完成法定设计审查。
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"id": "junctiontools-standards",
|
||||
"name": "junctiontools-standards",
|
||||
"title": "JunctionTools 行业规范化规划",
|
||||
"description": "",
|
||||
"status": "in_progress",
|
||||
"dev_type": null,
|
||||
"scope": null,
|
||||
"package": null,
|
||||
"priority": "P2",
|
||||
"creator": "dingkang",
|
||||
"assignee": "dingkang",
|
||||
"createdAt": "2026-09-07",
|
||||
"completedAt": null,
|
||||
"branch": null,
|
||||
"base_branch": "main",
|
||||
"worktree_path": null,
|
||||
"commit": null,
|
||||
"pr_url": null,
|
||||
"subtasks": [],
|
||||
"children": [],
|
||||
"parent": null,
|
||||
"relatedFiles": [],
|
||||
"notes": "",
|
||||
"meta": {}
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
"road-compiler": "bin/road-compiler.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/index.js && node test/native-road-edits.js && node test/road-revisions.js && node test/direct-edit-solver.js && node test/workbench-edit-api.js && node test/workbench-import-compile.js && node test/fixtures.js",
|
||||
"test": "node test/index.js && node test/junction-structure.js && node test/native-road-edits.js && node test/road-revisions.js && node test/direct-edit-solver.js && node test/workbench-edit-api.js && node test/workbench-import-compile.js && node test/fixtures.js",
|
||||
"test:fixtures:update-baseline": "node test/update-fixture-baselines.js",
|
||||
"road:workbench": "node bin/road-workbench.js",
|
||||
"road:export": "node bin/road-compiler.js",
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
'use strict';
|
||||
|
||||
const STANDARDS_PROFILE_SCHEMA = 'junction-standards-profile/v1';
|
||||
|
||||
function deepFreeze(value) {
|
||||
if (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;
|
||||
for (const nestedValue of Object.values(value)) deepFreeze(nestedValue);
|
||||
return Object.freeze(value);
|
||||
}
|
||||
|
||||
const CN_URBAN_DEFAULT_PROFILE = deepFreeze({
|
||||
schema: STANDARDS_PROFILE_SCHEMA,
|
||||
id: 'cn-urban-default',
|
||||
label: '中国城市道路(项目默认)',
|
||||
jurisdiction: '中国城市道路项目',
|
||||
version: '2026.09',
|
||||
sources: [
|
||||
{
|
||||
title: '城市道路工程设计规范',
|
||||
edition: '项目采用版本待按地区确认',
|
||||
clause: '道路宽度、交叉口与步行空间的项目适用条款',
|
||||
},
|
||||
{
|
||||
title: '无障碍设计规范',
|
||||
edition: '项目采用版本待按地区确认',
|
||||
clause: '人行连续性与净空的项目适用条款',
|
||||
},
|
||||
],
|
||||
applicability: {
|
||||
roadClasses: [
|
||||
'motorway',
|
||||
'trunk',
|
||||
'primary',
|
||||
'secondary',
|
||||
'tertiary',
|
||||
'unclassified',
|
||||
'residential',
|
||||
'living_street',
|
||||
'service',
|
||||
],
|
||||
shapeKinds: ['cross', 'offset-cross', 't-junction', 'multi-arm', 'unsupported'],
|
||||
},
|
||||
rules: [
|
||||
{
|
||||
id: 'effective-carriageway-width',
|
||||
objectKinds: ['road-arm'],
|
||||
recommended: { min: 6, unit: 'm', note: '项目推荐值,需结合车道数与道路等级调整' },
|
||||
warning: { min: 4.8, unit: 'm' },
|
||||
blocking: { min: 0, unit: 'm', invariant: 'finite' },
|
||||
level: 'hard-invariant',
|
||||
},
|
||||
{
|
||||
id: 'crossing-covers-carriageway',
|
||||
objectKinds: ['crossing'],
|
||||
level: 'hard-invariant',
|
||||
blocking: { invariant: 'covers-effective-carriageway' },
|
||||
},
|
||||
{
|
||||
id: 'stop-line-crossing-clearance',
|
||||
objectKinds: ['stop-line', 'crossing'],
|
||||
level: 'hard-invariant',
|
||||
blocking: { invariant: 'approach-side-non-overlap' },
|
||||
},
|
||||
{
|
||||
id: 'corner-radius-preserves-pedestrian-space',
|
||||
objectKinds: ['corner', 'sidewalk-turn', 'crossing'],
|
||||
recommended: { min: 4, max: 18, unit: 'm', note: '项目推荐范围,按转弯需求复核' },
|
||||
warning: { min: 0.5, max: 30, unit: 'm' },
|
||||
blocking: { invariant: 'preserves-pedestrian-clearance' },
|
||||
level: 'hard-invariant',
|
||||
},
|
||||
{
|
||||
id: 'pedestrian-continuity',
|
||||
objectKinds: ['crossing', 'sidewalk-turn', 'island', 'median'],
|
||||
level: 'hard-invariant',
|
||||
blocking: { invariant: 'connected-path' },
|
||||
},
|
||||
{
|
||||
id: 'junction-polygon-validity',
|
||||
objectKinds: ['junction', 'corner', 'road-arm'],
|
||||
level: 'hard-invariant',
|
||||
blocking: { invariant: 'simple-non-self-intersecting-surfaces' },
|
||||
},
|
||||
],
|
||||
projectOverrides: {},
|
||||
});
|
||||
|
||||
function cloneProfile(profile) {
|
||||
return JSON.parse(JSON.stringify(profile));
|
||||
}
|
||||
|
||||
function validateStandardsProfile(profile) {
|
||||
if (!profile || typeof profile !== 'object') throw new Error('Junction standards profile must be an object');
|
||||
for (const field of ['id', 'label', 'jurisdiction', 'version'])
|
||||
if (typeof profile[field] !== 'string' || profile[field].trim() === '')
|
||||
throw new Error(`Junction standards profile.${field} must be a non-empty string`);
|
||||
if (!Array.isArray(profile.sources) || profile.sources.length === 0)
|
||||
throw new Error('Junction standards profile.sources must contain at least one source');
|
||||
if (
|
||||
!profile.applicability ||
|
||||
!Array.isArray(profile.applicability.roadClasses) ||
|
||||
!Array.isArray(profile.applicability.shapeKinds)
|
||||
)
|
||||
throw new Error('Junction standards profile.applicability must declare roadClasses and shapeKinds');
|
||||
if (!Array.isArray(profile.rules)) throw new Error('Junction standards profile.rules must be an array');
|
||||
const ids = new Set();
|
||||
for (const rule of profile.rules) {
|
||||
if (!rule || typeof rule.id !== 'string' || !rule.id.trim())
|
||||
throw new Error('Every standards rule needs a non-empty id');
|
||||
if (ids.has(rule.id)) throw new Error(`Duplicate junction standards rule: ${rule.id}`);
|
||||
ids.add(rule.id);
|
||||
if (!Array.isArray(rule.objectKinds) || rule.objectKinds.length === 0)
|
||||
throw new Error(`Standards rule ${rule.id} must declare objectKinds`);
|
||||
if (!['guidance', 'hard-invariant'].includes(rule.level))
|
||||
throw new Error(`Invalid standards rule level: ${rule.id}`);
|
||||
if (!rule.recommended && !rule.warning && !rule.blocking)
|
||||
throw new Error(`Standards rule ${rule.id} must declare a range or invariant`);
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
function evaluateRange(value, rule) {
|
||||
if (!Number.isFinite(value)) return 'blocking';
|
||||
if (rule.blocking?.min !== undefined && value < rule.blocking.min) return 'blocking';
|
||||
if (rule.blocking?.max !== undefined && value > rule.blocking.max) return 'blocking';
|
||||
if (rule.warning?.min !== undefined && value < rule.warning.min) return 'warning';
|
||||
if (rule.warning?.max !== undefined && value > rule.warning.max) return 'warning';
|
||||
if (rule.recommended?.min !== undefined && value < rule.recommended.min) return 'warning';
|
||||
if (rule.recommended?.max !== undefined && value > rule.recommended.max) return 'warning';
|
||||
return 'pass';
|
||||
}
|
||||
|
||||
validateStandardsProfile(CN_URBAN_DEFAULT_PROFILE);
|
||||
|
||||
module.exports = {
|
||||
STANDARDS_PROFILE_SCHEMA,
|
||||
CN_URBAN_DEFAULT_PROFILE,
|
||||
cloneProfile,
|
||||
evaluateRange,
|
||||
validateStandardsProfile,
|
||||
};
|
||||
@@ -0,0 +1,170 @@
|
||||
'use strict';
|
||||
|
||||
const JUNCTION_STRUCTURE_SCHEMA = 'junction-structure/v1';
|
||||
const SHAPE_KINDS = new Set(['cross', 'offset-cross', 't-junction', 'multi-arm', 'unsupported']);
|
||||
const DIRECTIONALITY = new Set(['one-way', 'two-way', 'unknown']);
|
||||
const OVERRIDE_MODES = new Set(['global', 'local']);
|
||||
const FACILITY_KINDS = new Set(['crossing', 'stop-line', 'island', 'median', 'sidewalk-turn', 'signal']);
|
||||
|
||||
function objectKey(value, fallback) {
|
||||
const key = String(value ?? '').trim();
|
||||
if (key) return key;
|
||||
if (fallback) return String(fallback);
|
||||
throw new Error('Junction object key must be a non-empty string');
|
||||
}
|
||||
|
||||
function readableLabel(value, fallback) {
|
||||
const label = String(value ?? '').trim();
|
||||
return label || fallback;
|
||||
}
|
||||
|
||||
function finiteNumber(value, field, { integer = false, minimum = -Infinity } = {}) {
|
||||
const number = Number(value);
|
||||
if (!Number.isFinite(number) || (integer && !Number.isInteger(number)) || number < minimum)
|
||||
throw new Error(`Junction ${field} must be a finite number${integer ? ' integer' : ''} >= ${minimum}`);
|
||||
return number;
|
||||
}
|
||||
|
||||
function overrideState(input = {}) {
|
||||
const mode = input.mode || 'global';
|
||||
if (!OVERRIDE_MODES.has(mode)) throw new Error(`Unsupported junction override mode: ${mode}`);
|
||||
return {
|
||||
mode,
|
||||
...(input.inheritedFrom ? { inheritedFrom: String(input.inheritedFrom) } : {}),
|
||||
resetToGlobalAvailable: mode === 'local' ? input.resetToGlobalAvailable !== false : false,
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeRoadArm(input, index) {
|
||||
const key = objectKey(input.key, `road-arm:${index + 1}`);
|
||||
const label = readableLabel(input.label, `道路 ${index + 1}`);
|
||||
const directionality = input.directionality || 'unknown';
|
||||
if (!DIRECTIONALITY.has(directionality)) throw new Error(`Unsupported road arm directionality: ${directionality}`);
|
||||
const carriageway = input.carriageway || {};
|
||||
const normalized = {
|
||||
key,
|
||||
label,
|
||||
heading: finiteNumber(input.heading ?? 0, 'arm heading'),
|
||||
directionality,
|
||||
carriageway: {
|
||||
...(carriageway.laneCount === undefined
|
||||
? {}
|
||||
: { laneCount: finiteNumber(carriageway.laneCount, 'lane count', { integer: true, minimum: 0 }) }),
|
||||
...(carriageway.effectiveWidthMeters === undefined
|
||||
? {}
|
||||
: { effectiveWidthMeters: finiteNumber(carriageway.effectiveWidthMeters, 'effective width', { minimum: 0 }) }),
|
||||
},
|
||||
...(input.pedestrian
|
||||
? {
|
||||
pedestrian: {
|
||||
connected: Boolean(input.pedestrian.connected),
|
||||
...(input.pedestrian.bicycleConnected === undefined
|
||||
? {}
|
||||
: { bicycleConnected: Boolean(input.pedestrian.bicycleConnected) }),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
geometryRef: objectKey(input.geometryRef, `junction:${key}`),
|
||||
overrideState: overrideState(input.overrideState),
|
||||
};
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function normalizeCorner(input, index) {
|
||||
const key = objectKey(input.key, `corner:${index + 1}`);
|
||||
const fromArmKey = objectKey(input.fromArmKey || input.incomingRoadArmKey, `road-arm:${index + 1}`);
|
||||
const toArmKey = objectKey(input.toArmKey || input.outgoingRoadArmKey, `road-arm:${index + 2}`);
|
||||
if (fromArmKey === toArmKey) throw new Error(`Junction corner ${key} must connect two different road arms`);
|
||||
return {
|
||||
key,
|
||||
label: readableLabel(input.label, `角部 ${index + 1}`),
|
||||
fromArmKey,
|
||||
toArmKey,
|
||||
...(input.angleDegrees === undefined ? {} : { angleDegrees: finiteNumber(input.angleDegrees, 'corner angle') }),
|
||||
...(input.radiusMeters === undefined
|
||||
? {}
|
||||
: { radiusMeters: finiteNumber(input.radiusMeters, 'corner radius', { minimum: 0 }) }),
|
||||
geometryRef: objectKey(input.geometryRef, `junction:${key}`),
|
||||
overrideState: overrideState(input.overrideState),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeFacility(input, index) {
|
||||
const kind = String(input.kind || '').trim();
|
||||
if (!FACILITY_KINDS.has(kind)) throw new Error(`Unsupported junction facility kind: ${kind || '<empty>'}`);
|
||||
const key = objectKey(input.key, `${kind}:${index + 1}`);
|
||||
return {
|
||||
key,
|
||||
kind,
|
||||
label: readableLabel(input.label, kind === 'crossing' ? `人行横道 ${index + 1}` : `设施 ${index + 1}`),
|
||||
...(input.armKey ? { armKey: String(input.armKey) } : {}),
|
||||
...(input.cornerKey ? { cornerKey: String(input.cornerKey) } : {}),
|
||||
...(input.relatedFacilityKey ? { relatedFacilityKey: String(input.relatedFacilityKey) } : {}),
|
||||
...(input.direction === undefined ? {} : { direction: finiteNumber(input.direction, 'facility direction') }),
|
||||
geometryRef: objectKey(input.geometryRef, `junction:${key}`),
|
||||
editable: input.editable !== false,
|
||||
overrideState: overrideState(input.overrideState),
|
||||
};
|
||||
}
|
||||
|
||||
function assertUniqueKeys(items, objectKind) {
|
||||
const keys = new Set();
|
||||
for (const item of items) {
|
||||
if (keys.has(item.key)) throw new Error(`Duplicate junction ${objectKind} key: ${item.key}`);
|
||||
keys.add(item.key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
function buildJunctionStructure(input = {}) {
|
||||
const shape = input.shape || {};
|
||||
const kind = String(shape.kind || 'unsupported');
|
||||
if (!SHAPE_KINDS.has(kind)) throw new Error(`Unsupported junction shape kind: ${kind}`);
|
||||
const arms = (input.arms || []).map(normalizeRoadArm);
|
||||
const armKeys = assertUniqueKeys(arms, 'road arm');
|
||||
const corners = (input.corners || []).map(normalizeCorner);
|
||||
const cornerKeys = assertUniqueKeys(corners, 'corner');
|
||||
for (const corner of corners)
|
||||
if (!armKeys.has(corner.fromArmKey) || !armKeys.has(corner.toArmKey))
|
||||
throw new Error(`Junction corner ${corner.key} references an unknown road arm`);
|
||||
const facilities = (input.facilities || []).map(normalizeFacility);
|
||||
const facilityKeys = assertUniqueKeys(facilities, 'facility');
|
||||
for (const facility of facilities) {
|
||||
if (facility.armKey && !armKeys.has(facility.armKey))
|
||||
throw new Error(`Junction facility ${facility.key} references an unknown road arm`);
|
||||
if (facility.cornerKey && !cornerKeys.has(facility.cornerKey))
|
||||
throw new Error(`Junction facility ${facility.key} references an unknown corner`);
|
||||
if (facility.relatedFacilityKey && !facilityKeys.has(facility.relatedFacilityKey))
|
||||
throw new Error(`Junction facility ${facility.key} references an unknown facility`);
|
||||
}
|
||||
const effectiveArmCount = shape.effectiveArmCount ?? arms.length;
|
||||
finiteNumber(effectiveArmCount, 'effective arm count', { integer: true, minimum: 0 });
|
||||
if (effectiveArmCount !== arms.length)
|
||||
throw new Error('Junction effective arm count must match the supplied road arms');
|
||||
return {
|
||||
schema: JUNCTION_STRUCTURE_SCHEMA,
|
||||
junctionKey: objectKey(input.junctionKey, 'junction:unknown'),
|
||||
label: readableLabel(input.label, '未命名路口'),
|
||||
shape: {
|
||||
kind,
|
||||
label: readableLabel(shape.label, '暂未识别的路口形态'),
|
||||
effectiveArmCount,
|
||||
throughPairCount: finiteNumber(shape.throughPairCount ?? 0, 'through pair count', { integer: true, minimum: 0 }),
|
||||
},
|
||||
...(input.center ? { center: [...input.center] } : {}),
|
||||
...(input.effectiveRadiusMeters === undefined
|
||||
? {}
|
||||
: { effectiveRadiusMeters: finiteNumber(input.effectiveRadiusMeters, 'effective radius', { minimum: 0 }) }),
|
||||
arms,
|
||||
corners,
|
||||
facilities,
|
||||
...(input.standards ? { standards: input.standards } : {}),
|
||||
...(input.reference ? { reference: input.reference } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
JUNCTION_STRUCTURE_SCHEMA,
|
||||
SHAPE_KINDS,
|
||||
buildJunctionStructure,
|
||||
};
|
||||
@@ -5,6 +5,8 @@ module.exports = {
|
||||
gaodeReference: require('./reference/gaode'),
|
||||
turnLaneArrows: require('./compile/turn-lane-arrows'),
|
||||
complexJunction: require('./compile/complex-junction'),
|
||||
junctionStructure: require('./compile/junction-structure'),
|
||||
junctionStandards: require('./compile/junction-standards'),
|
||||
osm: require('./osm'),
|
||||
trafficSignals: require('./traffic-signals'),
|
||||
nativeTrafficSignals: require('./native-traffic-signals'),
|
||||
|
||||
@@ -10,6 +10,8 @@ assert.equal(typeof compiler.gaodeReference.convertGeoJson, 'function');
|
||||
assert.equal(typeof compiler.turnLaneArrows.buildCustomTurnLaneArrows, 'function');
|
||||
assert.equal(typeof compiler.complexJunction.buildComplexJunctionGeometry, 'function');
|
||||
assert.equal(typeof compiler.complexJunction.classifyJunctionShape, 'function');
|
||||
assert.equal(typeof compiler.junctionStructure.buildJunctionStructure, 'function');
|
||||
assert.equal(typeof compiler.junctionStandards.validateStandardsProfile, 'function');
|
||||
const shapeHelpers = { distanceMeters: (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1]) };
|
||||
const arm = (heading, distance = 20) => ({
|
||||
heading,
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert/strict');
|
||||
const { buildJunctionStructure } = require('../src/compile/junction-structure');
|
||||
const {
|
||||
CN_URBAN_DEFAULT_PROFILE,
|
||||
cloneProfile,
|
||||
evaluateRange,
|
||||
validateStandardsProfile,
|
||||
} = require('../src/compile/junction-standards');
|
||||
|
||||
const arm = (key, label, directionality = 'two-way') => ({
|
||||
key,
|
||||
label,
|
||||
heading: key === 'south' ? 180 : key === 'east' ? 90 : key === 'west' ? 270 : 0,
|
||||
directionality,
|
||||
carriageway: {
|
||||
laneCount: directionality === 'one-way' ? 1 : 2,
|
||||
effectiveWidthMeters: directionality === 'one-way' ? 3.5 : 7,
|
||||
},
|
||||
geometryRef: `road-surface:${key}`,
|
||||
});
|
||||
|
||||
const cross = buildJunctionStructure({
|
||||
junctionKey: 'junction:fixture-cross',
|
||||
label: '科技园东路与科技园一路',
|
||||
shape: { kind: 'cross', label: '十字路口', effectiveArmCount: 4, throughPairCount: 2 },
|
||||
arms: [arm('north', '科技园一路'), arm('east', '科技园东路'), arm('south', '科技园一路'), arm('west', '科技园东路')],
|
||||
corners: [
|
||||
{ key: 'corner:north-east', fromArmKey: 'north', toArmKey: 'east', radiusMeters: 12 },
|
||||
{ key: 'corner:east-south', fromArmKey: 'east', toArmKey: 'south', radiusMeters: 12 },
|
||||
],
|
||||
facilities: [
|
||||
{ key: 'crossing:north', kind: 'crossing', label: '北侧人行横道', armKey: 'north' },
|
||||
{
|
||||
key: 'stop-line:north',
|
||||
kind: 'stop-line',
|
||||
label: '北侧停止线',
|
||||
armKey: 'north',
|
||||
relatedFacilityKey: 'crossing:north',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
assert.equal(cross.schema, 'junction-structure/v1');
|
||||
assert.equal(cross.shape.kind, 'cross');
|
||||
assert.equal(cross.shape.effectiveArmCount, 4);
|
||||
assert.equal(cross.arms[0].label, '科技园一路');
|
||||
assert.equal(cross.facilities[1].relatedFacilityKey, 'crossing:north');
|
||||
assert.equal(cross.arms[0].overrideState.mode, 'global');
|
||||
|
||||
const localArm = buildJunctionStructure({
|
||||
junctionKey: 'junction:t',
|
||||
shape: { kind: 't-junction', label: 'T 字路口', effectiveArmCount: 3, throughPairCount: 1 },
|
||||
arms: [arm('north', '道路 1'), arm('east', '道路 2'), arm('west', '道路 3', 'one-way')],
|
||||
});
|
||||
assert.equal(localArm.shape.kind, 't-junction');
|
||||
assert.equal(localArm.arms.length, 3);
|
||||
assert.equal(localArm.arms[2].directionality, 'one-way');
|
||||
assert.equal(localArm.arms[2].carriageway.laneCount, 1);
|
||||
|
||||
for (const [kind, label, headings] of [
|
||||
['offset-cross', '偏置十字路口', ['north', 'east', 'south', 'west']],
|
||||
['multi-arm', '5 臂非规则路口', ['north', 'east', 'south', 'west', 'north-east']],
|
||||
]) {
|
||||
const structure = buildJunctionStructure({
|
||||
junctionKey: `junction:${kind}`,
|
||||
shape: { kind, label, effectiveArmCount: headings.length, throughPairCount: kind === 'offset-cross' ? 2 : 1 },
|
||||
arms: headings.map((heading, index) => arm(`${heading}-${index}`, `道路 ${index + 1}`)),
|
||||
});
|
||||
assert.equal(structure.shape.kind, kind);
|
||||
assert.equal(structure.shape.effectiveArmCount, headings.length);
|
||||
}
|
||||
|
||||
assert.throws(
|
||||
() => buildJunctionStructure({ shape: { kind: 't-junction', effectiveArmCount: 4 }, arms: [arm('north', '道路 1')] }),
|
||||
/effective arm count must match/,
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
buildJunctionStructure({
|
||||
shape: { kind: 'cross', effectiveArmCount: 1 },
|
||||
arms: [arm('north', '道路 1'), arm('north', '道路 2')],
|
||||
}),
|
||||
/Duplicate junction road arm key/,
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
buildJunctionStructure({
|
||||
shape: { kind: 't-junction', effectiveArmCount: 1 },
|
||||
arms: [arm('north', '道路 1')],
|
||||
corners: [{ fromArmKey: 'north', toArmKey: 'missing' }],
|
||||
}),
|
||||
/unknown road arm/,
|
||||
);
|
||||
|
||||
validateStandardsProfile(CN_URBAN_DEFAULT_PROFILE);
|
||||
assert.equal(CN_URBAN_DEFAULT_PROFILE.id, 'cn-urban-default');
|
||||
assert.ok(CN_URBAN_DEFAULT_PROFILE.sources.every((source) => source.title && source.edition && source.clause));
|
||||
assert.throws(() => (CN_URBAN_DEFAULT_PROFILE.rules[0].recommended.min = 99), /read only/);
|
||||
assert.deepEqual(
|
||||
CN_URBAN_DEFAULT_PROFILE.rules.map((rule) => rule.id),
|
||||
[
|
||||
'effective-carriageway-width',
|
||||
'crossing-covers-carriageway',
|
||||
'stop-line-crossing-clearance',
|
||||
'corner-radius-preserves-pedestrian-space',
|
||||
'pedestrian-continuity',
|
||||
'junction-polygon-validity',
|
||||
],
|
||||
);
|
||||
assert.equal(evaluateRange(7, CN_URBAN_DEFAULT_PROFILE.rules[0]), 'pass');
|
||||
assert.equal(evaluateRange(5, CN_URBAN_DEFAULT_PROFILE.rules[0]), 'warning');
|
||||
assert.equal(evaluateRange(-1, CN_URBAN_DEFAULT_PROFILE.rules[0]), 'blocking');
|
||||
const copy = cloneProfile(CN_URBAN_DEFAULT_PROFILE);
|
||||
copy.rules[0].recommended.min = 99;
|
||||
assert.equal(CN_URBAN_DEFAULT_PROFILE.rules[0].recommended.min, 6);
|
||||
assert.throws(
|
||||
() => validateStandardsProfile({ ...copy, rules: [{ ...copy.rules[0] }, { ...copy.rules[0] }] }),
|
||||
/Duplicate/,
|
||||
);
|
||||
|
||||
console.log('junction structure and standards tests passed');
|
||||
Reference in new issue
Block a user