fixed snapping, deprecated Puzzle#findClosest(..)
1 files changed, 13 insertions(+), 5 deletions(-)

M core/src/net/dermetfan/jigsawPuzzle/puzzle/JigsawPuzzle.java
M core/src/net/dermetfan/jigsawPuzzle/puzzle/JigsawPuzzle.java +13 -5
@@ 69,7 69,10 @@ public class JigsawPuzzle {
 			pieces.add(piece);
 	}
 
-	/** @param piece the piece to which to find the closest other piece */
+	/** @param piece the piece to which to find the closest other piece
+	 *  @return the piece most correctly placed in relation to the given piece
+	 *  @deprecated no known use case */
+	@Deprecated
 	public Piece findClosest(Piece piece) {
 		float distance = Float.POSITIVE_INFINITY;
 		Piece closest = null;

          
@@ 169,10 172,15 @@ public class JigsawPuzzle {
 			Actor dragged = payload.getDragActor();
 			Scene2DUtils.addAtStageCoordinates(dragged, (Group) getActor());
 			if(dragged instanceof Piece) {
-				Piece piece = (Piece) dragged, ref = puzzle.findClosest(piece);
-				if(piece.isPlacedCorrectly(ref, tolerance)) {
-					piece.place(ref); // snap it into its perfect position in relation to some already placed piece
-					placed(piece);
+				Piece piece = (Piece) dragged;
+				for(int i = 0; i < puzzle.getPieces().size; i++) {
+					Piece ref = puzzle.getPieces().get(i);
+					if(ref == piece)
+						continue;
+					if(piece.isPlacedCorrectly(ref, tolerance)) {
+						piece.place(ref); // snap it into its perfect position in relation to some already placed piece
+						placed(piece);
+					}
 				}
 			}
 		}