001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.renderer.shape;
017:
018: import junit.framework.TestCase;
019:
020: /**
021: * @source $URL:
022: * http://svn.geotools.org/geotools/branches/2.2.x/ext/shaperenderer/test/org/geotools/renderer/shape/ScreenMapTest.java $
023: */
024: public class ScreenMapTest extends TestCase {
025: private int xmin;
026: private int width;
027: private int height;
028: private int ymin;
029:
030: /*
031: * Test method for 'org.geotools.renderer.shape.ScreenMap.set(int, int)'
032: */
033: public void testSet() {
034: ymin = xmin = 0;
035: height = width = 8;
036: ScreenMap map = new ScreenMap(0, 0, 8, 8);
037:
038: for (int x = 0; x < 8; x++) {
039: for (int y = 0; y < 8; y++) {
040: assertEquals(false, map.get(x, y));
041: }
042: }
043:
044: setOne(map, 0, 0, true, false);
045: setOne(map, 0, 0, false, true);
046: setOne(map, 3, 4, true, false);
047: setAll(map, true);
048: setAll(map, false);
049: }
050:
051: private void setOne(ScreenMap map, int xconst, int yconst,
052: boolean bool, boolean expectedOldValue) {
053: assertEquals(expectedOldValue, map.get(xconst, yconst));
054: map.set(xconst, yconst, bool);
055:
056: for (int x = xmin; x < width; x++) {
057: for (int y = ymin; y < height; y++) {
058: if ((x == xconst) && (y == yconst)) {
059: assertEquals("x=" + x + " y=" + y, bool, map.get(x,
060: y));
061: } else {
062: assertEquals("x=" + x + " y=" + y, false, map.get(
063: x, y));
064: }
065: }
066: }
067: }
068:
069: private void setAll(ScreenMap map, boolean value) {
070: for (int x = xmin; x < width; x++) {
071: for (int y = ymin; y < height; y++) {
072: map.set(x, y, value);
073: }
074: }
075:
076: for (int x = xmin; x < width; x++) {
077: for (int y = ymin; y < height; y++) {
078: assertEquals(value, map.get(x, y));
079: }
080: }
081: }
082:
083: public void testSubsetScreen() throws Exception {
084: xmin = 478;
085: ymin = 0;
086: width = 283;
087: height = 452;
088: ScreenMap map = new ScreenMap(xmin, ymin, width + 1, height + 1);
089:
090: // test 4 corners
091: setOne(map, xmin, ymin, true, false);
092: setOne(map, xmin, ymin, false, true);
093:
094: setOne(map, xmin + width - 1, ymin, true, false);
095: setOne(map, xmin + width - 1, ymin, false, true);
096:
097: setOne(map, xmin + width - 1, ymin + height - 1, true, false);
098: setOne(map, xmin + width - 1, ymin + height - 1, false, true);
099:
100: setOne(map, xmin, ymin + height - 1, true, false);
101: setOne(map, xmin, ymin + height - 1, false, true);
102:
103: // test a couple edges
104: setOne(map, xmin + 7, ymin, true, false);
105: setOne(map, xmin + 7, ymin, false, true);
106:
107: setOne(map, xmin + width - 1, ymin + 10, true, false);
108: setOne(map, xmin + width - 1, ymin + 10, false, true);
109:
110: setOne(map, xmin + 5, ymin + height - 1, true, false);
111: setOne(map, xmin + 5, ymin + height - 1, false, true);
112:
113: setOne(map, xmin, ymin + 7, true, false);
114: setOne(map, xmin, ymin + 7, false, true);
115:
116: // test the case I know fails
117: setOne(map, 728, 427, true, false);
118:
119: setAll(map, true);
120: setAll(map, false);
121:
122: }
123: }
|