struct VoronoiDiagramGenerator::Halfedge * VoronoiDiagramGenerator::ELleftbnd(struct Point *p)
{
	int i, bucket;
	struct Halfedge *he;
	
	/* Use hash table to get close to desired halfedge */
	bucket = (int)((p->x - xmin)/deltax * ELhashsize);	//use the hash function to find the place in the hash map that this HalfEdge should be

	if(bucket<0) bucket =0;					//make sure that the bucket position in within the range of the hash array
	if(bucket>=ELhashsize) bucket = ELhashsize - 1;

	he = ELgethash(bucket);
	if(he == (struct Halfedge *) NULL)			//if the HE isn't found, search backwards and forwards in the hash map for the first non-null entry
	{   
		for(i=1; 1 ; i += 1)
		{	
			if ((he=ELgethash(bucket-i)) != (struct Halfedge *) NULL) 
				break;
			if ((he=ELgethash(bucket+i)) != (struct Halfedge *) NULL) 
				break;
		};
		totalsearch += i;
	};
	ntry += 1;
	/* Now search linear list of halfedges for the correct one */
	if (he==ELleftend  || (he != ELrightend && right_of(he,p)))
	{
		do 
		{
			he = he -> ELright;
		} while (he!=ELrightend && right_of(he,p));	//keep going right on the list until either the end is reached, or you find the 1st edge which the point
		he = he -> ELleft;				//isn't to the right of
	}
	else 							//if the point is to the left of the HalfEdge, then search left for the HE just to the left of the point
		do 
		{
			he = he -> ELleft;
		} while (he!=ELleftend && !right_of(he,p));
		
	/* Update hash table and reference counts */
	if(bucket > 0 && bucket <ELhashsize-1)
	{	
		if(ELhash[bucket] != (struct Halfedge *) NULL) 
		{
			ELhash[bucket] -> ELrefcnt -= 1;
		}
		ELhash[bucket] = he;
		ELhash[bucket] -> ELrefcnt += 1;
	};
	return (he);
}
Example #2
0
    void cover_column(toroid_header_t* c)
    {
        assert (finalized_m);

        right_of(c)->left_m = left_of(c);
        left_of(c)->right_m = right_of(c);

        for (toroid_node_t* i(down_of(c)); i != c; i = down_of(i))
        {
            for (toroid_node_t* j(right_of(i)); j != i; j = right_of(j))
            {
                down_of(j)->up_m = up_of(j);

                up_of(j)->down_m = down_of(j);

                --(column_of(j)->size_m);
            }
        }
    }
Example #3
0
    void uncover_column(toroid_header_t* c)
    {
        assert (finalized_m);

        for (toroid_node_t* i(up_of(c)); i != c; i = up_of(i))
        {
            for (toroid_node_t* j(left_of(i)); j != i; j = left_of(j))
            {
                ++(column_of(j)->size_m);

                down_of(j)->up_m = j;

                up_of(j)->down_m = j;
            }
        }

        right_of(c)->left_m = c;
        left_of(c)->right_m = c;
    }
Example #4
0
static int cptclip_z_id(cpt_t* cpt,
			double zleft,
			double zright,
			bool (*left_of)(double,double),
			bool (*right_of)(double,double))
{
  cpt_seg_t* seg;

  /*
    pop segments from the left until one of them
    intersects the requested interval
  */

  while ((seg = cpt_pop(cpt)) != NULL)
    {
      if (right_of(seg->rsmp.val,zleft)) 
	break;

      cpt_seg_destroy(seg);
    }

  if (seg)
    {
      /*
	if this segment is not completely inside the
	requested interval then clip it to the interval
      */

      if (left_of(seg->lsmp.val,zleft))
	{
	  fill_t fill;
	  double z = 
	    (zleft - seg->lsmp.val)/
	    (seg->rsmp.val - seg->lsmp.val); 

	  if  (fill_interpolate(z,
				seg->lsmp.fill,
				seg->rsmp.fill,
				cpt->model,
				&fill) != 0)
            {
              btrace("fill interpolation failed");
              return 1;
            }

	  seg->lsmp.fill = fill;
	  seg->lsmp.val  = zleft;
	}

      /*
	push the (possibly modified) segment back to 
	where it came
      */

      cpt_prepend(seg,cpt);
    }

  /* likewise on the right */

  while ((seg = cpt_shift(cpt)) != NULL)
    {
      if (left_of(seg->lsmp.val,zright)) 
	break;
      
      cpt_seg_destroy(seg);
    }

  if (seg)
    {
      if (right_of(seg->rsmp.val,zright))
	{
	  fill_t fill;
	  double z = 
	    (zright - seg->lsmp.val)/ 
	    (seg->rsmp.val - seg->lsmp.val);

	  if  (fill_interpolate(z,
				seg->lsmp.fill,
				seg->rsmp.fill,
				cpt->model,
				&fill) != 0)
            {
              btrace("fill interpolation failed");
              return 1;
            }

	  seg->rsmp.fill = fill;
	  seg->rsmp.val  = zright;
	}

      cpt_append(seg,cpt);
    }

  return 0;
}