Package chunmap.model.elem

Source Code of chunmap.model.elem.MonotonyChainTest

/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
*     2010-05-05  Jed Young  Creation
*/
package chunmap.model.elem;

import static org.junit.Assert.*;

import org.junit.Test;

import chunmap.model.algorithm.MonotonyChain;
import chunmap.model.coord.Coordinate2D;
import chunmap.model.coord.CPoint;

/**
* @author chunquedong
*
*/
public class MonotonyChainTest {

  /**
   * {@link chunmap.model.algorithm.MonotonyChain#intersection(chunmap.model.algorithm.MonotonyChain)}
   * 的测试方法。
   */
  @Test
  public void testIntersection() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(1, 2);
    CPoint p3 = new Coordinate2D(0.5, 0.9);
    CPoint p4 = new Coordinate2D(1, 1);

    chain1.add(p1);
    chain1.add(p2);
    chain2.add(p3);
    chain2.add(p4);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.size() == 0);
  }

  @Test
  public void testIntersection2() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(1, 2);
    CPoint p3 = new Coordinate2D(0.5, 1);
    CPoint p4 = new Coordinate2D(1, 1);

    chain1.add(p1);
    chain1.add(p2);
    chain2.add(p3);
    chain2.add(p4);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.size() == 1);
  }

  @Test
  public void testIntersection3() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(1, 2);
    CPoint p3 = new Coordinate2D(0.5, 1);
    CPoint p5 = new Coordinate2D(2, 0);
    CPoint p6 = new Coordinate2D(2, 1);

    chain1.add(p1);
    chain1.add(p2);
    chain1.add(p5);

    chain2.add(p3);
    chain2.add(p6);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.size() == 2);
  }

  @Test
  public void testIntersection4() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(1, 2);
    CPoint p2 = new Coordinate2D(1, 2);

    chain1.add(p1);
    chain2.add(p2);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.size() == 1);
  }

  @Test
  public void testIntersection5() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(1, 2);
    CPoint p3 = new Coordinate2D(0.5, 1);

    chain1.add(p1);
    chain1.add(p2);
    chain2.add(p3);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.size() == 1);
  }

  @Test
  public void testIntersection6() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(1, 2);
    CPoint p3 = new Coordinate2D(0, 0);
    CPoint p4 = new Coordinate2D(1, 2);

    chain1.add(p1);
    chain1.add(p2);
    chain2.add(p3);
    chain2.add(p4);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.size() == 1);
  }

  @Test
  public void testIntersection7() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(1, 2);
    CPoint p3 = new Coordinate2D(0.5, 1);
    CPoint p4 = new Coordinate2D(2, 2);

    chain1.add(p1);
    chain1.add(p2);
    chain1.add(p4);

    chain2.add(p3);
    chain2.add(p2);
    chain2.add(p4);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.size() == 1);
  }

  @Test
  public void testIntersection8() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(1, 0);

    chain1.add(p1);
    chain1.add(p2);

    chain2.add(p1);
    chain2.add(p2);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.size() == 1);
  }

  @Test
  public void testIntersection9() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(0, -1);

    chain1.add(p1);
    chain1.add(p2);

    chain2.add(p1);
    chain2.add(p2);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.size() == 1);
  }

  @Test
  public void testIntersection10() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(1, 2);
    CPoint p4 = new Coordinate2D(2, 2);
    CPoint p5 = new Coordinate2D(0.5, 2.8);
    CPoint p6 = new Coordinate2D(3, 3);
    CPoint p7 = new Coordinate2D(2, 1);

    chain1.add(p1);
    chain1.add(p2);
    chain1.add(p4);
    chain1.add(p6);

    chain2.add(p5);
    chain2.add(p2);
    chain2.add(p4);
    chain2.add(p7);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.size() == 1);
  }

  @Test
  public void testIntersection11() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(0, 2);

    chain1.add(p1);
    chain1.add(p2);

    chain2.add(p2);
    chain2.add(p1);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.getPointSize() == 0);
    assertTrue(geos.getLineStringSize() == 1);
  }

  @Test
  public void testIntersection12() {
    MonotonyChain chain1 = new MonotonyChain();
    MonotonyChain chain2 = new MonotonyChain();

    CPoint p1 = new Coordinate2D(0, 0);
    CPoint p2 = new Coordinate2D(1, 0);
    CPoint p3 = new Coordinate2D(2, 0);

    chain1.add(p1);
    chain1.add(p2);

    chain2.add(p2);
    chain2.add(p3);

    PointLineBag geos = chain1.intersection(chain2);

    assertTrue(geos.getPointSize() == 1);
    assertTrue(geos.getLineStringSize() == 0);
  }
}
TOP

Related Classes of chunmap.model.elem.MonotonyChainTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.