内部1D区间优化

时间:2015-09-24 09:21:28

标签: java geometry computational-geometry

如果我能优化这个功能,我就会徘徊,这样在优化之后它将使用最少的计算工作。

public class Rectangle2 {
    Vector2 origin;
    Vector2 size;
    public boolean isInside(double x, double y){
        return false;
    }
}

原点被认为是x和y的最小值

谢谢

2 个答案:

答案 0 :(得分:1)

COMMAND:
./shell.sh /tmp/file_{1..12}.xml
string(66) "
FILES: /tmp/file_{1..12}.xml
Posting file /tmp/file_{1..12}.xml
"

x-= origin.x;
y-= origin.y;
return x > 0 && x < size.x && y > 0 && y < size.y;

答案 1 :(得分:-1)

试试这个:

public class Test
{

private static Double MIN_X=0.0;
private static Double MIN_Y=0.0;

private static Double LENGTH=5.0;
private static Double BREADTH=3.0;

private static Integer X_INDEX=0;
private static Integer Y_INDEX=1;

private static Integer LENGTH_INDEX=0;
private static Integer BREADTH_INDEX=1;

Vector<Double> origin=new Vector<>();
Vector<Double> size=new Vector<>();


public static void main(String[] args)
{

    Test test=new Test();

    test.origin.add(X_INDEX, MIN_X);
    test.origin.add(Y_INDEX, MIN_Y);


    test.size.add(LENGTH_INDEX,LENGTH);
    test.size.add(BREADTH_INDEX,BREADTH);

    System.out.println(test.isInside(2.0, 3.0));


}

public boolean isInside(double x, double y)
{
    boolean result=false;

    if((origin.get(X_INDEX)+size.get(LENGTH_INDEX)> x)  &&  (origin.get(Y_INDEX)+size.get(BREADTH_INDEX) > y))
    {
        result=true;

    }

    return result;
}

}