소스 검색

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",


불러오는 중...
취소
저장