Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 12:27 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed May 16, 2012 12:40 pm 
Offline

Joined: Fri May 04, 2012 3:24 pm
Posts: 3
Hello why isn't this working?

Code:
package edu.chl.codenameg.main;

import org.newdawn.slick.geom.*;

public class RectangleTest {

   public static void main(String[] args) {
      Rectangle big = new Rectangle(0,0,500,500);
      Rectangle small = new Rectangle(10,10,10,10);
      
      System.out.println(big.contains(small));
   }
   
}


Tested with both stable and nightly. Both return false.


Top
 Profile  
 
PostPosted: Wed May 16, 2012 1:55 pm 
Offline
Regular
User avatar

Joined: Thu May 05, 2011 8:35 pm
Posts: 231
Location: Somewhere between the bits and bytes
Yep that seems like a bug and its present in the dev branch too.

It happens because the method is inherited from Shape and that checks whether the shapes intersect, if it does it returns false.
But it conflicts with the Rectangle to Rectangle intersection check, which is a simple but very fast check.

Adding this to Rectangle class appears to fix it, haven't tested it much thou.
Code:
   public boolean contains(Shape other) {
      if (!(other instanceof Rectangle) && other.intersects(this)) {
         return false;
      }

      for (int i = 0; i < other.getPointCount(); i++) {
         float[] pt = other.getPoint(i);
         if (!contains(pt[0], pt[1])) {
            return false;
         }
      }

      return true;
   }

_________________
For every new problem, a new source of solutions has come to exist.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group