示例#1
0
int classify_polygon(VEC2F a, VEC2F normal, VEC2F **vertex, int *vnum, POLY2D *in, POLY2D *out0, POLY2D *out1)
{
 int i, behind = 0, infront = 0, flag;
 int count0 = 0, count1 = 0, new_vert_num = 0, new_vert_index = 0;
 float *d = (float *)malloc(in->vnum * sizeof(float)), k;

 for(i = 0; i < in->vnum; i++)
  {
   d[i] = which_side(a, normal, (*vertex)[in->vind[i]]);
   if(d[i] < -BSP_EPSILON) { behind++; }
   if(d[i] > BSP_EPSILON) { infront++; }
  }

 if(behind && !infront)
  return BSP_BEHIND;
 if(infront && ! behind)
  return BSP_INFRONT;
 if(!behind && !infront)
  return BSP_INFRONT;

 inline void clip_count(int v0, int v1)
  {
   flag = 0;
   if(d[v0] > BSP_EPSILON) { flag++; out0->vnum++; }
   else                    { out1->vnum++; }
   if(d[v1] > BSP_EPSILON) { flag++; }

   if(flag == 1)
    {
     out0->vnum++;
     out1->vnum++;
     new_vert_num++;
    }
  }
示例#2
0
int classify_polygon(VEC2F a, VEC2F normal, VEC2F poly[], int pnum,
                     VEC2F out_poly0[], int *out_pnum0, VEC2F out_poly1[], int *out_pnum1)
{
 int i, behind = 0, infront = 0, flag, count0 = 0, count1 = 0;
 float *d = (float *)malloc(pnum * sizeof(float)), k;

 for(i = 0; i < pnum; i++)
  {
   d[i] = which_side(a, normal, poly[i]);
   if(d[i] < -BSP_EPSILON) { behind++; }
   if(d[i] > BSP_EPSILON) { infront++; }
  }

 if(behind && !infront)
  return BSP_BEHIND;
 if(infront && ! behind)
  return BSP_INFRONT;
 if(!behind && !infront)
  return BSP_INFRONT;

 inline void clip_count(int v0, int v1)
  {
   flag = 0;
   if(d[v0] > BSP_EPSILON) { flag++; (*out_pnum0)++; }
   else                    { (*out_pnum1)++; }
   if(d[v1] > BSP_EPSILON) { flag++; }

   if(flag == 1)
    {
     (*out_pnum0)++;
     (*out_pnum1)++;
    }
  }
示例#3
0
/**
   With respect to parent P, replace N with R
   @param P is N->parent
   @param N is the node we are removing
   @param R is the replacement
 */
static inline void
replace(struct RBTREE_NODE* P,
        struct RBTREE_NODE* N,
        struct RBTREE_NODE* R)
{
  tree_side s = which_side(P, N);
  if (s == LEFT)
    P->left = R;
  else if (s == RIGHT)
    P->right = R;
  else
    valgrind_fail("replace: P-!>N "RBTREE_KEY_PRNF"->"RBTREE_KEY_PRNF
              "\n", RBTREE_KEY_PRNA(P->key), RBTREE_KEY_PRNA(N->key));
}
示例#4
0
static inline void
delete_case6(struct RBTREE_TYPENAME* target,
             struct RBTREE_NODE* N)
{
  struct RBTREE_NODE* P = N->parent;
  struct RBTREE_NODE* S = sibling(P, N);
  S->color = P->color;
  P->color = BLACK;

  tree_side s = which_side(P, N);
  if (s == LEFT)
  {
    S->right->color = BLACK;
    rotate_left(target, P);
  }
  else if (s == RIGHT)
  {
    S->left->color = BLACK;
    rotate_right(target, P);
  }
  else
    valgrind_fail("X");
}
示例#5
0
/**
   P                     P
      N                     R
     B C        -\         B C
       ...      -/          ...
        R                     N
       X Y                   X Y
 */
static inline void
swap_nodes(struct RBTREE_TYPENAME* target,
           struct RBTREE_NODE* N, struct RBTREE_NODE* R)
{
  struct RBTREE_NODE* P = N->parent;
  struct RBTREE_NODE* B = N->left;
  struct RBTREE_NODE* C = N->right;
  struct RBTREE_NODE* X = R->left;
  struct RBTREE_NODE* Y = R->right;

  // Possibilities
  // N, R unrelated
  // R->parent == N

  // Link P to R
  if (P == NULL)
  {
    assert(target->root == N);
    target->root = R;
  }
  else
  {
    replace(P, N, R);
  }

  // Link N to its new parent
  if (R->parent != N)
  {
    N->parent = R->parent;
    show_node(N->parent);
    replace(R->parent, R, N);
  }
  else
  {
    tree_side s = which_side(N, R);
    N->parent = R;
    if (s == LEFT)
      R->left = N;
    else
      R->right = N;
  }

  R->parent = P;

  // Set N's children
  N->left   = X;
  if (X != NULL)
    X->parent = N;
  N->right  = Y;
  if (Y != NULL)
    Y->parent = N;

  // Set R's children
  if (B != R) // otherwise set above
  {
    R->left = B;
    if (B != NULL)
      B->parent = R;
  }
  if (C != R) // otherwise set above
  {
    R->right = C;
    if (C != NULL)
      C->parent = R;
  }

  // Restore colors
  rbtree_color tmp = R->color;
  R->color = N->color;
  N->color = tmp;
}