Exemplo n.º 1
0
/* ----------------------------------------------------------------------------
 * Returns whether a square intersects with a line segment.
 * Also returns true if the line is fully inside the square.
 * s**: Square coordinates.
 * l**: Line coordinates.
 */
bool square_intersects_line(
    const float sx1, const float sy1, const float sx2, const float sy2,
    const float lx1, const float ly1, const float lx2, const float ly2
) {
    if(
        //Line crosses left side?
        lines_intersect(lx1, ly1, lx2, ly2, sx1, sy1, sx1, sy2, NULL, NULL) ||
        //Line crosses right side?
        lines_intersect(lx1, ly1, lx2, ly2, sx2, sy1, sx2, sy2, NULL, NULL) ||
        //Line crosses top side?
        lines_intersect(lx1, ly1, lx2, ly2, sx1, sy1, sx2, sy1, NULL, NULL) ||
        //Line crosses bottom side?
        lines_intersect(lx1, ly1, lx2, ly2, sx1, sy2, sx2, sy2, NULL, NULL)
    ) {
        return true;
    }
    
    if(
        (lx1 >= sx1 && lx2 >= sx1) &&
        (lx1 <= sx2 && lx2 <= sx2) &&
        (ly1 >= sy1 && ly2 >= sy1) &&
        (ly1 <= sy2 && ly2 <= sy2)
    ) return true;
    
    return false;
    
}
Exemplo n.º 2
0
int cutPoly2 (struct Plex *plex)
{
	int result, k;
	long nx, ny;
	long i, e, v0, v1;
	double p1[3], p2[3], p3[3], p4[3];
	struct PlexEdge *plexedg;
	struct PlexVertex *pv0, *pv1;
	
	nx = plex -> dimensions[0]; ny = plex -> dimensions[1];
	if (!defineGrid (plex)) return (0);
	/* go through grid lines perpendicular to x-axis */
	for (i = 0; i < nx; i++) {
		for (k = 0; k < 3; k++) {
			p1[k] = *(plex -> xgrid + 6 * i + k);
			p2[k] = *(plex -> xgrid + 6 * i + 3 + k);
		}
		for (e = 0; e < plex -> n_edge; e++) {
			plexedg = plex -> plexedges + e;
			v0 = plexedg -> vns[0];
			v1 = plexedg -> vns[1];
			pv0 = plex -> plexvertices + (v0-1);
			pv1 = plex -> plexvertices + (v1-1);
			for (k = 0; k < 3; k++) {
				p3[k] = pv0 -> center[k];
				p4[k] = pv1 -> center[k];
			}
			result = lines_intersect (p1, p2, p3, p4);
			if (!result) continue;
			result = do_fraction (plex, plexedg, p1, p2, p3, p4);
			if (!result) return (0);
		}
	}
	/* go through grid lines perpendicular to y-axis */
	for (i = 0; i < ny; i++) {
		for (k = 0; k < 3; k++) {
			p1[k] = *(plex -> ygrid + 6 * i + k);
			p2[k] = *(plex -> ygrid + 6 * i + 3 + k);
		}
		for (e = 0; e < plex -> n_edge; e++) {
			plexedg = plex -> plexedges + e;
			v0 = plexedg -> vns[0];
			v1 = plexedg -> vns[1];
			pv0 = plex -> plexvertices + (v0-1);
			pv1 = plex -> plexvertices + (v1-1);
			for (k = 0; k < 3; k++) {
				p3[k] = pv0 -> center[k];
				p4[k] = pv1 -> center[k];
			}
			result = lines_intersect (p1, p2, p3, p4);
			if (!result) continue;
			result = do_fraction (plex, plexedg, p1, p2, p3, p4);
			if (!result) return (0);
		}
	}
	return (1);
}
Exemplo n.º 3
0
int collide_polygon_rectangle(int n, int *xs, int *ys, int rx, int ry, int w, int h) {
    assert(n > 0);
    int polygon_line[2][2];
    int rectangle_lines[4][2][2] = { { {rx,   ry},   {rx+w, ry} },
                                     { {rx+w, ry},   {rx+w, ry+h} },
                                     { {rx+w, ry+h}, {rx,   ry+h} },
                                     { {rx,   ry+h}, {rx,   ry} } };
    int polygon_index, rectangle_index;
    int old_polygon_index = n - 1;
    for (polygon_index = 0; polygon_index < n; ++polygon_index) {
        polygon_line[0][0] = xs[old_polygon_index];
        polygon_line[0][1] = ys[old_polygon_index];
        polygon_line[1][0] = xs[polygon_index];
        polygon_line[1][1] = ys[polygon_index];
        for (rectangle_index = 0; rectangle_index < 4; ++rectangle_index) {
            if (lines_intersect(polygon_line, rectangle_lines[rectangle_index])) {
                return COLLISION;
            }
        }
        old_polygon_index = polygon_index;
    }
    if (point_in_rectangle(xs[0], ys[0], rx, ry, w, h)) {
        return COLLISION;
    }
    if (point_in_polygon(rx, ry, n, xs, ys)) {
        return COLLISION;
    }
    return NO_COLLISION;
}
Exemplo n.º 4
0
int main()
{
    float x1, x2, x3, x4, y1, y2, y3, y4;
    float x, y;

    for (;;) {
        cout << "X1, Y1: ";
        cin >> x1 >> y1;
        cout << "X2, Y2: ";
        cin >> x2 >> y2;
        cout << "X3, Y3: ";
        cin >> x3 >> y3;
        cout << "X4, Y4: ";
        cin >> x4 >> y4;

        switch ( lines_intersect( x1, y1, x2, y2, x3, y3, x4, y4, x, y )) {
        case DONT_INTERSECT:
            cout << "Lines don't intersect\n";
            break;
        case COLLINEAR:
            cout << "Lines are collinear\n";
            break;
        case DO_INTERSECT:
            cout << "Lines intersect at " << x << "," << y << endl;
            break;
        }
    }
} /* main */
Exemplo n.º 5
0
int ball_intersect_paddle(struct Ball* ball, struct Paddle* paddle)
{
    if (lines_intersect(ball->x, ball->y, ball->px, ball->py,
                        paddle->x, paddle->y + paddle->width + 1, //Add one so that we hit the actual bottom of the paddle
                        paddle->x, paddle->y)){
        return 1;
    }
    return 0;
}
Exemplo n.º 6
0
//----------------------------------------------------------------------------------
bool
TSPLib::intersect( int idx1, int idx2, int idx3, int idx4 )
{
    double x, y ;

    int result = lines_intersect(   m_points[idx1].x, m_points[idx1].y,
                                    m_points[idx2].x, m_points[idx2].y,
                                    m_points[idx3].x, m_points[idx3].y,
                                    m_points[idx4].x, m_points[idx4].y,
                                    x, y ) ;
    if( result==DO_INTERSECT )
    {
        return true ;
    }

    return false ;
}
Exemplo n.º 7
0
Position Line::Intersection(int seg,Segment other) {
	switch(degree) {
	case 1:
		return lines_intersect(Segment(at(seg),at(seg+1)),other);
	case 3:
		double roots[4];
		/*
		if(between(other.a,at(seg),other.b))
			return Position(at(seg));
		if(between(other.a,at(seg+3),other.b))
			return Position(at(seg+3));
			*/
		if(splineIntersectsLine(&at(seg),other,roots)>0)
			return Position(Bezier(&at(seg),3,roots[0]));
		else
			return Position();
	default:
	case 0:
		return Position();
	}
}
Exemplo n.º 8
0
void choose_ls_triplets(ls lss[MAX_LS_AMOUNT],   
			struct ls_triplet_chain **ls_triplets, int ls_amount) 
     /* Selects the loudspeaker triplets, and
      calculates the inversion matrices for each selected triplet.
     A line (connection) is drawn between each loudspeaker. The lines
     denote the sides of the triangles. The triangles should not be 
     intersecting. All crossing connections are searched and the 
     longer connection is erased. This yields non-intesecting triangles,
     which can be used in panning.*/
{
  int i,j,k,l,m,li, table_size;
  int *i_ptr;
  cart_vec vb1,vb2,tmp_vec;
  int connections[MAX_LS_AMOUNT][MAX_LS_AMOUNT];
  float angles[MAX_LS_AMOUNT];
  int sorted_angles[MAX_LS_AMOUNT];
  float distance_table[((MAX_LS_AMOUNT * (MAX_LS_AMOUNT - 1)) / 2)];
  int distance_table_i[((MAX_LS_AMOUNT * (MAX_LS_AMOUNT - 1)) / 2)];
  int distance_table_j[((MAX_LS_AMOUNT * (MAX_LS_AMOUNT - 1)) / 2)];
  float distance;
  struct ls_triplet_chain *trip_ptr, *prev, *tmp_ptr;

  if (ls_amount == 0) {
    fprintf(stderr,"Number of loudspeakers is zero\nExiting\n");
    exit(-1);
  }
  for(i=0;i<ls_amount;i++)
    for(j=i+1;j<ls_amount;j++)
      for(k=j+1;k<ls_amount;k++){
	if(vol_p_side_lgth(i,j, k, lss) > MIN_VOL_P_SIDE_LGTH){
	  connections[i][j]=1;
	  connections[j][i]=1;
	  connections[i][k]=1;
	  connections[k][i]=1;
	  connections[j][k]=1;
	  connections[k][j]=1;
	  add_ldsp_triplet(i,j,k,ls_triplets, lss);
	}
      }
  /*calculate distancies between all lss and sorting them*/
  table_size =(((ls_amount - 1) * (ls_amount)) / 2); 
  for(i=0;i<table_size; i++)
    distance_table[i] = 100000.0;
  for(i=0;i<ls_amount;i++){ 
    for(j=(i+1);j<ls_amount; j++){ 
      if(connections[i][j] == 1) {
	distance = fabs(vec_angle(lss[i].coords,lss[j].coords));
	k=0;
	while(distance_table[k] < distance)
	  k++;
	for(l=(table_size - 1);l > k ;l--){
	  distance_table[l] = distance_table[l-1];
	  distance_table_i[l] = distance_table_i[l-1];
	  distance_table_j[l] = distance_table_j[l-1];
	}
	distance_table[k] = distance;
	distance_table_i[k] = i;
	distance_table_j[k] = j;
      } else
	table_size--;
    }
  }

  /* disconnecting connections which are crossing shorter ones,
     starting from shortest one and removing all that cross it,
     and proceeding to next shortest */
  for(i=0; i<(table_size); i++){
    int fst_ls = distance_table_i[i];
    int sec_ls = distance_table_j[i];
    if(connections[fst_ls][sec_ls] == 1)
      for(j=0; j<ls_amount ; j++)
	for(k=j+1; k<ls_amount; k++)
	  if( (j!=fst_ls) && (k != sec_ls) && (k!=fst_ls) && (j != sec_ls)){
	    if(lines_intersect(fst_ls, sec_ls, j,k,lss) == 1){
	      connections[j][k] = 0;
	      connections[k][j] = 0;
	    }
	  }
  }

  /* remove triangles which had crossing sides
     with smaller triangles or include loudspeakers*/
  trip_ptr = *ls_triplets;
  prev = NULL;
  while (trip_ptr != NULL){
    i = trip_ptr->ls_nos[0];
    j = trip_ptr->ls_nos[1];
    k = trip_ptr->ls_nos[2];
    if(connections[i][j] == 0 || 
       connections[i][k] == 0 || 
       connections[j][k] == 0 ||
       any_ls_inside_triplet(i,j,k,lss,ls_amount) == 1 ){
      if(prev != NULL) {
	prev->next = trip_ptr->next;
	tmp_ptr = trip_ptr;
	trip_ptr = trip_ptr->next;
	free(tmp_ptr);
      } else {
	*ls_triplets = trip_ptr->next;
	tmp_ptr = trip_ptr;
	trip_ptr = trip_ptr->next;
	free(tmp_ptr);
      }
    } else {
      prev = trip_ptr;
      trip_ptr = trip_ptr->next;

    }
  }
}
Exemplo n.º 9
0
bool SquareLine::CanSee()
{
#if defined(_showdebugger_)
//	Debugger::GetInstance().Output("(%d,%d)  ",s_cur.x,s_cur.y);
#endif //defined(_showdebugger_)

	if(s_cur == s_goal)
		return true;
	if(!NotOutOfBoard(s_cur))//IsAValidRefuge can call CanSee with a square out of board. 
		return true;		//if no obstacle can hide the refuge from the borders of the map, the refuge is exposed.
	else if(board->GetContentAt(s_cur) == e_obstacle)
		return false;

	vector2d l_cornerspos[4]; //corners of a square
	board->GetSquareCornersInLogPx(s_cur,l_cornerspos);
	Segment sg2;
	int i,intersection_value ;
	vector2d ipoint;

	//foreach segment in the square, see intersection;
	for(i=0; i<4; i++)
	{
		if(i+1 == 4)
			sg2=Segment(l_cornerspos[i],l_cornerspos[0]);
		else
			sg2=Segment(l_cornerspos[i],l_cornerspos[i+1]);
		
		intersection_value = lines_intersect(sg,sg2, ipoint);

		ipoint.setint();

		if(intersection_value == 1 && ! (ipoint== p_lastipoint) )
		{
			if( ipoint == l_cornerspos[i] || ipoint == l_cornerspos[i+1])
			{
				vector2d g = sg.p1-ipoint;

				if(g.x>0)
				{
					if(g.y>0)
					{
						s_cur=s_cur+vector2d(1,1);
					}
					else if(g.y<0)
					{
						s_cur=s_cur+vector2d(1,-1);
					}
					else
						assert(0); //this means that the line coincides with the x-axis. and this is not possible since the destination point is a square center.
				}
				else if(g.x<0)
				{
					if(g.y>0)
					{
						s_cur=s_cur+vector2d(-1,1);
					}
					else if(g.y<0)
					{
						s_cur=s_cur+vector2d(-1,-1);
					}
					else
						assert(0); //this means that the line coincides with the x-axis. and this is not possible since the destination point is a square center.
				}
				else
					assert(0); //this means that the line coincides with the y-axis. and this is not possible since the destination point is a square center.
			}
			else if(i==0)
			{
				s_cur=s_cur+vector2d(0,-1);
			}
			else if(i==1)
			{
				s_cur=s_cur+vector2d(1,0);
			}
			else if(i==2)
			{
				s_cur=s_cur+vector2d(0,1);
			}
			else
			{
				s_cur=s_cur+vector2d(-1,0);
			}

			p_lastipoint=ipoint;

			break;
		}
	}

	return CanSee();
}
Exemplo n.º 10
0
//gets the square next to s_from, in the direction of s_to.
//used by FindARefuge to have a square next to an obstacle.
Square SquareLine::GetAdjacentSquareTowards(Square s_from, Square s_to, Board * board)
{
	vector2d l_cornerspos[4]; //corners of a square
	Square	s_ret=s_from;
	Segment sg2;

	int i,intersection_value ;
	vector2d ipoint;


	board->GetSquareCornersInLogPx(s_from,l_cornerspos);

	
	Segment sg(board->GetCenterInPx(s_from),board->GetCenterInPx(s_to));

	//foreach segment in the square, see intersection;
	for(i=0; i<4; i++)
	{
		if(i+1 == 4)
			sg2=Segment(l_cornerspos[i],l_cornerspos[0]);
		else
			sg2=Segment(l_cornerspos[i],l_cornerspos[i+1]);
		
		intersection_value = lines_intersect(sg,sg2, ipoint);

		ipoint.setint();

		if(intersection_value == 1)
		{
			if( ipoint == l_cornerspos[i] || ipoint == l_cornerspos[i+1])
			{
				vector2d g = sg.p1-ipoint;

				if(g.x>0)
				{
					if(g.y>0)
					{
						s_ret=s_ret+vector2d(1,1);
					}
					else if(g.y<0)
					{
						s_ret=s_ret+vector2d(1,-1);
					}
					else
						assert(0); //this means that the line coincides with the x-axis. and this is not possible since the destination point is a square center.
				}
				else if(g.x<0)
				{
					if(g.y>0)
					{
						s_ret=s_ret+vector2d(-1,1);
					}
					else if(g.y<0)
					{
						s_ret=s_ret+vector2d(-1,-1);
					}
					else
						assert(0); //this means that the line coincides with the x-axis. and this is not possible since the destination point is a square center.
				}
				else
					assert(0); //this means that the line coincides with the y-axis. and this is not possible since the destination point is a square center.
			}
			else if(i==0)
			{
				s_ret=s_ret+vector2d(0,-1);
			}
			else if(i==1)
			{
				s_ret=s_ret+vector2d(1,0);
			}
			else if(i==2)
			{
				s_ret=s_ret+vector2d(0,1);
			}
			else
			{
				s_ret=s_ret+vector2d(-1,0);
			}


			break;
		}
	}

	return s_ret;
}
Exemplo n.º 11
0
/*GetALine follow squares intersecting the segment sg, until it reaches : 
-the border of the board, 
-an obstacle or 
-a square that insects the segment only one time (the segment can't go beyond it to neigbooring squares) 
*/
void SquareLine::GetALine()
{
	vector2d l_cornerspos[4]; //corners of a square
	board->GetSquareCornersInLogPx(s_cur,l_cornerspos);
	Segment sg2;
	int i,intersection_value ;
	vector2d ipoint;

	//foreach segment in the square, see intersection;
	for(i=0; i<4; i++)
	{
		if(i+1 == 4)
			sg2=Segment(l_cornerspos[i],l_cornerspos[0]);
		else
			sg2=Segment(l_cornerspos[i],l_cornerspos[i+1]);
		
		intersection_value = lines_intersect(sg,sg2, ipoint);

		ipoint.setint();

		if(intersection_value == 1 && ! (ipoint== p_lastipoint) )
		{
			if( ipoint == l_cornerspos[i] || ipoint == l_cornerspos[i+1])
			{
				vector2d g = sg.p1-ipoint;
				Square s;

				if(g.x>0)
				{
					if(g.y>0)
					{
						s=s_cur+vector2d(1,0);
						if(board->GetContentAt(s) ==  e_obstacle)
						{
							s=s_cur+vector2d(0,1);
							if(board->GetContentAt(s) ==  e_obstacle)
							{
								return;
							}
							else
							{
								pl_squares->push_back(s);
							}
						}
						else
						{
							pl_squares->push_back(s);
						}

						s_cur=s_cur+vector2d(1,1);
					}
					else if(g.y<0)
					{
						s=s_cur+vector2d(1,0);
						if(board->GetContentAt(s) ==  e_obstacle)
						{
							s=s_cur+vector2d(0,-1);
							if(board->GetContentAt(s) ==  e_obstacle)
							{
								return;
							}
							else
							{
								pl_squares->push_back(s);
							}
						}
						else
						{
							pl_squares->push_back(s);
						}

						s_cur=s_cur+vector2d(1,-1);
					}
					else
						assert(0); //this means that the line coincides with the x-axis. and this is not possible since the destination point is a square center.
				}
				else if(g.x<0)
				{
					if(g.y>0)
					{
						s=s_cur+vector2d(-1,0);
						if(board->GetContentAt(s) ==  e_obstacle)
						{
							s=s_cur+vector2d(0,1);
							if(board->GetContentAt(s) ==  e_obstacle)
							{
								return;
							}
							else
							{
								pl_squares->push_back(s);
							}
						}
						else
						{
							pl_squares->push_back(s);
						}
						s_cur=s_cur+vector2d(-1,1);
					}
					else if(g.y<0)
					{
						s=s_cur+vector2d(-1,0);
						if(board->GetContentAt(s) ==  e_obstacle)
						{
							s=s_cur+vector2d(0,-1);
							if(board->GetContentAt(s) ==  e_obstacle)
							{
								return;
							}
							else
							{
								pl_squares->push_back(s);
							}
						}
						else
						{
							pl_squares->push_back(s);
						}
						s_cur=s_cur+vector2d(-1,-1);
					}
					else
						assert(0); //this means that the line coincides with the x-axis. and this is not possible since the destination point is a square center.
				}
				else
					assert(0); //this means that the line coincides with the y-axis. and this is not possible since the destination point is a square center.
			}
			else if(i==0)
			{
				s_cur=s_cur+vector2d(0,-1);
			}
			else if(i==1)
			{
				s_cur=s_cur+vector2d(1,0);
			}
			else if(i==2)
			{
				s_cur=s_cur+vector2d(0,1);
			}
			else
			{
				s_cur=s_cur+vector2d(-1,0);
			}

			p_lastipoint=ipoint;

			break;
		}
	}

	if(!NotOutOfBoard(s_cur) || board->GetContentAt(s_cur) ==  e_obstacle)
	{
		return;
	}

	if(i==4) 
	{//when i == 4, it's the last square touched by the segment sg.
		return;
	}

	pl_squares->push_back(s_cur);
	
	GetALine();

}
Exemplo n.º 12
0
static void choose_ls_triplets(t_def_ls *x) 
     /* Selects the loudspeaker triplets, and
      calculates the inversion matrices for each selected triplet.
     A line (connection) is drawn between each loudspeaker. The lines
     denote the sides of the triangles. The triangles should not be 
     intersecting. All crossing connections are searched and the 
     longer connection is erased. This yields non-intesecting triangles,
     which can be used in panning. 
     See theory in paper Pulkki, V. Lokki, T. "Creating Auditory Displays
     with Multiple Loudspeakers Using VBAP: A Case Study with
     DIVA Project" in International Conference on 
     Auditory Displays -98.*/
{
  int i,j,k,l,/*m,li,*/ table_size;
  //int *i_ptr;
  //t_ls vb1,vb2,tmp_vec;
  int connections[MAX_LS_AMOUNT][MAX_LS_AMOUNT];
  //float angles[MAX_LS_AMOUNT];
  //int sorted_angles[MAX_LS_AMOUNT];
  t_float distance_table[((MAX_LS_AMOUNT * (MAX_LS_AMOUNT - 1)) / 2)];
  int distance_table_i[((MAX_LS_AMOUNT * (MAX_LS_AMOUNT - 1)) / 2)];
  int distance_table_j[((MAX_LS_AMOUNT * (MAX_LS_AMOUNT - 1)) / 2)];
  t_float distance;
  t_ls_set *trip_ptr, *prev, *tmp_ptr;
  int ls_amount = x->x_def_ls_amount;
  t_ls *lss = x->x_ls;
  if (ls_amount == 0) { post("define-loudspeakers: Number of loudspeakers is zero"); return; }
 
  for(i=0;i<ls_amount;i++)
    for(j=i+1;j<ls_amount;j++)
      for(k=j+1;k<ls_amount;k++)
			{
        if(vol_p_side_lgth(i,j,k, x->x_ls) > MIN_VOL_P_SIDE_LGTH)
				{
          connections[i][j]=1;
          connections[j][i]=1;
          connections[i][k]=1;
          connections[k][i]=1;
          connections[j][k]=1;
          connections[k][j]=1;
          add_ldsp_triplet(i,j,k,x);
        }
      }
   

  /*calculate distancies between all lss and sorting them*/
  table_size =(((ls_amount - 1) * (ls_amount)) / 2); 
  for(i=0;i<table_size; i++)
    distance_table[i] = 100000.0;
  for(i=0;i<ls_amount;i++)
	{ 
    for(j=(i+1);j<ls_amount; j++)
		{ 
		  if(connections[i][j] == 1) 
		  {
        distance = fabs(vec_angle(lss[i],lss[j]));
        k=0;
        while(distance_table[k] < distance)
          k++;
        for(l=(table_size - 1);l > k ;l--)
				{
          distance_table[l] = distance_table[l-1];
          distance_table_i[l] = distance_table_i[l-1];
          distance_table_j[l] = distance_table_j[l-1];
        }
        distance_table[k] = distance;
        distance_table_i[k] = i;
        distance_table_j[k] = j;
      } 
			else
			{
        table_size--;
			}
    }
  }

  /* disconnecting connections which are crossing shorter ones,
     starting from shortest one and removing all that cross it,
     and proceeding to next shortest */
  for(i=0; i<(table_size); i++)
	{
    int fst_ls = distance_table_i[i];
		int sec_ls = distance_table_j[i];
    if(connections[fst_ls][sec_ls] == 1)
		{
      for(j=0; j<ls_amount ; j++)
			{
        for(k=j+1; k<ls_amount; k++)
				{
          if( (j!=fst_ls) && (k != sec_ls) && (k!=fst_ls) && (j != sec_ls))
					{
            if(lines_intersect(fst_ls, sec_ls, j,k,x->x_ls) == 1)
						{
              connections[j][k] = 0;
              connections[k][j] = 0;
            }
          }
				}
			}
		}
  }

  /* remove triangles which had crossing sides
     with smaller triangles or include loudspeakers*/
  trip_ptr = x->x_ls_set;
  prev = NULL;
  while (trip_ptr != NULL)
	{
    i = trip_ptr->ls_nos[0];
    j = trip_ptr->ls_nos[1];
    k = trip_ptr->ls_nos[2];
    if(connections[i][j] == 0 || 
       connections[i][k] == 0 || 
       connections[j][k] == 0 ||
			 any_ls_inside_triplet(i,j,k,x->x_ls,ls_amount) == 1 )
		{
      if(prev != NULL) 
			{
        prev->next = trip_ptr->next;
        tmp_ptr = trip_ptr;
        trip_ptr = trip_ptr->next;
        freebytes(tmp_ptr, sizeof (struct t_ls_set));
      } 
			else 
			{
        x->x_ls_set = trip_ptr->next;
        tmp_ptr = trip_ptr;
        trip_ptr = trip_ptr->next;
        freebytes(tmp_ptr, sizeof (struct t_ls_set));
      }
    } 
		else 
		{
      prev = trip_ptr;
      trip_ptr = trip_ptr->next;
    }
  }
  x->x_triplets_specified=1;
}