瀏覽代碼

Add a function to decide what type a unit is

Custom attributes will take string input and then decide if it is an acceptable
type of unit.
master
Fen Dweller 3 年之前
父節點
當前提交
0e2f1d37b3
共有 1 個文件被更改,包括 36 次插入0 次删除
  1. +36
    -0
      macrovision.js

+ 36
- 0
macrovision.js 查看文件

@@ -75,6 +75,42 @@ let ratioInfo;

//#region units

function dimsEqual(unit1, unit2) {
a = unit1.dimensions;
b = unit2.dimensions;

if (a.length != b.length) {
return false;
}

for (let i = 0; i < a.length && i < b.length; i++) {
if (a[i] != b[i]) {
return false;
}
}

return true;
}

// Determines if a unit is one of a length, area, volume, mass, or energy
function typeOfUnit(unit) {
if (dimsEqual(unit, math.unit(1, "meters"))) {
return "length"
}
if (dimsEqual(unit, math.unit(1, "meters^2"))) {
return "area"
}
if (dimsEqual(unit, math.unit(1, "meters^3"))) {
return "volume"
}
if (dimsEqual(unit, math.unit(1, "kilograms"))) {
return "mass"
}
if (dimsEqual(unit, math.unit(1, "joules"))) {
return "energy"
}
}

math.createUnit({
ShoeSizeMensUS: {
prefixes: "long",


Loading…
取消
儲存