title: Collision between Circle and Rectangle doesnt work in corners ( javafx )
body: <p>Greetings SOCommunity,</p>
  
  <p>Right now I m trying to learn Collision-detection between shapes. The detection itself works fine. But the relocation of the object doesnt work completly.</p>
  
  <p>So whenever my Circle touches the rectangle´s corners the relocation doesnt work.</p>
  
  <p>Here´s my code:</p>
  
  <pre><code>public class Collision extends Application {
  
  @Override
  public void start(Stage stage) {
  
      Group root = new Group();
      Scene scene = new Scene(root, 600, 600, Color.CADETBLUE);
  
  // Nodes
      Rectangle bounds = new Rectangle(500,500, Color.TRANSPARENT);
      bounds.setStroke(Color.WHITE);
      bounds.setStrokeWidth(5);
      bounds.setTranslateX(50);
      bounds.setTranslateY(50);
  
      Circle c1 = new Circle(30, Color.WHITE);
      c1.setTranslateX(300);
      c1.setTranslateY(300);
  
  // Events
  
      // Collision Detection and c1 movement
      EventHandler&lt;MouseEvent&gt; handle = new EventHandler&lt;MouseEvent&gt;() {      
  
          double difX;    // Circle to mouse difference
          double difY;
  
          double reloX;   // Circle touches bounds
          double reloY;
  
          Bounds nodeBounds = c1.getBoundsInLocal();  // Bound Objects for Node and Rect
          Bounds bound = bounds.getBoundsInLocal();
  
          public void handle(MouseEvent event) {
  
              // If Pressed save Coordinates
              if(event.getEventType() == MouseEvent.MOUSE_PRESSED) {
  
                  difX = event.getX();
                  difY = event.getY();      
  
              }
              // If Dragged check Collision and relocate
              else if(event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
  
                  c1.setTranslateX( event.getSceneX() - difX );
                  c1.setTranslateY( event.getSceneY() - difY );
  
  
                  if( c1.localToScene(nodeBounds).getMinX() &lt; bounds.localToScene(bound).getMinX() ) {
                      bounds.setStroke(Color.RED);
                      c1.setTranslateX( bound.getMinX() - nodeBounds.getMinX() + 50 );
                  }
                  else if( c1.localToScene(nodeBounds).getMinY() &lt; bounds.localToScene(bound).getMinY() ) { 
                      bounds.setStroke(Color.RED);
                      c1.setTranslateY( bound.getMinY() - nodeBounds.getMinY() + 50 );
                  }
                  else if( c1.localToScene(nodeBounds).getMaxX() &gt; bounds.localToScene(bound).getMaxX() ) { 
                      bounds.setStroke(Color.RED);
                      c1.setTranslateX( bound.getMaxX() - nodeBounds.getMaxX() + 50 );
                  }
                  else if( c1.localToScene(nodeBounds).getMaxY() &gt; bounds.localToScene(bound).getMaxY() ) { 
                      bounds.setStroke(Color.RED);
                      c1.setTranslateY( bound.getMaxY() - nodeBounds.getMaxY() + 50 );
                  }                   
                  else {
                      bounds.setStroke(Color.WHITE);
                  }
  
              }       
  
  
          }
      };
  
      c1.addEventHandler(MouseEvent.ANY, handle);
  
  //Stage is setUp
      root.getChildren().addAll(bounds, c1);
      stage.setTitle("omfg, srsly !?");
      stage.setScene(scene);
      stage.show();
  }
  
  public static void main(String[] args) {
      launch(args);}}
  </code></pre>
  
  <p>Please help me to find out why this doesnt work and how i could get it to work.</p>
  
  <p>Thx in advance :)</p>