예제 #1
0
bool geo_polygon_segment_intersects(const geo_polygon_type * polygon , double x1 , double y1 , double x2 , double y2) {
  bool intersects = false;
  double ** points = (double**)util_malloc( 4 * sizeof * points);
  {
    int i;
    for (i = 0; i < 4; i++)
      points[i] = (double*)util_malloc( 2 * sizeof * points[i]);
  }

  points[0][0] = x1;
  points[1][0] = x2;
  points[0][1] = y1;
  points[1][1] = y2;

  {
    int index = 0;
    while (true) {

      if (index >= (geo_polygon_get_size( polygon ) - 1))
        break;

      {
        double xc,yc;

        points[2][0] = double_vector_iget( polygon->xcoord , index );
        points[3][0] = double_vector_iget( polygon->xcoord , index + 1);
        points[2][1] = double_vector_iget( polygon->ycoord , index );
        points[3][1] = double_vector_iget( polygon->ycoord , index + 1);

        {
          geo_util_xlines_status_enum xline_status = geo_util_xsegments(( const double **) points , &xc , &yc);
          if ((xline_status == GEO_UTIL_LINES_CROSSING) ||
              (xline_status == GEO_UTIL_LINES_OVERLAPPING))
            intersects = true;
        }

        if (intersects)
          break;

      }

      index++;
    }
  }

  {
    int i;
    for (i = 0; i < 4; i++)
      free(points[i]);

    free( points );
  }

  return intersects;
}
예제 #2
0
void test_overlapping_lines_not_in_contact_vertical(double ** points) {
  double x0 = -100;
  double y0 = -100;

  points[0][0] = 0;
  points[1][0] = 0;

  points[0][1] = 0;
  points[1][1] = 1;


  points[2][0] = 0;
  points[3][0] = 0;

  points[2][1] = 2;
  points[3][1] = 3;

  test_assert_int_equal(GEO_UTIL_NOT_CROSSING , geo_util_xsegments( (const double **) points , &x0 , &y0 ));
  test_assert_double_equal( x0 , -100 );
  test_assert_double_equal( y0 , -100 );
}