Commit 9a321df4 authored by Eric Tobias's avatar Eric Tobias

Added cloning facilities to the object

parent 2137eeba
......@@ -12,6 +12,7 @@ Implementation of XML based bootstrapping for widgets and coronas.
+ Removed the field "background" and all related methods from Corona. Adjusted Image accordingly. The field was not used. Conceptually, coronas should never be part of the background.
+ Added ValueProvider interface.
+ Made TangibleObject Cloneable and added facilities to produce a constrained (by position) clone.
-- Bugfixes --
......
......@@ -29,12 +29,12 @@ import java.util.logging.Logger;
* Class which defines common attributes of a tangible object.
*
* @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @author Eric TOBIAS [eric.tobias@list.lu]
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.0
* @version 2.0.41
* @version 2.2.2
*/
@NonNullByDefault
public class TangibleObject {
public class TangibleObject implements Cloneable {
/** Enumeration of different types of objects recognised */
public enum Type {
/** Type denoting that the object is a physical entity represented by a tag or marker. */
......@@ -520,4 +520,41 @@ public class TangibleObject {
public int hashCode() {
return getObjectId();
}
@Override
public TangibleObject clone() {
return new TangibleObjectBuilder(objectId, Type.OBJECT, 0, 0)
.withSeconds(seconds)
.withMicroSeconds(microSeconds)
.withxSpeed(xSpeed)
.withySpeed(ySpeed)
.withMotionSpeed(motionSpeed)
.withMotionAccel(motionAccel)
.withRotationSpeed(rotationSpeed)
.withRotationAccel(rotationAccel)
.withPath(path)
.withState(state)
.build();
}
/**
* Method used to produce a clone of this instance with the last element of the path, the most
* recent position of the object, replaced by a given point. This is used to modify the latest
* position in order to restrain any rotation or movement. This should be used with caution as
* modifications might have repercussions on the responsiveness of the application and the
* digital-tangible dimensional barrier.
*
* @param point
* The point holding the modified position of the object.
* @return The modified object.
*/
public TangibleObject constrainedClone(Point point) {
ArrayList<Point> newPath = new ArrayList<>(path);
newPath.set(newPath.size() - 1, point);
TangibleObject contrainedClone = clone();
contrainedClone.setPath(newPath);
return contrainedClone;
}
}
\ No newline at end of file
......@@ -218,7 +218,7 @@ public class BaseWidget {
*
* @return The position as a {@link Point} of the handle with the lowest ID.
*/
public Point getPosition() {
public @Nullable Point getPosition() {
List<Integer> keys = new ArrayList<>(positions.keySet());
Collections.sort(keys, Ordering.natural());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment