change value constrain

This commit is contained in:
interfisch 2019-06-10 22:24:43 +02:00
parent 63494cf384
commit 49b28848bc
1 changed files with 14 additions and 11 deletions

View File

@ -33,7 +33,8 @@ abstract class Visualization
public abstract void drawVis(); public abstract void drawVis();
public void setValue(float pv){ public void setValue(float pv){
this.value=constrain(pv,valueMin,valueMax); //this.value=constrain(pv,valueMin,valueMax);
this.value=pv;
if (this.showMinMax){ if (this.showMinMax){
if (Float.isNaN(this.valueMinRecord) || this.value<this.valueMinRecord){ if (Float.isNaN(this.valueMinRecord) || this.value<this.valueMinRecord){
this.valueMinRecord=this.value; this.valueMinRecord=this.value;
@ -45,7 +46,8 @@ abstract class Visualization
} }
public void setValue2(float pv){ public void setValue2(float pv){
this.value2=constrain(pv,valueMin,valueMax); //this.value2=constrain(pv,valueMin,valueMax);
this.value2=pv;
if (this.showMinMax){ if (this.showMinMax){
if (Float.isNaN(this.value2MinRecord) || this.value2<this.value2MinRecord){ if (Float.isNaN(this.value2MinRecord) || this.value2<this.value2MinRecord){
this.value2MinRecord=this.value2; this.value2MinRecord=this.value2;
@ -57,23 +59,23 @@ abstract class Visualization
} }
public float getValueNormalized() { public float getValueNormalized() {
return (this.value-this.valueMin)/(this.valueMax-this.valueMin); return (constrain(this.value,this.valueMin,this.valueMax)-this.valueMin)/(this.valueMax-this.valueMin);
} }
public float getValueMinNormalized() { public float getValueMinNormalized() {
return (this.valueMinRecord-this.valueMin)/(this.valueMax-this.valueMin); return (constrain(this.valueMinRecord,this.valueMin,this.valueMax)-this.valueMin)/(this.valueMax-this.valueMin);
} }
public float getValueMaxNormalized() { public float getValueMaxNormalized() {
return (this.valueMaxRecord-this.valueMin)/(this.valueMax-this.valueMin); return (constrain(this.valueMaxRecord,this.valueMin,this.valueMax)-this.valueMin)/(this.valueMax-this.valueMin);
} }
public float getValue2Normalized() { public float getValue2Normalized() {
return (this.value2-this.value2Min)/(this.value2Max-this.value2Min); return (constrain(this.value2,this.valueMin,this.valueMax)-this.value2Min)/(this.value2Max-this.value2Min);
} }
public float getValue2MinNormalized() { public float getValue2MinNormalized() {
return (this.value2MinRecord-this.value2Min)/(this.value2Max-this.value2Min); return (constrain(this.value2MinRecord,this.valueMin,this.valueMax)-this.value2Min)/(this.value2Max-this.value2Min);
} }
public float getValue2MaxNormalized() { public float getValue2MaxNormalized() {
return (this.value2MaxRecord-this.value2Min)/(this.value2Max-this.value2Min); return (constrain(this.value2MaxRecord,this.valueMin,this.valueMax)-this.value2Min)/(this.value2Max-this.value2Min);
} }
public void setShowMinMax(boolean pshowMinMax){ public void setShowMinMax(boolean pshowMinMax){
@ -278,8 +280,9 @@ public class Direction extends Visualization {
ellipse(super.posOrigin.x, super.posOrigin.y, this.size,this.size); ellipse(super.posOrigin.x, super.posOrigin.y, this.size,this.size);
stroke(super.cmain); stroke(super.cmain);
float angle=map(super.value,super.valueMin,super.valueMax,0,2*PI)+this.angleoffset; float angle=map(super.getValueNormalized(),0,1,0,2*PI)+this.angleoffset;
float _vecsize=this.size*( (super.value2-super.value2Min)/(super.value2Max-super.value2Min)); //float _vecsize=this.size*( (super.value2-super.value2Min)/(super.value2Max-super.value2Min));
float _vecsize=this.size*super.getValue2Normalized();
line(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+cos(angle)*_vecsize,super.posOrigin.y-sin(angle)*_vecsize); line(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+cos(angle)*_vecsize,super.posOrigin.y-sin(angle)*_vecsize);
line(super.posOrigin.x+cos(angle-0.1)*_vecsize*0.9,super.posOrigin.y-sin(angle-0.1)*_vecsize*0.9,super.posOrigin.x+cos(angle)*_vecsize,super.posOrigin.y-sin(angle)*_vecsize); //arrow line(super.posOrigin.x+cos(angle-0.1)*_vecsize*0.9,super.posOrigin.y-sin(angle-0.1)*_vecsize*0.9,super.posOrigin.x+cos(angle)*_vecsize,super.posOrigin.y-sin(angle)*_vecsize); //arrow