开发者

Android overriding PointF to get something close to java Point2D.double

开发者 https://www.devze.com 2023-03-19 07:01 出处:网络
I have a java method that returns Point2D.double and Android\'s closest class to this is PointF. The issue is that Po开发者_开发知识库intF returns float rather than double. Is there a way to override

I have a java method that returns Point2D.double and Android's closest class to this is PointF. The issue is that Po开发者_开发知识库intF returns float rather than double. Is there a way to override PointF so that it is double rather than float?


Why dont you just convert your doubles to floats then use PointF, you could do that with a simple cast, unless you need to keep the data as doubles for some other purpose, if thats the case you could try extending the PointF class as below, it will be slower than just using PointF due to all the casting and manipulating of the doubles to floats etc but so long as your not calling it too often it should be ok!

public class pointD extends PointF{

public double x;
public double y;

public pointD(double x, double y){
    this.set((float) x,(float) y);
    this.x = x;
    this.y = y;
}

public double Length(){
    double l = (double)this.length();
    return l;
}

public final void set(double x, double y){
    this.set((float) x,(float) y);
    this.x = x;
    this.y = y;
}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号