Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1505232
  • 博文数量: 108
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 997
  • 用 户 组: 普通用户
  • 注册时间: 2013-06-29 09:58
个人简介

兴趣是坚持一件事永不衰竭的动力

文章分类

全部博文(108)

文章存档

2021年(1)

2020年(10)

2019年(19)

2018年(9)

2016年(23)

2015年(43)

2013年(3)

我的朋友

分类: Java

2015-11-24 23:48:09

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());


}


}

阅读(877) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~