跳至內容
Astera Technology

標籤尺寸落在半格之間,怎樣取點?

先訂取整規則,才把尺寸換成設備格點設定。

下載完整個案資料及參考答案 ↓

訂判斷及所需輸入

本例格線每毫米八點,12.3 毫米對98.4 點,不能直接當整點設定。最接近取98,向上取99;兩種都不是在猜真正打印機預設。

已填本地測試工作表
情況輸入 JSON
原例測試{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"nearest"}
下載可編輯 CSV ↓

跑所附比較

程序先按十分之一毫米整數乘格線,再取點。幾何尺寸及所選整點數仍是不同記錄,供覆核取整影響。

錯誤及所需輸出
路徑輸出 JSON
錯誤路徑{"dots":98.4,"executableInteger":false}
所需路徑{"dots":98,"executableInteger":true}
下載可編輯 CSV ↓
完整本地 Node24.14.1 程序
import assert from 'node:assert/strict';
const smallWhole=(x,max)=>Number.isSafeInteger(x)&&x>=0&&x<=max;

const run=function run(i,corrected=true){
    if(!['nearest','ceil'].includes(i.rounding)||!smallWhole(i.tenthsMillimetre,1000000)||!smallWhole(i.dotsPerMillimetre,100)||i.dotsPerMillimetre===0)return {held:true};
    const numerator=i.tenthsMillimetre*i.dotsPerMillimetre;
    const dots=corrected?(i.rounding==='ceil'?Math.ceil(numerator/10):Math.floor((numerator+5)/10)):numerator/10;
    return {dots,executableInteger:Number.isInteger(dots)};
  };
const cases=[{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"nearest"},"corrected":false,"expected":{"dots":98.4,"executableInteger":false}},{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"nearest"},"corrected":true,"expected":{"dots":98,"executableInteger":true}},{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"ceil"},"corrected":true,"expected":{"dots":99,"executableInteger":true}},{"input":{"tenthsMillimetre":125,"dotsPerMillimetre":8,"rounding":"nearest"},"corrected":true,"expected":{"dots":100,"executableInteger":true}},{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":null},"corrected":true,"expected":{"held":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
下載可執行例子 ↓

按邊界依據作判斷

剛好12.5 毫米就是100 點,沒有取整歧義;未選取整法便停。

  1. 取所附格線密度
  2. 先換算再取整
  3. 尺寸及所選點數一起留

取整法未訂就停,不能靜靜代選。

可編輯邊界輸入及結果
條件輸入 JSON預期輸出 JSON
明選向上取點{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"ceil"}{"dots":99,"executableInteger":true}
換算剛好整點{"tenthsMillimetre":125,"dotsPerMillimetre":8,"rounding":"nearest"}{"dots":100,"executableInteger":true}
取整選擇未知{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":null}{"held":true}
下載可編輯 CSV ↓

原例最接近取整,應填哪個設定?

查看參考答案

98 整點。原12.3 毫米仍保留;98.4 只是換算結果,不是可執行整點數。

相關資源