Преглед изворни кода

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…
Откажи
Сачувај