示例#1
0
static void paste_track_overwrite(bg_nle_project_t * p, bg_nle_track_t * src,
                                  bg_nle_track_t * dst, gavl_time_t dst_pos,
                                  gavl_time_t dst_len)
  {
  int i;
  int start_seg = -1;
  
  /* Make room for pasted segments */
  i = 0;
  while(i < dst->num_segments)
    {
    /* ---------|        |------------ */
    /* ----|  |----------------------- */
    if(dst->segments[i].dst_pos + dst->segments[i].len < dst_pos)
      {
      i++;
      continue;
      }
    /* ---------|        |------------ */
    /* ----------------------|  |----- */
    else if(dst->segments[i].dst_pos >= dst_pos + dst_len)
      break;
    
    if(dst->segments[i].dst_pos < dst_pos)
      {
      /* ---------|        |------------ */
      /* ------|   xxxxxxxx     |------- */
      if(dst->segments[i].dst_pos + dst->segments[i].len > dst_pos + dst_len)
        {
        split_segment(p, dst, i,
                      dst_pos - dst->segments[i].dst_pos,
                      &p->undo_id);
        i++;

        change_segment(p, dst, i,
                       dst->segments[i].src_pos +
                       gavl_time_scale(dst->segments[i].scale, dst_len+5),
                       dst->segments[i].dst_pos + dst_len,
                       dst->segments[i].len - dst_len,
                       &p->undo_id);
        
        start_seg = i;
        break;
        }
      /* ---------|        |------------ */
      /* ------|   xxxx|---------------- */
      else
        {
        gavl_time_t diff =
          dst->segments[i].dst_pos +
          dst->segments[i].len - dst_pos;
        
        change_segment(p, dst, i,
                       dst->segments[i].src_pos,
                       dst->segments[i].dst_pos,
                       dst->segments[i].len - diff,
                       &p->undo_id);
        start_seg = i;
        i++;
        }
      }
    else
      {
      /* ---------|        |------------ */
      /* -------------|xxxx     |------- */
      if(dst->segments[i].dst_pos + dst->segments[i].len > dst_pos + dst_len)
        {
        gavl_time_t diff =
          dst_pos + dst_len - dst->segments[i].dst_pos;
        
        change_segment(p, dst, i,
                       dst->segments[i].src_pos +
                       gavl_time_scale(dst->segments[i].scale, diff+5),
                       dst->segments[i].dst_pos + diff,
                       dst->segments[i].len - diff,
                       &p->undo_id);
        
        if(start_seg < 0)
          start_seg = i;
        break;
        }
      /* ---------|        |------------ */
      /* -----------|xx|---------------- */
      else
        {
        delete_segment(p, dst, i, &p->undo_id);
        if(start_seg < 0)
          start_seg = i;
        }
      }
    }

  /* Insert new segments */
  if(start_seg < 0)
    start_seg = 0;
  
  for(i = 0; i < src->num_segments; i++)
    {
    insert_segment(p, dst, start_seg + i,
                   &src->segments[i],
                   dst_pos + src->segments[i].dst_pos,
                   &p->undo_id);
    }
  
  }
bool TrapezoidSweep::next_step()
{
	if (current_endpoint == NULL_POINT)
	{
		done = false;
		queue_it = queue.begin();
	}

	if (queue_it == queue.end())
	{
		done = true;
		return done;
	}

	endpoint p = queue_it->first;
	segment* s = queue_it->second;

	current_segment = *s;
	current_endpoint = p;

	x_sweep = p.x;

	// update y-coordinate of intersection with sweep line
	s->y_sweep = p.y;
	update_y_sweep(L_red);
	update_y_sweep(L_blue);
	
	finished_t.insert(finished_t.end(),current_t.begin(),current_t.end());
	current_t.clear();

	if (s->color == RED || p.type == LEFT)
	{
		add_trapezoid(*search(L_blue,s, 1),*search(L_blue,s,-1));
	}
	else
	{
		add_trapezoid(*search(L_blue,s, 1),*s);
		add_trapezoid(*s,*search(L_blue,s,-1));
	}
			
	// find the nearest s_blue in both directions
	if (s->color == RED || p.type == LEFT)
	{
		advance(search(L_blue,s, 1));
		advance(search(L_blue,s,-1));
	}

	// right blue segment
	else
	{
		advance(next(L_blue,s, 1));
		advance(s);
		advance(next(L_blue,s,-1));
	}

	// update both L_red and L_blue list
	if (p.type == LEFT)
	{
		if (s->color == RED)
			insert_segment(L_red , s);
		if (s->color == BLUE)
			insert_segment(L_blue, s);
	} else {
		if (s->color == RED)
			delete_segment(L_red , s);
		if (s->color == BLUE)
			delete_segment(L_blue, s);
	}
	
	++queue_it;
	return done;
}
示例#3
0
void bg_nle_project_delete_segment(bg_nle_project_t * p,
                                   bg_nle_track_t * t, int index)
  {
  delete_segment(p, t, index, NULL);
  }