2016-04-24 6 views
1

これは私が希望メソッドを記述する方法を把握しようとしています私はJavaFXのを使用していますが、私はポイントがバウンディングボックス内にあるかどうかを判断しようとしています

public class Spot { 

private static final int IMAGE_HEIGHT = 500; 
private static final int IMAGE_WIDTH = 500; 

private static final int DOT_HEIGHT = 20; 
private static final int DOT_WIDTH = 20; 

private static final Color DOT_COLOR = Color.RED; 
private Random ran = new Random(); 

private int x = this.ran.nextInt(IMAGE_WIDTH); 
private int y = this.ran.nextInt(IMAGE_HEIGHT); 
/** 
* Draws spot onto given playfield object 
* 
* @param playfield 
*/ 
public void drawSpot(Playfield playfield) { 
    playfield.getGraphicsContext2D().setFill(DOT_COLOR); 
    playfield.getGraphicsContext2D().fillOval(x, y, DOT_WIDTH, DOT_HEIGHT); 
    this.drawSpot(playfield); 

} 

を使用していたクラスです指定されたx座標とy座標が境界ボックスの内側にあるかどうかを判定します。

public boolean isINSpot(int x, int y){ 
     if (x > this.x && x < this.x + DOT_WIDTH && y > this.y && y < this.y + DOT_HEIGHT) { 
     return false; 
    } else { 
     return true; 
    } 
    } 
} 

}

+0

[Point inside oriented bounding box?]の可能な複製?(http://stackoverflow.com/questions/13493070/point-inside-oriented-bounding-box) – OldUgly

答えて

0

これが役立つことがあります。

return x > boxX && x < boxX + boxWidth && y > boxY && y < boxY + boxHeight; 

はない場合、私はめちゃくちゃ。

+0

falseを返すには、これをif文の内側に置く必要がありますかポイントがドットの中に入っていることを確認するためにassertTrueを使ってテストクラスを書いたら? – runemonster

+0

isINspotメソッドにあります – TheKindOfGoodProgrammer