Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"test": "node --test",
"prebuild": "npm run check:template-sync",
"build": "vite build",
"build:pages": "npm run check:template-sync && vite build --base=/OpenBox3D/",
Expand Down
11 changes: 9 additions & 2 deletions src/design/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ export function bboxOf(l) {
}

export function dpiOf(l) {
if (l.kind !== 'image' || !l.pxw) return 0;
return Math.round(l.pxw / (l.w / 25.4));
if (l.kind !== 'image') return 0;
const pxw = Number(l.pxw || l.imgW), pxh = Number(l.imgH);
const w = Number(l.w), h = Number(l.h);
const crop = Array.isArray(l.crop) ? l.crop : [0, 0, 1, 1];
const cropW = Number(crop[2]), cropH = Number(crop[3]);
if (![pxw, pxh, w, h, cropW, cropH].every(v => Number.isFinite(v) && v > 0)) return 0;
const dpiX = pxw * cropW / (w / 25.4);
const dpiY = pxh * cropH / (h / 25.4);
return Math.round(Math.min(dpiX, dpiY));
}

// 图集 UV 用:每个面板(fill 多边形)的包围盒,供 3D 与导出对齐
Expand Down
13 changes: 10 additions & 3 deletions src/ui/StructureView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ export function StructureView() {
{ k: '含出血', v: fmt(sw + 2 * s.bleed) + ' × ' + fmt(sh + 2 * s.bleed) },
{ k: '纸厚 t', v: t + ' mm' }
].concat(specTpl[s.tpl] || []);
const checks = ['外轮廓闭合', '无自交 / 孤立线段', '最小刀距 ≥ 1.5 mm', '压痕两侧均有连接面', '出血 ≥ ' + m.bleed + ' mm(' + m.note + ')'];
const bleedOk = s.bleed >= m.bleed;
const checks = [
{ label: '外轮廓闭合:未自动检测', dot: '#9a8f7e' },
{ label: '自交 / 孤立线段:未自动检测', dot: '#9a8f7e' },
{ label: '最小刀距 ≥ 1.5 mm:未自动检测', dot: '#9a8f7e' },
{ label: '压痕两侧均有连接面:未自动检测', dot: '#9a8f7e' },
{ label: '出血 ' + s.bleed + ' mm ' + (bleedOk ? '≥' : '<') + ' 材质建议 ' + m.bleed + ' mm(' + m.note + ')', dot: bleedOk ? '#3f9e5f' : '#d05a2a' }
];
const compNote = s.tpl === 'rte' || s.tpl === 'ste' ? '当前:W+t · L+t · W+t · L+2t,高度 H+t' : s.tpl === 'mailer' ? '当前:楞厚 t=' + t + ',侧墙 H+t,盖宽 W+3t' : s.tpl === 'cyl' ? '当前:直径 D=L,筒身 24 段卷合,盖为 24 边形' : s.tpl === 'hex' ? '当前:边长 W,六棱筒,盖为正六边形' : '当前:盖/套筒按 +1mm/边 放量';
const editOn = s.editMode;
const typeOvrCount = Object.keys(s.typeOvr).length;
Expand Down Expand Up @@ -123,8 +130,8 @@ export function StructureView() {
<div style={{ padding: 14 }}>
<ST>校验</ST>
{checks.map(c => (
<div key={c} style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '4px 0', fontSize: 12, color: '#3d3830' }}>
<div style={{ width: 6, height: 6, borderRadius: 99, background: '#3f9e5f', flex: 'none' }} />{c}
<div key={c.label} style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '4px 0', fontSize: 12, color: '#3d3830' }}>
<div style={{ width: 6, height: 6, borderRadius: 99, background: c.dot, flex: 'none' }} />{c.label}
</div>
))}
</div>
Expand Down
33 changes: 33 additions & 0 deletions test/layers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { dpiOf } from '../src/design/layers.js';

const imageLayer = overrides => ({
kind: 'image',
imgW: 600,
imgH: 300,
pxw: 600,
w: 50.8,
h: 25.4,
...overrides
});

test('dpiOf uses both full-image dimensions when no crop is set', () => {
assert.equal(dpiOf(imageLayer()), 300);
});

test('dpiOf returns the lower DPI after non-uniform scaling', () => {
assert.equal(dpiOf(imageLayer({ h: 50.8 })), 150);
});

test('dpiOf uses the cropped pixel dimensions on both axes', () => {
const cropped = { imgW: 4000, imgH: 2000, pxw: 4000, crop: [0.1, 0.2, 0.5, 0.25] };
assert.equal(dpiOf(imageLayer({ ...cropped, w: 127, h: 25.4 })), 400);
assert.equal(dpiOf(imageLayer({ ...cropped, w: 101.6, h: 50.8 })), 250);
});

test('dpiOf returns zero for non-image layers or missing dimensions', () => {
assert.equal(dpiOf({ kind: 'text', pxw: 600, w: 50.8 }), 0);
assert.equal(dpiOf({ kind: 'image', pxw: 600, w: 50.8 }), 0);
assert.equal(dpiOf({ kind: 'image', pxw: 600, w: 0, h: 25.4 }), 0);
});