use of maspack.util.DoubleInterval in project artisynth_core by artisynth.
the class FemBeamColored method prerender.
@Override
public void prerender(RenderList list) {
// Synchronize color bar/values in case they are changed
ColorBar cbar = (ColorBar) (renderables().get("colorBar"));
cbar.setColorMap(fem.getColorMap());
DoubleInterval range = fem.getStressPlotRange();
cbar.updateLabels(range.getLowerBound(), range.getUpperBound());
super.prerender(list);
}
use of maspack.util.DoubleInterval in project artisynth_core by artisynth.
the class HueColorMap method setHueRange.
/**
* Sets the hue range. Normally, these values are in the range
* [0, 1]; however, the hues support wrapping. If maxHue is less
* than minHue, colors will be interpolated backwards.
* <p>
* Examples:<br>
* [0, 1/6] will interpolate from red to yellow <br>
* [1/6, 0] will interpolate from yellow to red <br>
* [5/6, 7/6] will interpolate from violet to yellow <br>
*/
public void setHueRange(double minHue, double maxHue) {
myMinHue = minHue;
myMaxHue = maxHue;
if (myHueRange == null) {
myHueRange = new DoubleInterval();
}
myHueRange.set(minHue, maxHue);
}
use of maspack.util.DoubleInterval in project artisynth_core by artisynth.
the class SetHandler method getNumericRange.
public static NumericInterval getNumericRange(Property prop) {
NumericInterval nrange = null;
PropertyInfo info = prop.getInfo();
if (info.isReadOnly()) {
return null;
}
Class<?> type = info.getValueClass();
if (type == double.class || type == float.class || type == Double.class || type == Float.class) {
Object value = prop.get();
// i.e., if the value is not Void
if (value instanceof Number) {
double x = ((Number) value).doubleValue();
if (info.hasRestrictedRange()) {
Range range = prop.getRange();
NumericInterval defaultRange = info.getDefaultNumericRange();
if (range instanceof NumericInterval) {
nrange = new DoubleInterval((NumericInterval) range);
if (!nrange.isBounded()) {
if (defaultRange != null) {
nrange.intersect(defaultRange);
}
}
nrange = SliderRange.estimateBoundsIfNecessary(nrange, x);
} else if (defaultRange != null) {
nrange = SliderRange.estimateBoundsIfNecessary(defaultRange, x);
}
}
if (nrange == null) {
// try to calculate range a from the value
if (x == -1) {
nrange = new DoubleInterval(-1, 1);
} else {
// interval is unbounded
nrange = new DoubleInterval();
nrange = SliderRange.estimateBoundsIfNecessary(nrange, x);
}
}
}
} else if (type == int.class || type == Integer.class) {
Object value = prop.get();
// i.e., if the value is not Void
if (value instanceof Number) {
int x = ((Number) value).intValue();
if (info.hasRestrictedRange()) {
Range range = prop.getRange();
NumericInterval defaultRange = info.getDefaultNumericRange();
if (range instanceof NumericInterval) {
nrange = new IntegerInterval((NumericInterval) range);
if (!nrange.isBounded()) {
if (defaultRange != null) {
nrange.intersect(defaultRange);
}
}
nrange = SliderRange.estimateBoundsIfNecessary(nrange, x);
} else if (defaultRange != null) {
nrange = SliderRange.estimateBoundsIfNecessary(defaultRange, x);
}
}
}
}
return nrange;
}
use of maspack.util.DoubleInterval in project artisynth_core by artisynth.
the class DoubleFieldSlider method updateInternalValue.
protected boolean updateInternalValue(Object value) {
if (super.updateInternalValue(value)) {
if (value instanceof Number && mySliderRange != null) {
double newValue = ((Number) value).doubleValue();
int sliderValue = toSliderValue(newValue);
int halfPixel = halfPixelValue();
if (myAutoRangingP) {
double max = mySliderRange.getUpperBound();
double min = mySliderRange.getLowerBound();
// adjust the upper or lower slider bounds, if necessary
DoubleInterval newRange = null;
if (newValue > max) {
newRange = new DoubleInterval(min, newValue);
} else if (newValue < min) {
newRange = new DoubleInterval(newValue, max);
}
if (newRange != null) {
newRange = SliderRange.roundBoundsTo125(newRange);
// make sure hard range OK
newRange.intersect(getRange());
setSliderRange(newRange);
}
// and if this widget does not have hard bounds
if (!myRange.isBounded() && mySlider != null) {
if (sliderValue < halfPixel && newValue > min) {
double newMax = SliderRange.roundUp125(min + 4 * (newValue - min));
setSliderRange(new DoubleInterval(min, newMax));
}
}
}
if (sliderValue < -halfPixel || sliderValue > SLIDER_INTERNAL_RANGE + halfPixel) {
mySlider.setBackground(Color.GRAY);
} else {
mySlider.setBackground(null);
}
}
return true;
} else {
return false;
}
}
use of maspack.util.DoubleInterval in project artisynth_core by artisynth.
the class DoubleIntervalField method textToValue.
@Override
public Object textToValue(String[] text, boolean[] corrected, StringHolder errMsg) {
DoubleInterval tmp = new DoubleInterval();
if ((LabeledTextField.isBlank(text[0]) || LabeledTextField.isBlank(text[1]))) {
return setVoidIfPossible(errMsg);
}
try {
tmp.setLowerBound(DoubleField.parseDouble(text[0]));
corrected[0] = false;
} catch (Exception e) {
return illegalValue("Improperly formed number for minimum", errMsg);
}
try {
tmp.setUpperBound(DoubleField.parseDouble(text[1]));
corrected[1] = false;
} catch (Exception e) {
return illegalValue("Improperly formed number for maximum", errMsg);
}
return validValue(tmp, errMsg);
}
Aggregations