Exemplo n.º 1
0
int reg_shape_overlap( regShape* shape1, regShape* shape2 )
{
    double fx[2] = { -DBL_MAX, DBL_MAX };
    double fy[2] = { -DBL_MAX, DBL_MAX };
    double xpos1[2];
    double ypos1[2];
    double xpos2[2];
    double ypos2[2];
    int ok = 1;

    if ( !shape1 || !shape2 ) {
        return 0;
    }

    /* Exclusions always overlap */
    if ( shape1->include != regInclude || shape2->include != regInclude ) { 
        return 1;
    }

    reg_extent_shape( shape1, fx, fy, xpos1, ypos1 );
    reg_extent_shape( shape2, fx, fy, xpos2, ypos2 );
    ok = reg_rectangle_overlap( xpos1, ypos1, xpos2, ypos2 );
    
    return ok;
}
Exemplo n.º 2
0
/**
 * Return 1 if the regions bounding rectangles overlap. 0 otherwise.
 */
int regOverlapRegion(regRegion* region1, regRegion* region2) {
  
  // Null regions do not overlap
  if (!region1 || !region2) {
    return 0;
  }

  return reg_rectangle_overlap(
          region1->xregbounds,
          region1->yregbounds,
          region2->xregbounds,
          region2->yregbounds);
}
Exemplo n.º 3
0
/*
 * Determines if two shapes intersect, and whether or not one (or both) should be 
 * discarded in the interesction of those shapes. (e.g., if one rectangle entirely
 * contains the other, then there is no reason to put the contained rectangle inside
 * the other.)
 */
int reg_shape_intersect( regShape* shape1, regShape* shape2, long* index1, long* index2 )
{
    double fx[2] = { -DBL_MAX, DBL_MAX };
    double fy[2] = { -DBL_MAX, DBL_MAX };
    double xpos1[2];
    double ypos1[2];
    double xpos2[2];
    double ypos2[2];
    int ok = 1;

    if ( !shape1 || !shape2 ) {
        return 0;
    }

    reg_extent_shape_raw( shape1, fx, fy, xpos1, ypos1 );
    reg_extent_shape_raw( shape2, fx, fy, xpos2, ypos2 );

    ok = reg_rectangle_overlap( xpos1, ypos1, xpos2, ypos2 );
    if ( ok )
    {
        /* If shapes are identical, just return one of them */
        if ( regCompareShape( shape1, shape2, 0 ))
        {
            *index2 = 0;
            return ok;
        }
	else if ( shape1->include != shape2->include )
	{
	    /* The regions are exact opposites, they cancel out             
	     *  This often happens with bounding areas. */
	  if ( regCompareShape( shape1, shape2, 1 ))
	      {
		*index1 = 0;
		*index2 = 0;
		ok = 0;
		return ok;
	      }
	}

        /* Exclusions always overlap */
        if ( shape1->include != regInclude || shape2->include != regInclude ) {
            return ok;
        }
  
        /* The temporary hack to support only rectangles */
        /* If shape1 is entirely within rectangle 2, ignore rectangle 2. */
        if ( reg_is_rect( shape2 ))
        {
            if ( reg_rectangle_inside( xpos1, ypos1, xpos2, ypos2 ))
            {
                *index2 = 0;
            }
            else if ( reg_is_rect( shape1 ))
            {
                /* Replace shape1 with intersected rectangle */
                *index2 = 0;
                if ( shape2->xpos[0] > shape1->xpos[0] ) shape1->xpos[0] = shape2->xpos[0];
                if ( shape2->xpos[1] < shape1->xpos[1] ) shape1->xpos[1] = shape2->xpos[1];
                if ( shape2->ypos[0] > shape1->ypos[0] ) shape1->ypos[0] = shape2->ypos[0];
                if ( shape2->ypos[1] < shape1->ypos[1] ) shape1->ypos[1] = shape2->ypos[1];    
            }
        }
        else if (  reg_is_rect( shape1 ) && reg_rectangle_inside( xpos2, ypos2, xpos1, ypos1 ))
        {
            *index1 = 0;
        }

        return ok;
    }

    ok = 1;
    if ( shape1->include != regInclude )
    {
        if ( shape2->include != regInclude ) {
            return 1;
        }
        /* Exclude region outside included area of interest - ignore */
        *index1 = 0;
    }
    else if (  shape2->include != regInclude )
    {
        /* Exclude region outside included area of interest - ignore */
        *index2 = 0;
    }
    else
    {
        *index1 = 0;
        *index2 = 0; 
            /*
             * In this case, two included regions have no overlap. 
             * This is the case in which we throw out the whole intersection as null.
             */
        ok = 0;
    }

    return ok;
}