Description
ProjectGlobals contains 3 methods that can be used by other designs.
Parameter Rules
Method: | return function fractionString(num, maxDenominator = 16, isFeetToo = true, isSuppressUnits = true, isFractionHyphen = false, isFeetInchHyphen = true, isHideZeroInches = (isFeetToo || (Math.abs(num) < (1 - 1/(maxDenominator/2)))), isHideZeroFeet = true) { |
| let denominators = [64,32,16,8,4,2]; //backwards to facilitate loop in $denominator |
| if (!denominators.includes(maxDenominator)) { |
| throw "The maxDenominator must be one of 2, 4, 8, 16, 32, or 64"; |
| // determine the feet and inch values |
| let realValue = this.roundInc(num, 1/maxDenominator); |
| let absValue = Math.abs(realValue); |
| let wholeValue = Math.floor(absValue); |
| let wholeInches = (isFeetToo) ? (wholeValue % 12) : wholeValue; |
| let remainder = (absValue - wholeValue); |
| let isAbsZero = (Math.abs(absValue - 0.0) < 0.0001); |
| let isRemainderZero = (Math.abs(remainder - 0.0) < 0.0001); |
| let roundedRemainder = this.roundInc(remainder,(1.0/maxDenominator)); |
| if (roundedRemainder === 0) { |
| let start = denominators.indexOf(maxDenominator); |
| for (index = start;index < denominators.length;index++) { |
| if (this.isOddReal(roundedRemainder * denominators[index])) { |
| denominator = denominators[index]; |
| } else if (index > denominators.length) { |
| let numerator = denominator * roundedRemainder; |
| let isShowFeet = isFeetToo && ((feetValue >= 1)||(! isHideZeroFeet)); |
| let isShowInches = (wholeInches > 0) || (! isHideZeroInches) || isAbsZero; |
| let isShowFraction = (! isRemainderZero); |
| let signString = (realValue < 0) ? '-' : ''; |
| let feetString = (isShowFeet) ? feetValue.toString() + '\'' : ''; |
| let feetDashString = (isShowFeet && (isShowInches || isShowFraction)) ? (isFeetInchHyphen ? '-' : ' ') : ''; |
| let inchString = isShowInches ? wholeInches.toString() : ''; |
| let inchDashString = (isShowInches && isShowFraction) ? (isFractionHyphen ? '-' : ' ') : ''; |
| let fractionString = isShowFraction ? numerator.toString() + '/' + denominator.toString() : ''; |
| let inchUnits = ((isFeetToo || (! isSuppressUnits)) && (isShowFraction || isShowInches)) ? '\"' : ''; |
| let resultString = signString + feetString + feetDashString + inchString + inchDashString + fractionString + inchUnits; |
Method: | return function isOddReal(num) { |
| return ((num/2) !== Math.floor(num/2)); |
Method: | return function roundInc(num, increment) { |
| return Math.ceil(num / increment) * increment; |
Mixins
None
RULE NAME
|
TYPE
|
DEFAULTS
|
CATEGORY
|
FLAGS
|
fractionString
|
method
|
Formula
|
Methods
|
Methods
|
SheetName
|
string
|
Formula
|
Methods
|
Methods
|
ViewportData
|
array
|
Formula
|
Methods
|
Methods
|