2019-10-22 07:15:35 +02:00
|
|
|
/*
|
2018-12-23 03:07:31 +05:30
|
|
|
* The MIT License
|
2019-10-12 20:05:54 +03:00
|
|
|
* Copyright © 2014-2019 Ilkka Seppälä
|
2018-12-23 03:07:31 +05:30
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-10-22 07:15:35 +02:00
|
|
|
|
2018-12-23 03:07:31 +05:30
|
|
|
package com.iluwatar.spatialpartition;
|
|
|
|
|
2020-01-04 22:06:08 +05:30
|
|
|
import java.util.Collection;
|
2021-01-30 17:07:52 +05:30
|
|
|
import java.util.HashMap;
|
2018-12-23 03:07:31 +05:30
|
|
|
|
|
|
|
/**
|
2019-11-12 01:51:12 +05:30
|
|
|
* The abstract Point class which will be extended by any object in the field whose location has to
|
|
|
|
* be kept track of. Defined by x,y coordinates and an id for easy hashing into hashtable.
|
|
|
|
*
|
2018-12-23 03:07:31 +05:30
|
|
|
* @param <T> T will be type subclass
|
|
|
|
*/
|
|
|
|
|
|
|
|
public abstract class Point<T> {
|
|
|
|
|
2019-11-12 01:51:12 +05:30
|
|
|
public int coordinateX;
|
|
|
|
public int coordinateY;
|
2018-12-23 03:07:31 +05:30
|
|
|
public final int id;
|
2019-11-12 01:51:12 +05:30
|
|
|
|
2018-12-23 03:07:31 +05:30
|
|
|
Point(int x, int y, int id) {
|
2019-11-12 01:51:12 +05:30
|
|
|
this.coordinateX = x;
|
|
|
|
this.coordinateY = y;
|
2018-12-23 03:07:31 +05:30
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-12 01:51:12 +05:30
|
|
|
* defines how the object moves.
|
2018-12-23 03:07:31 +05:30
|
|
|
*/
|
|
|
|
abstract void move();
|
2019-11-12 01:51:12 +05:30
|
|
|
|
2018-12-23 03:07:31 +05:30
|
|
|
/**
|
2019-11-12 01:51:12 +05:30
|
|
|
* defines conditions for interacting with an object obj.
|
|
|
|
*
|
2018-12-23 03:07:31 +05:30
|
|
|
* @param obj is another object on field which also extends Point
|
|
|
|
* @return whether the object can interact with the other or not
|
|
|
|
*/
|
|
|
|
abstract boolean touches(T obj);
|
2019-11-12 01:51:12 +05:30
|
|
|
|
2018-12-23 03:07:31 +05:30
|
|
|
/**
|
2019-11-12 01:51:12 +05:30
|
|
|
* handling interactions/collisions with other objects.
|
|
|
|
*
|
2020-01-04 22:06:08 +05:30
|
|
|
* @param toCheck contains the objects which need to be checked
|
|
|
|
* @param all contains hashtable of all points on field at this time
|
2018-12-23 03:07:31 +05:30
|
|
|
*/
|
2021-01-30 17:07:52 +05:30
|
|
|
abstract void handleCollision(Collection<? extends Point> toCheck, HashMap<Integer, T> all);
|
2018-12-23 03:07:31 +05:30
|
|
|
}
|