Skip to content

Orientation.Index problem with COLLINEARity #750

@FObermaier

Description

@FObermaier

The following unit test fails:

  public void testCollinear() {
    Coordinate p0 = new Coordinate(0, 100);
    Coordinate p1 = new Coordinate(1, 102.1082);
    Coordinate p2 = new Coordinate(3, 106.3246);

    assertEquals(Orientation.COLLINEAR, Orientation.index(p0, p1, p2));
  }

I'm aware that this is due to floating point arithmetic, so would it be acceptable to add the following overload of Orientation.index:

  /**
   * Returns the orientation index of the direction of the point <code>q</code> relative to
   * a directed infinite line specified by <code>p1-p2</code>.
   * The index indicates whether the point lies to the {@link #LEFT} or {@link #RIGHT}
   * of the line, or lies on it {@link #COLLINEAR}.
   * The index also indicates the orientation of the triangle formed by the three points
   * ( {@link #COUNTERCLOCKWISE}, {@link #CLOCKWISE}, or {@link #STRAIGHT} )
   * 
   * @param p1 the origin point of the line vector
   * @param p2 the final point of the line vector
   * @param q the point to compute the direction to
   * @param eps a threshold value for the determinat to be meaningful
   * 
   * @return -1 ( {@link #CLOCKWISE} or {@link #RIGHT} ) if q is clockwise (right) from p1-p2;
   *         1 ( {@link #COUNTERCLOCKWISE} or {@link #LEFT} ) if q is counter-clockwise (left) from p1-p2;
   *         0 ( {@link #COLLINEAR} or {@link #STRAIGHT} ) if q is collinear with p1-p2
   */
  public static int index(Coordinate p1, Coordinate p2, Coordinate q, double eps)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions