| Total Complexity | 10 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | package org.gannacademy.cdf.graphics.curriculum; |
||
| 8 | public class Sprite { |
||
| 9 | private List<Drawable> components; |
||
| 10 | |||
| 11 | public Sprite() { |
||
| 12 | components = new Vector<>(); |
||
| 13 | } |
||
| 14 | |||
| 15 | public void addComponent(Drawable component) { |
||
| 16 | if (!components.contains(component)) { |
||
| 17 | components.add(component); |
||
| 18 | } |
||
| 19 | } |
||
| 20 | |||
| 21 | public boolean intersects(Sprite other) { |
||
| 22 | for(Drawable component : components) { |
||
| 23 | for (Drawable otherComponent : other.components) { |
||
| 24 | if (component.intersects(otherComponent.getBounds())) { |
||
| 25 | return true; |
||
| 26 | } |
||
| 27 | } |
||
| 28 | } |
||
| 29 | return false; |
||
| 30 | } |
||
| 31 | |||
| 32 | public double getTop() { |
||
| 33 | double top = Double.MAX_VALUE; |
||
| 34 | for(Drawable component:components) { |
||
| 35 | top = Math.min(top, component.getY()); |
||
| 36 | } |
||
| 37 | if (top == Double.MAX_VALUE) { |
||
| 38 | return Double.NaN; |
||
| 39 | } |
||
| 40 | return top; |
||
| 41 | } |
||
| 43 |