142 lines
5.2 KiB
JavaScript
142 lines
5.2 KiB
JavaScript
'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,
|
|
};
|