cs2110.collision
Class Shape

java.lang.Object
  extended by cs2110.collision.Shape

public class Shape
extends Object

A shape is a collection of blocks.


Field Summary
(package private)  boolean overlaps
          A flag indicating whether this shape overlaps with some other shape.
(package private)  BlockTree tree
          A hierarchical tree structure for the blocks of the shape.
 
Constructor Summary
Shape(HashSet<Block> blocks)
           
 
Method Summary
(package private)  boolean betterOverlaps(Shape t)
          Better implementation of overlap detection.
 void clear()
          "Clear" the shape from displacement and turned on flags.
 void click()
          Toggle the clickedOn flag.
 boolean contains(cs2110.collision.Vector2D p)
           
 void displace(cs2110.collision.Vector2D v)
          (Further) displace this shape by displacement vector v.
(package private)  cs2110.collision.BoundingBox getAbsBBox()
           
(package private)  cs2110.collision.Vector2D getCenter()
           
(package private)  boolean naiveOverlaps(Shape t)
          Naive implementation of overlap detection.
(package private)  boolean overlaps(Shape t)
           
(package private)  boolean overlapsOffscreen(double width, double height)
           
 void paint(Graphics g, double scale)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

overlaps

boolean overlaps
A flag indicating whether this shape overlaps with some other shape.


tree

BlockTree tree
A hierarchical tree structure for the blocks of the shape.

Constructor Detail

Shape

public Shape(HashSet<Block> blocks)
Parameters:
blocks - A collection of blocks.
Method Detail

getCenter

cs2110.collision.Vector2D getCenter()
Returns:
The center of the bounding box of the shape.

getAbsBBox

cs2110.collision.BoundingBox getAbsBBox()
Returns:
The bounding box of the image when you account for the displacement.

overlapsOffscreen

boolean overlapsOffscreen(double width,
                          double height)
Parameters:
width - The width of canvas (in image coordinates)
height - The height of canvas (in image coordinates)
Returns:
True iff the object's bounding box is partially offscreen, i.e., outside the [0,width] x [0,height] region.

overlaps

boolean overlaps(Shape t)
Parameters:
t - A shape.
Returns:
True iff this shape overlaps with shape t.

naiveOverlaps

boolean naiveOverlaps(Shape t)
Naive implementation of overlap detection.

Parameters:
t - A shape.
Returns:
True iff this shape overlaps with shape t.

betterOverlaps

boolean betterOverlaps(Shape t)
Better implementation of overlap detection.

Parameters:
t - A shape.
Returns:
True iff this shape overlaps with shape t.

clear

public void clear()
"Clear" the shape from displacement and turned on flags.


displace

public void displace(cs2110.collision.Vector2D v)
(Further) displace this shape by displacement vector v.

Parameters:
v - Displacement v.

paint

public void paint(Graphics g,
                  double scale)
Parameters:
g - A Graphics2D object.
scale - The scale from image coordinates to canvas coordinates.

click

public void click()
Toggle the clickedOn flag.


contains

public boolean contains(cs2110.collision.Vector2D p)
Parameters:
p - A point.
Returns:
True iff this shape contains the point p.