You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
parses number written in Computer Scientific Notation and returns an String Array containing Elements of Scientific Notation
/** * This Function parses number written in Computer Scientific Notation and returns * an String Array containing Elements of Scientific Notation * value: value in scientific format like 1.0005E-25 or 1.0005E25 * Return String Array with Following thing * String[0] = multiplier section(example [10.2 * ] ) * String[1] = base (example [10] ) * String[2] = power (example [-2] ) * * this example represents 10.2 * 10^-2 * */publicstaticString[] makeEtoPower(floatvalue){
String[] return_value;
if (Float.isInfinite(value)){
Gdx.app.error(TAG, "Passed value is Infinite, value: " + value);
return_value = newString[]{"Inf.", "", " "};
} elseif (Float.isNaN(value)){
Gdx.app.error(TAG, "Passed value is Not a Number, value: " + value);
return_value = newString[]{"NaN", "", " "};
} else { // we have a valid value, parse it// match all the values in scientific format like 1.0005E-25 or 1.0005E25Matchermatch = Pattern.compile("-?\\d+(\\.\\d+)?").matcher(String.valueOf(value));
ArrayList<String> matches = newArrayList<String>();
while(match.find()) {
matches.add(match.group());
}
try {
doubleval = Double.valueOf(matches.get(0));
Stringmultiplier = String.valueOf(Math.round(val * 100.0)/ 100.0f); // round to two decimal placemultiplier = multiplier + " * "; // append Multiply SignStringbase = "10";
Stringpower = matches.get(1);
return_value = newString[]{multiplier, base, power};
} catch (IndexOutOfBoundsExceptione){
// In this case we got passed a value in non Scientific notation// So we will send that back in multiplier field of arrayGdx.app.error(TAG, "Caught IndexOutOfBoundsException - RegEx can not parse provided value, reporting value as Infinite, value: " + value);
return_value = newString[]{String.valueOf(value), "", ""};
}
}
returnreturn_value;
}
publicstaticGroupcreateSuperScriptText(StringpreText, String[] EtoPower,
StringpostText, Label.LabelStylelabelStyle) {
// Group is Primitive Type and does not handle it's own Height, Width// and positing of it's elements// So Here we manage position the elements of group in relative to each other// and Set the height and width of group before returning it.// We set Height and width of group so the containing Table can position it properlyGroupgroup = newGroup();
// group.debugAll();// Text before the superScript TextLabelpreLabel = newLabel(preText, labelStyle);
group.addActor(preLabel);
// EtoPower is String array with following things// String[0] = multiplier section(example [10.2 * ] )// String[1] = base (example [10] )// String[2] = power (example [-2] )// multiplier TextLabelmultiplierLabel = newLabel(EtoPower[0], labelStyle);
multiplierLabel.setPosition(preLabel.getX() + preLabel.getPrefWidth(), preLabel.getY());
group.addActor(multiplierLabel);
// SuperScript Text// SuperScript Base TextLabelbaseLabel = newLabel(EtoPower[1], labelStyle);
baseLabel.setPosition(multiplierLabel.getX() + multiplierLabel.getPrefWidth(), multiplierLabel.getY());
group.addActor(baseLabel);
// SuperScript power TextfloatsuperscriptOFFSET = baseLabel.getPrefHeight()/3; // how high is superscriptfloatsuperscriptSCALE = 0.80f;
LabelpowerLabel = newLabel(EtoPower[2], labelStyle);
powerLabel.setFontScale(superscriptSCALE);
powerLabel.setPosition(baseLabel.getX() + baseLabel.getPrefWidth(), baseLabel.getY() + superscriptOFFSET);
group.addActor(powerLabel);
// Something we want to write after the SuperScript TextLabelpostLabel = newLabel(postText, labelStyle);
postLabel.setPosition(powerLabel.getX() + powerLabel.getPrefWidth(), baseLabel.getY());
group.addActor(postLabel);
group.setHeight(baseLabel.getPrefHeight() + superscriptOFFSET);
group.setWidth(preLabel.getPrefWidth() + multiplierLabel.getPrefWidth() + baseLabel.getPrefWidth() +
powerLabel.getPrefWidth() + postLabel.getPrefWidth());
returngroup;
}