/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.lucene.geo;

import org.apache.lucene.util.LuceneTestCase;

import static org.apache.lucene.geo.GeoEncodingUtils.encodeLatitude;
import static org.apache.lucene.geo.GeoEncodingUtils.encodeLongitude;
import static org.apache.lucene.geo.GeoTestUtil.nextBox;

/** Test case for the Polygon {@link Tessellator} class */
public class TestTessellator extends LuceneTestCase {

  public void testLinesIntersect() {
    Rectangle rect = nextBox();
    // quantize lat/lon of bounding box:
    int minX = encodeLongitude(rect.minLon);
    int maxX = encodeLongitude(rect.maxLon);
    int minY = encodeLatitude(rect.minLat);
    int maxY = encodeLatitude(rect.maxLat);
    // simple case; test intersecting diagonals
    assertTrue(Tessellator.linesIntersect(minX, minY, maxX, maxY, maxX, minY, minX, maxY));
    // test closest encoded value
    assertFalse(Tessellator.linesIntersect(minX, maxY, maxX, maxY, minX - 1, minY, minX - 1, maxY));
  }

  public void testSimpleTessellation() throws Exception {
    Polygon poly = GeoTestUtil.createRegularPolygon(0.0, 0.0, 1000000, 1000000);
    Polygon inner = new Polygon(new double[] {-1.0, -1.0, 0.5, 1.0, 1.0, 0.5, -1.0},
        new double[]{1.0, -1.0, -0.5, -1.0, 1.0, 0.5, 1.0});
    Polygon inner2 = new Polygon(new double[] {-1.0, -1.0, 0.5, 1.0, 1.0, 0.5, -1.0},
        new double[]{-2.0, -4.0, -3.5, -4.0, -2.0, -2.5, -2.0});
    poly = new Polygon(poly.getPolyLats(), poly.getPolyLons(), inner, inner2);
    assertTrue(Tessellator.tessellate(poly).size() > 0);
  }
}
@@ -917,163 +917,43 @@
 .Geo
-EncodingUtils.encodeLatitude;%0Aimport static org.apache.lucene.geo.GeoEncodingUtils.encodeLongitude;%0Aimport static org.apache.lucene.geo.GeoTestUtil.nextBox
+TestUtil.nextBoxNotCrossingDateline
 ;%0A%0A/
@@ -1065,16 +1065,48 @@
 Case %7B%0A%0A
+  /** test line intersection */%0A
   public
@@ -1166,367 +1166,313 @@
 tBox
-();%0A    // quantize lat/lon of bounding box:%0A    in
+NotCrossingDateline();%0A    // simple case; tes
 t 
-m
 in
-X = encodeLongitude(rect.minLon);%0A    int maxX = encodeLongitude(rect.maxLon);%0A    int minY = encodeLatitude(rect.minLat);%0A    int maxY = encodeLatitude(rect.maxLat);%0A    // simple case; test intersecting diagonals%0A    assertTrue(Tessellator.linesIntersect(minX, minY, maxX, maxY, maxX, minY, minX, maxY
+tersecting diagonals%0A    // note: we don't quantize because the tessellator operates on non quantized vertices%0A    assertTrue(Tessellator.linesIntersect(rect.minLon, rect.minLat, rect.maxLon, rect.maxLat, rect.maxLon, rect.minLat, rect.minLon, rect.maxLat
 ));%0A
@@ -1552,62 +1552,119 @@
 ect(
-minX, maxY, maxX, maxY, minX
+rect.minLon, rect.maxLat, rect.maxLon, rect.maxLat, rect.minLon
  - 1
+d
 , 
-minY, minX - 1, maxY
+rect.minLat, rect.minLon - 1, rect.maxLat
 ));%0A

Fix simple tessellator test errors