package com.ddChat.graphic;
public class GData
{
private double value;
private int resolution;
private final int MIN_RESOLUTION = 0;
private final int MAX_RESOLUTION = 10;
public GData()
{
}
public GData(double value, int resolution)
{
super();
resolution = resolution < MIN_RESOLUTION ? MIN_RESOLUTION : resolution;
resolution = resolution > MAX_RESOLUTION ? MAX_RESOLUTION : resolution;
this.value = value;
this.resolution = resolution;
}
public double getValue()
{
return value;
}
public void setValue(double value)
{
this.value = value;
}
public int getResolution()
{
return resolution;
}
public void setResolution(int resolution)
{
this.resolution = resolution;
}
public int toInt()
{
return (int) (value * Math.pow(10, resolution));
}
public GData floor(GData base)
{
GData result = new GData();
double baseValue = base.getValue();
double scale = Math.pow(10, base.getResolution());
int scaleBaseValue = (int) (scale * baseValue);
int valueInt = toInt();
scaleBaseValue = scaleBaseValue >= 0 ?scaleBaseValue :-scaleBaseValue;
double modValue = valueInt % scaleBaseValue;
result.setResolution(base.getResolution());
if(modValue < 0 )
{
result.setValue((valueInt - modValue - scaleBaseValue)/scale);
}
else if(modValue == 0 )
{
result.setValue(valueInt/scale);
}
else
{
result.setValue((valueInt - modValue)/scale);
}
return result;
}
public GData ceil(GData base)
{
GData result = new GData();
double baseValue = base.getValue();
baseValue = baseValue >= 0 ?baseValue :-baseValue;
double scale = Math.pow(10, base.getResolution());
int scaleBaseValue = (int) (scale * baseValue);
int valueInt = toInt();
scaleBaseValue = scaleBaseValue >= 0 ?scaleBaseValue :-scaleBaseValue;
double modValue = valueInt % scaleBaseValue;
result.setResolution(base.getResolution());
if(modValue < 0 )
{
result.setValue((valueInt - modValue)/scale );
}
else if(modValue == 0 )
{
result.setValue(valueInt/scale);
}
else
{
result.setValue((valueInt - modValue + scaleBaseValue)/scale);
}
return result;
}
@Override
public String toString()
{
return "GData [value=" + value + ", resolution=" + resolution + "]";
}
public static void main(String[] args)
{
GData min = new GData(10, 1);
GData max = new GData(10.8, 1);
TickInfo ti = new TickInfo(min, max);
System.out.println("ti.getMin()"+ti.getMin());
System.out.println("ti.getMax()"+ti.getMax());
System.out.println("ti.getAlignMin()"+ti.getAlignMin());
System.out.println("ti.getAlignMax()"+ti.getAlignMax());
}
}
阅读(869) | 评论(0) | 转发(0) |