Пример #1
0
/*
  ====================
  CopyBrush

  ====================
*/
cbspbrush_t * CopyBrush( cbspbrush_t *in )
{
	int		i;
	int	size;
	cbspbrush_t	*b;

	size = (int)&(((cbspbrush_t *)0)->surfaces[in->surfacenum]);
	b = NewBrush( in->surfacenum );
	memcpy( b, in, size );

	for ( i = 0; i < in->surfacenum; i++ )
	{
		if ( in->surfaces[i].p )
			b->surfaces[i].p = CopyPolygon( in->surfaces[i].p );
	}

	return b;
}
Пример #2
0
/*
  ==============================
  GenBaseTile

  ==============================
*/
u_list_t * GenBaseTile( u_list_t *raw_poly_list, fp_t rotate, vec2d_t scale, fp_t u_shift, fp_t v_shift, vec3d_t norm, fp_t dist )
{
	int		i;
	polygon_t	*p, *pnew;
	u_list_iter_t	iter;
	u_list_t		*list;

//	printf( "gen: shf: %f %f scl: %f %f\n", u_shift, v_shift, scale[0], scale[1] );

	list = NEWTYPE( u_list_t );
	U_InitList( list );

	U_ListIterInit( &iter, raw_poly_list );
	for( ; ( p = U_ListIterNext( &iter ) ) ; )
	{		
		pnew = CopyPolygon( p );
		U_ListInsertAtHead( list, pnew );
		for ( i = 0; i < p->pointnum; i++ )
		{
			CalcPoint( pnew->p[i], p->p[i], norm, dist, u_shift, v_shift, rotate, scale );
		}
	}	
	return list;
}
Пример #3
0
u_list_t * ScanPolygon( polygon_t *poly, vec3d_t norm, fp_t dist, fp_t step )
{
	fp_t		max_d;
	int		i;
	fp_t		d;
	polygon_t	*remain;

	u_list_t	*frag_list;

//	printf( "dist: %f, step: %f\n", dist,step );
//	Vec3dPrint( norm );

	// get max dist of poly towards the plane
	
	max_d = -999999.9;
	for ( i = 0; i < poly->pointnum; i++ )
	{
		d = Vec3dDotProduct( norm, poly->p[i] ) - dist;
		if ( d > max_d )
			max_d = d;
	}

	if ( max_d < 0.0 )
	{
		d = -ceil( (-max_d)/step ) * step;
	}
	else
	{
		d = ceil( (max_d)/step ) * step;
	}

	dist += d;
	
	remain = CopyPolygon( poly );

	frag_list = NEWTYPE( u_list_t );
	U_InitList( frag_list );

	for( ; remain ; )
	{
		polygon_t	*front, *back;
		
//		printf( "split dist: %f\n", dist );

		SplitPolygon( remain, norm, dist, &front, &back );
		
		if ( front )
		{
			scan_frag_t	*frag;

			frag = NEWTYPE( scan_frag_t );
			frag->p = front;
			frag->dist = dist;
			U_ListInsertAtHead( frag_list, frag );
			
//			printf( "hit!\n" );
			
		}
		
		dist -= step;
		remain = back;
	}
	return frag_list;
}
Пример #4
0
/* ---------------------------------------------------------------------------
 * pastes the contents of the buffer to the layout. Only visible objects
 * are handled by the routine.
 */
bool
CopyPastebufferToLayout (Coord X, Coord Y)
{
  Cardinal i;
  bool changed = false;

#ifdef DEBUG
  printf("Entering CopyPastebufferToLayout.....\n");
#endif

  /* set movement vector */
  DeltaX = X - PASTEBUFFER->X, DeltaY = Y - PASTEBUFFER->Y;

  /* paste all layers */
  for (i = 0; i < max_copper_layer + 2; i++)
    {
      LayerType *sourcelayer = &PASTEBUFFER->Data->Layer[i];
      LayerType *destlayer = LAYER_PTR (i);

      if (destlayer->On)
	{
	  changed = changed ||
	    (sourcelayer->LineN != 0) ||
	    (sourcelayer->ArcN != 0) ||
	    (sourcelayer->PolygonN != 0) || (sourcelayer->TextN != 0);
	  LINE_LOOP (sourcelayer);
	  {
	    CopyLine (destlayer, line);
	  }
	  END_LOOP;
	  ARC_LOOP (sourcelayer);
	  {
	    CopyArc (destlayer, arc);
	  }
	  END_LOOP;
	  TEXT_LOOP (sourcelayer);
	  {
	    CopyText (destlayer, text);
	  }
	  END_LOOP;
	  POLYGON_LOOP (sourcelayer);
	  {
	    CopyPolygon (destlayer, polygon);
	  }
	  END_LOOP;
	}
    }

  /* paste elements */
  if (PCB->PinOn && PCB->ElementOn)
    {
      ELEMENT_LOOP (PASTEBUFFER->Data);
      {
#ifdef DEBUG
	printf("In CopyPastebufferToLayout, pasting element %s\n",
	      element->Name[1].TextString);
#endif
	if (FRONT (element) || PCB->InvisibleObjectsOn)
	  {
	    CopyElement (element);
	    changed = true;
	  }
      }
      END_LOOP;
    }

  /* finally the vias */
  if (PCB->ViaOn)
    {
      changed |= (PASTEBUFFER->Data->ViaN != 0);
      VIA_LOOP (PASTEBUFFER->Data);
      {
	CopyVia (via);
      }
      END_LOOP;
    }

  if (changed)
    {
      Draw ();
      IncrementUndoSerialNumber ();
    }

#ifdef DEBUG
  printf("  .... Leaving CopyPastebufferToLayout.\n");
#endif

  return (changed);
}
Пример #5
0
void DistributePolygon( map3_t *map, polygon_t *p, cplane_t *pl )
{
	int		i;
	vec2d_t		v;
	vec2d_t		min, max;
	projectionType		type;
	vec3d_t		right, up;
	fp_t		x, y;
	
	vec3d_t		norms[4];
	fp_t		dists[4];

	polygon_t	*poly;

	type = GetProjectionTypeOfPlane( pl );
	GetProjectionVecs( right, up, type );
	
	Vec2dInitBB( min, max, 999999.9 );
	for ( i = 0; i < p->pointnum; i++ )
	{
		ProjectVec3d( v, p->p[i], type );
		Vec2dAddToBB( min, max, v );
	}

	min[0] = floor(min[0]/FIELD_CELL_SIZE)*FIELD_CELL_SIZE;
	min[1] = floor(min[1]/FIELD_CELL_SIZE)*FIELD_CELL_SIZE;
	
	for ( x = min[0]; x < max[0]; x+=FIELD_CELL_SIZE )
	{
		Vec3dFlip( norms[0], right );
		Vec3dCopy( norms[1], right );
		dists[0] = -x;
		dists[1] = x+FIELD_CELL_SIZE;

		for ( y = min[1]; y < max[1]; y+=FIELD_CELL_SIZE )
		{
			Vec3dFlip( norms[2], up );
			Vec3dCopy( norms[3], up );
			dists[2] = -y;
			dists[3] = y+FIELD_CELL_SIZE;	

			
			poly = CopyPolygon( p );
			for ( i = 0; i < 4; i++ )
			{ 
				ClipPolygonInPlace( &poly, norms[i], dists[i] );
				if ( !poly )
					break;
			}
			if ( !poly )
				continue;

			{
				int		xc, yc, zc;
				veccell_t	*c;
				vec3d_t			center;
				ivec3d_t		icenter;
				vec3d_t		shift;
				fp_t		scale;

				PolygonCenter( poly, center );

//				xc = floor(center[0]/FIELD_CELL_SIZE);
//				yc = floor(center[1]/FIELD_CELL_SIZE);
//				zc = floor(center[2]/FIELD_CELL_SIZE);

				for ( scale = -8.0; scale <= 0.0; scale+=8.0 )
				{
					Vec3dMA( shift, scale, pl->norm, center );
					
					IVec3dRint( icenter, shift );

					xc = _UnitSnap( icenter[0], FIELD_CELL_SIZE );
					yc = _UnitSnap( icenter[1], FIELD_CELL_SIZE );
					zc = _UnitSnap( icenter[2], FIELD_CELL_SIZE );				

					
					if ( ( c = Map3FindCell( map, xc, yc, zc ) ) )
					{
						Vec3dAdd( c->vec, c->vec, pl->norm );
					}
					else
					{
						c = NEW( veccell_t );
						c->x = xc;
						c->y = yc;
						c->z = zc;
						Map3InsertCell( map, c );
						Vec3dCopy( c->vec, pl->norm );
						fieldcellnum++;
					} 
				}			
			}
			fieldpatchnum++;
		}
	}
}
Пример #6
0
// 
// SplitPolygon
//
void SplitPolygon( polygon_t *in, vec3d_t norm, fp_t dist, polygon_t **front, polygon_t **back )
{  
	int		i, j;
	fp_t		dists[MAX_POINTS_ON_POLYGON+1];
	int		sides[MAX_POINTS_ON_POLYGON+1];
	int		counts[3];
	fp_t		d;
	int		maxpts;
	fp_t		*p1, *p2;
	vec3d_t		pclip;
	polygon_t	*f, *b;

	counts[0] = counts[1] = counts[2] = 0;

	for ( i = 0; i < in->pointnum; i++ ) {
		d = Vec3dDotProduct( in->p[i], norm ) - dist;
		dists[i] = d;

		if ( d > front_epsilon )
			sides[i] = SIDE_FRONT;
		else if ( d < back_epsilon )
			sides[i] = SIDE_BACK;
		else 
			sides[i] = SIDE_ON;

		counts[sides[i]]++;
	}

	dists[i] = dists[0];
	sides[i] = sides[0];
	
	*front = *back = NULL;
	
	if ( !counts[SIDE_FRONT] ) 
	{
		*back = CopyPolygon( in );
		return;
	}

	if ( !counts[SIDE_BACK] )
	{
		*front = CopyPolygon( in );
		return;
	}

	maxpts = in->pointnum+4;

	*front = f = NewPolygon( maxpts );
	*back = b = NewPolygon( maxpts );

	for ( i = 0; i < in->pointnum; i++ )
	{
		p1 = in->p[i];
		
		if ( sides[i] == SIDE_ON )
		{
			Vec3dCopy( f->p[f->pointnum++], p1 );
			Vec3dCopy( b->p[b->pointnum++], p1 );
			continue;
		}

		if ( sides[i] == SIDE_FRONT )
			Vec3dCopy( f->p[f->pointnum++], p1 );

		if ( sides[i] == SIDE_BACK )
			Vec3dCopy( b->p[b->pointnum++], p1 );

		if ( sides[i+1] == SIDE_ON || sides[i+1] == sides[i] )
			continue;

		p2 = in->p[(i+1)%in->pointnum];

		d = dists[i] / ( dists[i]-dists[i+1] );
		for ( j = 0; j < 3; j++ )
		{
			if ( norm[j] == 1.0 )
				pclip[j] = dist;
			else if ( norm[j] == -1.0 )
				pclip[j] = -dist;
			else
				pclip[j] = p1[j] + d*(p2[j]-p1[j]);
		}

		Vec3dCopy( f->p[f->pointnum++], pclip );
		Vec3dCopy( b->p[b->pointnum++], pclip );
	}

	if ( f->pointnum > maxpts || b->pointnum > maxpts )
		Error( "maxpts reached.\n" );
}