Please enable JavaScript to view this site.

Knowledge Bridge Documentation

Help version: 3.3.8

Description

ProjectGlobals contains 3 methods that can be used by other designs.

 

Parameter Rules

 

fractionString:
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));
   let denominator;
   
   if (roundedRemainder === 0) {
     denominator = 0;
   } else {
     let start = denominators.indexOf(maxDenominator);
     let index;
     for (index = start;index < denominators.length;index++) {
       if (this.isOddReal(roundedRemainder * denominators[index])) {
         denominator = denominators[index];
         break;
       } else if (index > denominators.length) {
         denominator = 0;
         break;
       }
     }
   }
 
   let numerator = denominator * roundedRemainder;
   let isShowFeet = isFeetToo && ((feetValue >= 1)||(! isHideZeroFeet));
   let isShowInches = (wholeInches > 0) || (! isHideZeroInches) || isAbsZero;
   let isShowFraction = (! isRemainderZero);
   
   // sections of string
   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)) ?  '\"' : '';
   
   // resulting string
   let resultString = signString + feetString + feetDashString + inchString + inchDashString + fractionString + inchUnits;
 
   return resultString;
 
 }

 

isOddReal:
Method:return function isOddReal(num) {
 return ((num/2) !== Math.floor(num/2));
}

 

 

roundInc:
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

 

 

 

 

 

 

Knowledge Bridge from Engingeering Intent is a full-featured engineering and sales automation environment