Skip to content

Commit

Permalink
Merge pull request JFXtras#64 from Mario-S/2.2
Browse files Browse the repository at this point in the history
fixed method isMapMoveable in MapPane
  • Loading branch information
mario-s committed Sep 16, 2013
2 parents c209e25 + b78d42d commit a12a1b7
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 17 deletions.
6 changes: 2 additions & 4 deletions src/main/java/jfxtras/labs/map/MapPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,8 @@ public Point getCenter() {

@Override
public boolean isMapMoveable() {
//FIXME: returns false, even when one edge of the map is not visible
// Dimension dim = new Dimension(getMapWidth(), getMapHeight());
// return !mapEdgeChecker.isAllVisible(dim);
return true;
Dimension dim = new Dimension(getMapWidth(), getMapHeight());
return !mapEdgeChecker.isAllVisible(dim);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/jfxtras/labs/map/render/TileRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import jfxtras.labs.map.tile.CacheLoadStrategy;
import jfxtras.labs.map.tile.RefreshLoadStrategy;
import jfxtras.labs.map.tile.TileProvideable;
import jfxtras.labs.map.tile.TileImageComparator;
import jfxtras.labs.map.tile.TileOrderComparator;
import jfxtras.labs.map.tile.TileImage;
import jfxtras.labs.map.tile.TilesLoadable;
import jfxtras.labs.map.tile.TileSource;
Expand All @@ -64,7 +64,7 @@ public class TileRenderer implements TileRenderable {
*/
private static final double WIDTH = 0.4;

private TileImageComparator tileComparator = new TileImageComparator();
private TileOrderComparator tileComparator = new TileOrderComparator();

private boolean monoChrome;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* TileImageComparator.java
* TileOrderComparator.java
*
* Copyright (c) 2011-2013, JFXtras
* All rights reserved.
Expand Down Expand Up @@ -33,17 +33,23 @@

/**
* Compares tiles based on tileX & tileY fields.
*
* @author Mario Schroeder
*
*
*/
public class TileImageComparator implements Comparator<TileImage> {
public class TileOrderComparator implements Comparator<TileImage> {

private static final int EQ = 0;
private static final int HIGH = 1;
private static final int LOW = -1;

@Override
public int compare(TileImage left, TileImage right) {
return (left.getTileX() < right.getTileY()) ? -1
: (left.getTileX() > right.getTileY()) ? +1
: (left.getTileY() < right.getTileY()) ? -1
: (left.getTileY() > right.getTileY()) ? +1 : 0;
}
@Override
public int compare(TileImage left, TileImage right) {

return (left.getTileY() < right.getTileY()) ? LOW :
(left.getTileY() > right.getTileY()) ? HIGH :
(left.getTileX() < right.getTileX()) ? LOW :
(left.getTileX() > right.getTileX()) ? HIGH : EQ;
}

}
2 changes: 1 addition & 1 deletion src/main/java/jfxtras/labs/map/tile/TilesLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class TilesLoader implements TilesLoadable {

private static final int START = 0;

private TileImageComparator tileComparator = new TileImageComparator();
private TileOrderComparator tileComparator = new TileOrderComparator();

private static final Point[] directions = { new Point(1, 0),
new Point(0, 1), new Point(-1, 0), new Point(0, -1) };
Expand Down
100 changes: 100 additions & 0 deletions src/test/java/jfxtras/labs/map/tile/TileOrderComparatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* TileOrderComparatorTest.java
*
* Copyright (c) 2011-2013, JFXtras
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package jfxtras.labs.map.tile;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;


public class TileOrderComparatorTest {

private TileOrderComparator classUnderTest;

private TileImage left, right;

@Before
public void setUp() throws Exception {
classUnderTest = new TileOrderComparator();
left = new TileImage(null, 0, 0);
right = new TileImage(null, 0, 0);
}

@Test
public void testCompare() {

assertEquals(0, classUnderTest.compare(left, right));

left.setTileX(-1);
assertEquals(-1, classUnderTest.compare(left, right));

left.setTileX(1);
assertEquals(1, classUnderTest.compare(left, right));

left.setTileX(0);
assertEquals(0, classUnderTest.compare(left, right));

left.setTileX(0);
left.setTileY(-1);
assertEquals(-1, classUnderTest.compare(left, right));
}

@Test
public void testSorting(){
//construct 2x2 square
right.setTileX(1);
TileImage third = new TileImage(null, 0, 0);
third.setTileY(1);
TileImage fourth = new TileImage(null, 0, 0);
fourth.setTileX(1);
fourth.setTileY(1);

List<TileImage> list = new ArrayList<>();
list.add(third);
list.add(right);
list.add(fourth);
list.add(left);

Collections.sort(list, classUnderTest);

assertEquals(0, list.get(0).getTileX());
assertEquals(0, list.get(0).getTileY());
assertEquals(1, list.get(1).getTileX());
assertEquals(0, list.get(1).getTileY());
assertEquals(0, list.get(2).getTileX());
assertEquals(1, list.get(2).getTileY());
assertEquals(1, list.get(3).getTileX());
assertEquals(1, list.get(3).getTileY());

}
}

0 comments on commit a12a1b7

Please sign in to comment.