Package chunmap.model.elem

Source Code of chunmap.model.elem.LineSegmentTest

/**
* 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.coord.Coordinate2D;
import chunmap.model.coord.CPoint;
import chunmap.model.geom.LineString;

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

  /**
   * {@link chunmap.model.elem.LineSegment#intersection(chunmap.model.elem.LineSegment)}
   * 的测试方法。
   */
  @Test
  public void testIntersection() {
    CPoint p1 = new Coordinate2D(10, 10);
    CPoint p2 = new Coordinate2D(0, 0);
    CPoint p3 = new Coordinate2D(0, 10);
    CPoint p4 = new Coordinate2D(10, 0);
    CPoint p5 = new Coordinate2D(5, 5);
    CPoint p6 = new Coordinate2D(-1, -1);
    CPoint p7 = new Coordinate2D(-1, 7);

    LineSegment lseg1 = new LineSegment(p1, p2);
    LineSegment lseg2 = new LineSegment(p3, p4);

    CPoint p = (CPoint) lseg1.intersection(lseg2);
    CPoint ep = new Coordinate2D(5, 5);
    assertTrue(p.equals(ep));

    LineSegment lseg3 = new LineSegment(p5, p6);

    LineString l = new LineString((CPoint[]) lseg1.intersection(lseg3));
    assertTrue(l.toString().equals("LINESTRING(0.0 0.0,5.0 5.0)"));

    LineSegment lseg4 = new LineSegment(p6, p7);

    assertTrue(lseg1.intersection(lseg4) == null);
  }

  @Test
  public void testIntersection2() {
    CPoint p1 = new Coordinate2D(3, 1);
    CPoint p2 = new Coordinate2D(4, 0);
    CPoint p3 = new Coordinate2D(1, 0.5);
    CPoint p4 = new Coordinate2D(3, 0.5);

    LineSegment lseg1 = new LineSegment(p1, p2);
    LineSegment lseg2 = new LineSegment(p3, p4);

    assertTrue(lseg1.intersection(lseg2) == null);

  }

  /**
   * {@link chunmap.model.elem.LineSegment#onLineSegment(chunmap.model.geom.CPoint)}
   * 的测试方法。
   */
  @Test
  public void testOnLineSegment() {
    CPoint p1 = new Coordinate2D(10, 10);
    CPoint p2 = new Coordinate2D(0, 0);
    CPoint p3 = new Coordinate2D(0, 10);
    CPoint p4 = new Coordinate2D(10, 10);
    CPoint p5 = new Coordinate2D(5, 5);

    LineSegment lseg1 = new LineSegment(p1, p2);

    boolean b1 = lseg1.onLineSegment(p5);
    boolean b2 = lseg1.onLineSegment(p3);
    boolean b3 = lseg1.onLineSegment(p4);
    assertTrue(b1);
    assertFalse(b2);
    assertTrue(b3);
  }

  @Test
  public void testDingBiFenDian() {
    CPoint p1 = new Coordinate2D(10, 10);
    CPoint p2 = new Coordinate2D(20, 20);
    CPoint p3 = new Coordinate2D(12, 12);
    LineSegment lseg1 = new LineSegment(p1, p2);

    assertTrue(lseg1.getMiddlePoint().equals(lseg1.dingBiFenDian(1)));
    assertTrue(p3.equals(lseg1.dingBiFenDian(0.25)));
  }

  @Test
  public void testContainLineSegment() {
    CPoint p1 = new Coordinate2D(10, 10);
    CPoint p2 = new Coordinate2D(0, 0);
    CPoint p3 = new Coordinate2D(5, 5);
    LineSegment lseg1 = new LineSegment(p1, p2);
    LineSegment lseg2 = new LineSegment(p2, p3);
    assertTrue(lseg1.containLineSegment(lseg2));
    assertTrue(lseg1.containLineSegment(lseg1));
  }
}
TOP

Related Classes of chunmap.model.elem.LineSegmentTest

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.