コード例 #1
0
ファイル: tstraigh.c プロジェクト: sharkcz/xtrkcad
void AdjustStraightEndPt( track_p t, EPINX_T inx, coOrd pos )
{
	if (GetTrkType(t) != T_STRAIGHT) {
		AbortProg( "AdjustLIneEndPt( %d, %d ) not on STRAIGHT %d\n",
				GetTrkIndex(t), inx, GetTrkType(t) );
		return;
	}
	UndoModify( t );
#ifdef VERBOSE
lprintf("adjustStraightEndPt T%d[%d] p=[%0.3f %0.3f]\n",
		GetTrkIndex(t), inx, pos.x, pos.y );
#endif
	SetTrkEndPoint( t, inx, pos, GetTrkEndAngle(t,inx));
	ComputeBoundingBox( t );
	CheckTrackLength( t );
}
コード例 #2
0
ファイル: cprint.c プロジェクト: sharkcz/xtrkcad
static BOOL_T PrintPage(
		int x,
		int y )
{
	coOrd orig, p[4], minP, maxP;
	int i;
	coOrd clipOrig, clipSize;
	wFont_p fp;
	coOrd roomSize;

			if (BITMAP(bm,x,y)) {
				orig.x = currPrintGrid.orig.x + x*currPrintGrid.size.x;
				orig.y = currPrintGrid.orig.y + y*currPrintGrid.size.y;
				Rotate( &orig, currPrintGrid.orig, currPrintGrid.angle );
				p[0] = p[1] = p[2] = p[3] = orig;
				p[1].x = p[2].x = orig.x + currPrintGrid.size.x;
				p[2].y = p[3].y = orig.y + currPrintGrid.size.y + 
						( printGaudy ? printScale : 0.0 );
				Rotate( &p[0], orig, currPrintGrid.angle );
				Rotate( &p[1], orig, currPrintGrid.angle );
				Rotate( &p[2], orig, currPrintGrid.angle );
				Rotate( &p[3], orig, currPrintGrid.angle );
				minP = maxP = p[0];
				for (i=1; i<4; i++) {
					if (maxP.x < p[i].x) maxP.x = p[i].x;
					if (maxP.y < p[i].y) maxP.y = p[i].y;
					if (minP.x > p[i].x) minP.x = p[i].x;
					if (minP.y > p[i].y) minP.y = p[i].y;
				} 
				maxP.x -= minP.x;
				maxP.y -= minP.y;
				print_d.d = page_d.d = wPrintPageStart();
				if (page_d.d == NULL)
					return FALSE;
				print_d.dpi = page_d.dpi = wDrawGetDPI( print_d.d );
				print_d.angle = currPrintGrid.angle;
				print_d.orig = orig;
				print_d.size = /*maxP*/ currPrintGrid.size;
				page_d.orig = zero;
				page_d.angle = 0.0;
				if ( printGaudy ) {
					Translate( &print_d.orig, orig, currPrintGrid.angle+180.0, printScale );
					print_d.size.y += printScale;
				}
				if (printRotate) {
					rotateCW = (printFormat != PORTRAIT);
					if (rotateCW) {
						page_d.orig.x = realPageSize.y;
						page_d.orig.y = 0.0;
						page_d.angle = -90.0;
						print_d.angle += -90.0;
						Translate( &print_d.orig, print_d.orig, currPrintGrid.angle+90, maxPageSize.x );
					} else {
						page_d.orig.x = 0.0;
						page_d.orig.y = realPageSize.x;
						page_d.angle = 90.0;
						print_d.angle += 90.0;
						Translate( &print_d.orig, print_d.orig, currPrintGrid.angle,
								maxPageSize.y+(printGaudy?printScale:0) );
					}
					page_d.size.x = print_d.size.y/printScale;
					page_d.size.y = print_d.size.x/printScale;
					print_d.size.x = currPrintGrid.size.y;
					print_d.size.y = currPrintGrid.size.x;
				} else {
					page_d.size.x = print_d.size.x/printScale;
					page_d.size.y = print_d.size.y/printScale;
				}
				wSetCursor( wCursorWait );
				print_d.scale = printScale;
				if (print_d.d == NULL)
					 AbortProg( "wPrintPageStart" );
				clipOrig.x = clipOrig.y = 0;
				clipSize.x = maxPageSize.x/printScale;
				clipSize.y = maxPageSize.y/printScale;
				GetRoomSize( &roomSize );
				if (printGaudy) {
					PrintGaudyBox( roomSize );
					if ((!printRotate) || rotateCW) {
						clipOrig.y = 1.0;
					}
					if (printRotate && rotateCW) {
						print_d.size.x += printScale;
					}
				} else if (printRegistrationMarks)
					PrintPlainBox( x, y, p );
				if (printRotate) {
					wPrintClip( (wPos_t)(clipOrig.y*print_d.dpi), (wPos_t)(clipOrig.x*print_d.dpi),
							(wPos_t)(clipSize.y*print_d.dpi), (wPos_t)(clipSize.x*print_d.dpi) );
				} else {
					wPrintClip( (wPos_t)(clipOrig.x*print_d.dpi), (wPos_t)(clipOrig.y*print_d.dpi),
							(wPos_t)(clipSize.x*print_d.dpi), (wPos_t)(clipSize.y*print_d.dpi) );
				}
				p[0].x = p[3].x = 0.0;
				p[1].x = p[2].x = roomSize.x;
				p[0].y = p[1].y = 0.0;
				p[2].y = p[3].y = roomSize.y;
				fp = wStandardFont( F_TIMES, FALSE, FALSE );
				DrawRuler( &print_d, p[0], p[1], 0.0, TRUE, FALSE, wDrawColorBlack );
				DrawRuler( &print_d, p[0], p[3], 0.0, TRUE, TRUE, wDrawColorBlack );
				DrawRuler( &print_d, p[1], p[2], 0.0, FALSE, FALSE, wDrawColorBlack );
				DrawRuler( &print_d, p[3], p[2], 0.0, FALSE, TRUE, wDrawColorBlack );
				if ( printRuler && currPrintGrid.angle == 0 ) {
					if ( !printRotate ) {
						p[2] = p[3] = print_d.orig;
						p[3].x += print_d.size.x;
						p[3].y += print_d.size.y;
					} else if ( rotateCW ) {
						p[2].x = print_d.orig.x - print_d.size.y;
						p[2].y = print_d.orig.y; 
						p[3].x = print_d.orig.x;
						p[3].y = print_d.orig.y + print_d.size.x;
					} else {
						p[2].x = print_d.orig.x;
						p[2].y = print_d.orig.y - print_d.size.x;
						p[3].x = print_d.orig.x + print_d.size.y;
						p[3].y = print_d.orig.y;
					}
					if ( p[2].x > 0 )
						minP.x = p[2].x + 0.4 * print_d.scale;
					else
						minP.x = 0.0;
					if ( p[3].x < roomSize.x )
						maxP.x = p[3].x - 0.2 * print_d.scale;
					else
						maxP.x = roomSize.x;
					if ( p[2].y > 0 )
						minP.y = p[2].y + 0.4 * print_d.scale;
					else
						minP.y = 0.0;
					if ( p[3].y < roomSize.y )
						maxP.y = p[3].y - 0.2 * print_d.scale;
					else
						maxP.y = roomSize.y;
					p[0].y = 0.0;
					p[1].y = maxP.y - minP.y;
					if ( p[2].x > 0 ) {
						p[0].x = p[1].x = p[2].x + 0.4 * print_d.scale;
						DrawRuler( &print_d, p[0], p[1], minP.y, TRUE, TRUE, wDrawColorBlack );
					}
					if ( p[3].x < roomSize.x ) {
						p[0].x = p[1].x = p[3].x - 0.2 * print_d.scale;
						DrawRuler( &print_d, p[0], p[1], minP.y, FALSE, FALSE, wDrawColorBlack );
					}
					p[0].x = 0;
					p[1].x = maxP.x - minP.x;
					if ( p[2].y > 0 ) {
						p[0].y = p[1].y = p[2].y + 0.4 * print_d.scale;
						DrawRuler( &print_d, p[0], p[1], minP.x, TRUE, FALSE, wDrawColorBlack );
					}
					if ( p[3].y < roomSize.y ) {
						p[0].y = p[1].y = p[3].y - 0.2 * print_d.scale;
						DrawRuler( &print_d, p[0], p[1], minP.x, FALSE, TRUE, wDrawColorBlack );
					}
				}
				if (printGrid)
					DrawSnapGrid( &print_d, mapD.size, FALSE );
				roadbedWidth = printRoadbed?printRoadbedWidth:0.0;
				DrawTracks( &print_d, print_d.scale, minP, maxP );
				if (printRegistrationMarks && printScale == 1)
					DrawRegistrationMarks( &print_d );
				if ( !wPrintPageEnd( print_d.d ) )
					return FALSE;
				/*BITMAP(bm,x,y) = 0;*/
				MarkPage( x, y );
	}
	return TRUE;
}
コード例 #3
0
ファイル: randc_cypher.c プロジェクト: ReesAcheson/randcrypt
/*Returns the cyphered byte.
CypherChar is the per-character cryptor.  
It uses the current state of the randoms to encrypt/decrypt the character.
It does not alter the state of the randoms (with e.g. Next4Rands(), etc).
k is the byte to use, 0-3
There are several cypher methods to choose from, the choice made through 
the global CypherMode.  CypherModesMax can be set in randc_defs.h 
to limit modes available.
If desired to use only one method, this can be choosen at compile time
by setting CypherMode in initRandVars. 
Operation:
The function begins by creating a sequence which will be used to select
the layers to use.  Then the NumLayers var is set which is the number
of layers to use.  The layers are selected and the cipher number calculated
using the selected mothod.  Then the char is encrypted using either modulo 
arithmetic, or XOR, as determined in InitRandVars. */
uint8_t CryptChar(uint8_t ch, uint8_t k)
{ int j, zerohit;
  uint8_t c;			//Num that will be XORed with ch.
  uint8_t sequence[LayersMax];	//A layer sequence
  uint8_t ModCrypt;		//Use Modulo arithmetic or XOR?

  GenerateLayerSequence(sequence, k, SeqMixLoops);
  SetLayers(&LayersPickingLayer, k, sequence);
  zerohit = 0;
  c = LayerRandByte(sequence[0], k);	//Get 1st c

//The following calculates the encryption number using the CypherMode
//currently active to convert a series of numbers into a single byte.
//Each most likey produces a different resulting byte which will be used 
//for the char encryption.
//All modes: layers derived from sequence[].
//With CypherModesMax=1 only the 1st two will be used.  The others are here 
//for illustration as to possibilities.
  switch (CypherMode) { 
    case 0: //adding: add up all numbers, the overflow being lost.
            for (j=1; j<NumLayers; j++) 	
              c = c + LayerRandByte(sequence[j], k);
            break;
    case 1: //XOR:  XOR all numbers together
            for (j=1; j<NumLayers; j++) 	//xor char with rand from each layer
              c = c ^ LayerRandByte(sequence[j], k);
            break;
    case 2: //adding, twiddle every other one  (~ is bitwise complement)
            for (j=1; j<NumLayers; j++) 	
              if ((j & 1) == 0)
                c = c + LayerRandByte(sequence[j], k);
              else
                c = c + ~LayerRandByte(sequence[j], k);
            break;
    case 3: for (j=1; j<NumLayers; j++) 	
              c = c + (255-LayerRandByte(sequence[j], k));
            break;
    case 4: break;  //In the simplest case, just use the single layer's byte.
		    //To enable this method set CypherModeMax to at least 4.
		    //Currently disabled.
    default:printf("Cyphermode %u was called for.\n", CypherMode); 
            AbortProg("Fatal error. There is no such CypherMode", ex_progerr);
  }	//switch

  //If c is zero then ch remains unchanged.
  //Instead, find 2 layers who's sum is non-zero and use the sum.
  if (c == 0) {
    ZeroCorrects++;	//Keep count.
    zerohit = 1;	//So we can pass the hit on to debug below.
    j = 0;	
    while ((c == 0) && (j < LayersMax)) { 	//make sure we don't enter an endless loop
      c = LayerRandByte(sequence[j], k) + 
          LayerRandByte(sequence[(j+1)%LayersMax], k);
      j++;
    }	//while
    if (c == 0) 
      AbortProg("ERROR: A zero slipped through.  Unable to find non-zero replacement.", ex_progerr);
  }	//if c==0

  if (Debug == dg_Sequ || Debug == dg_Sequ2 || Debug == dg_RandsUsed)
    DebugSequencing2File(SeqDebugF, sequence, Debug, k, zerohit, c);
    
//How to apply c to the character?    
  if (UseModuloCrypt == 255)	//If 255 then select method now
    ModCrypt = LayerRandByte(sequence[LayersMax-1], k);
  else
    ModCrypt = UseModuloCrypt;  //Else use method as selected in InitRandVars.

  if ((ModCrypt &1) == 0) {	//if even
    ch = ch ^ c;		//XOR the character
  }
  else {			//else odd, use modulo
    if (operation == op_encrypt)
      ch = ch + c;		//If encrypting, add to ch
    else
      ch = ch -c;  		//If decrypting, subtract from ch
  }  

  if (Debug == dg_Sequ2)
    for (j=1; j<NumLayers; j++) {  //Find the highest and lowest layer used
      if(sequence[j] < DebugLayLow)
        DebugLayLow = sequence[j];
      if(sequence[j] > DebugLayHi)
        DebugLayHi = sequence[j];
    }	//for
  return ch;
}	//CryptChar()