Exemplo n.º 1
0
EXPORT BOOL_T UpdateDescStraight(
		int inx,
		int e0,
		int e1,
		int ln,
		int an,
		descData_p desc,
		long pivot )
{
	coOrd mid;
	if ( inx == e0 || inx == e1 ) {
		*(DIST_T*)desc[ln].valueP = FindDistance( *(coOrd*)desc[e0].valueP, *(coOrd*)desc[e1].valueP );
		*(ANGLE_T*)desc[an].valueP = FindAngle( *(coOrd*)desc[e0].valueP, *(coOrd*)desc[e1].valueP );
		if ( inx == e0 )
			desc[e1].mode |= DESC_CHANGE;
		else
			desc[e0].mode |= DESC_CHANGE;
		desc[ln].mode |= DESC_CHANGE;
		desc[an].mode |= DESC_CHANGE;
	} else if ( inx == ln || inx == an ) {
		if ( inx == ln && *(DIST_T*)desc[ln].valueP <= minLength ) {
			ErrorMessage( MSG_OBJECT_TOO_SHORT );
			*(DIST_T*)desc[ln].valueP = FindDistance( *(coOrd*)desc[e0].valueP, *(coOrd*)desc[e1].valueP );
			desc[ln].mode |= DESC_CHANGE;
			return FALSE;
		}
		switch (pivot) {
		case DESC_PIVOT_FIRST:
			Translate( (coOrd*)desc[e1].valueP, *(coOrd*)desc[e0].valueP, *(ANGLE_T*)desc[an].valueP, *(DIST_T*)desc[ln].valueP );
			desc[e1].mode |= DESC_CHANGE;
			break;
		case DESC_PIVOT_SECOND:
			Translate( (coOrd*)desc[e0].valueP, *(coOrd*)desc[e1].valueP, *(ANGLE_T*)desc[an].valueP+180.0, *(DIST_T*)desc[ln].valueP );
			desc[e0].mode |= DESC_CHANGE;
			break;
		case DESC_PIVOT_MID:
			mid.x = (((coOrd*)desc[e0].valueP)->x+((coOrd*)desc[e1].valueP)->x)/2.0;
			mid.y = (((coOrd*)desc[e0].valueP)->y+((coOrd*)desc[e1].valueP)->y)/2.0;
			Translate( (coOrd*)desc[e0].valueP, mid, *(ANGLE_T*)desc[an].valueP+180.0, *(DIST_T*)desc[ln].valueP/2.0 );
			Translate( (coOrd*)desc[e1].valueP, mid, *(ANGLE_T*)desc[an].valueP, *(DIST_T*)desc[ln].valueP/2.0 );
			desc[e0].mode |= DESC_CHANGE;
			desc[e1].mode |= DESC_CHANGE;
			break;
		default:
			break;
		}
	} else {
		return FALSE;
	}
	return TRUE;
}
Exemplo n.º 2
0
static STATUS_T CmdCircle2( wAction_t action, coOrd pos )
{

	switch (action) {

	case C_START:
		InfoMessage( _("Place circle center") );
		return C_CONTINUE;

	case C_DOWN:
		Dc2.pos = pos;
		InfoMessage( _("Drag to set radius") );
		return C_CONTINUE;

	case C_MOVE:
		dc2.radius = ConstrainR( FindDistance( Dc2.pos, pos ) );
		InfoMessage( "%s", FormatDistance(dc2.radius) );
		return C_CONTINUE;

	case C_UP:
		curCommand = cmdCircle;
		InfoMessage( _("Place circle") );
		return C_CONTINUE;

	default:
		return C_CONTINUE;
	}
}
float FindStrip(Point arr[],int n,float d){
//printf("\nHere");
float min=d;

int i;
int j;

//qsort(arr,n,sizeof(Point),cmpY);
for(i=0;i<n;i++){
for(j=i+1;(j<n &&  (arr[j].y-arr[i].y) <d);j++ ){
if(FindDistance(arr[i],arr[j])<min)
min=FindDistance(arr[i],arr[j]);
}

}

return min;
}
float FindBrute(Point arr[],int n){

float min=FLT_MAX;

int i;
int j;

for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(FindDistance(arr[i],arr[j])<min){
min=FindDistance(arr[i],arr[j]);
}
}
}


return min;
}
Exemplo n.º 5
0
double GetTargetVolume(Chiral &chiral, std::vector<sdgDistance> &dists)
{

    vector<double> ideal_dists;

    ideal_dists.push_back(FindDistance(chiral.GetCenter(), chiral.GetSub(0), dists).GetIdeal() );
    ideal_dists.push_back(FindDistance(chiral.GetCenter(), chiral.GetSub(1), dists).GetIdeal() );
    ideal_dists.push_back(FindDistance(chiral.GetCenter(), chiral.GetSub(2), dists).GetIdeal() );
    ideal_dists.push_back(FindDistance(chiral.GetSub(0), chiral.GetSub(1), dists).GetIdeal() );
    ideal_dists.push_back(FindDistance(chiral.GetSub(0), chiral.GetSub(2), dists).GetIdeal() );
    ideal_dists.push_back(FindDistance(chiral.GetSub(1), chiral.GetSub(2), dists).GetIdeal() );

    return CalcTetraVolume(ideal_dists);
}
Exemplo n.º 6
0
void CObjectTracker::FindNextFixScale(IplImage *frame)
{
UBYTE8 iteration = 0;
SINT16 optX, optY;

FLOAT32 *currentHistogram = new FLOAT32[HISTOGRAM_LENGTH];
FLOAT32 dist, optdist=1.0;

for (iteration=0; iteration<MEANSHIFT_ITARATION_NO; iteration++)
{
   FindHistogram(frame,currentHistogram); //current frame histogram, use the last frame location as starting point
  
      FindWightsAndCOM(frame,currentHistogram);//derive weights and new location
  
      //FindHistogram(frame,currentHistogram);   //uptade histogram
  
      //UpdateInitialHistogram(currentHistogram);//uptade initial histogram
   if( ((dist=FindDistance(currentHistogram)) < optdist) || iteration==0 )
   {
    optdist=dist;
    optX=m_sTrackingObjectTable[m_cActiveObject].X;
    optY=m_sTrackingObjectTable[m_cActiveObject].Y;
//      printf("%f->", dist);
   }
   else //bad iteration, then find a better start point for next iteration
   {
   m_sTrackingObjectTable[m_cActiveObject].X=(m_sTrackingObjectTable[m_cActiveObject].X+optX)/2;
   m_sTrackingObjectTable[m_cActiveObject].Y=(m_sTrackingObjectTable[m_cActiveObject].Y+optY)/2;
   }
}//end for
m_sTrackingObjectTable[m_cActiveObject].X=optX;
m_sTrackingObjectTable[m_cActiveObject].Y=optY;
LastDist=optdist; //the latest distance
// printf("/n");

delete[] currentHistogram, currentHistogram = 0;
}
Exemplo n.º 7
0
double Line::FindDistance(const Line& line_in) const
{
  NRLib::Point p1, p2;
  return FindDistance(line_in, p1, p2);
}
Exemplo n.º 8
0
EXPORT STATUS_T CreateCurve(
		wAction_t action,
		coOrd pos,
		BOOL_T track,
		wDrawColor color,
		DIST_T width,
		long mode,
		curveMessageProc message )
{
	DIST_T d;
	ANGLE_T a;
	static coOrd pos0;
	int inx;

	switch ( action ) {
	case C_START:
		DYNARR_SET( trkSeg_t, tempSegs_da, 8 );
		switch ( curveMode ) {
		case crvCmdFromEP1:
			InfoMessage( _("Drag from End-Point in direction of curve") );
			break;
		case crvCmdFromTangent:
			InfoMessage( _("Drag from End-Point to Center") );
			break;
		case crvCmdFromCenter:
			InfoMessage( _("Drag from Center to End-Point") );
			break;
		case crvCmdFromChord:
			InfoMessage( _("Drag to other end of chord") );
			break;
		}
		return C_CONTINUE;
	case C_DOWN:
			for ( inx=0; inx<8; inx++ ) {
				 tempSegs(inx).color = wDrawColorBlack;
				 tempSegs(inx).width = 0;
			}
			tempSegs_da.cnt = 0;
			SnapPos( &pos );
			pos0 = pos;
			switch (mode) {
			case crvCmdFromEP1:
				tempSegs(0).type = (track?SEG_STRTRK:SEG_STRLIN);
				tempSegs(0).color = color;
				tempSegs(0).width = width;
				message( _("Drag to set angle") );
				break;
			case crvCmdFromTangent:
			case crvCmdFromCenter:
				tempSegs(0).type = SEG_STRLIN;
				tempSegs(1).type = SEG_CRVLIN;
				tempSegs(1).u.c.radius = mainD.scale*0.05;
				tempSegs(1).u.c.a0 = 0;
				tempSegs(1).u.c.a1 = 360;
				tempSegs(2).type = SEG_STRLIN;
				message( mode==crvCmdFromTangent?_("Drag from End-Point to Center"):_("Drag from Center to End-Point") );
				break;
			case crvCmdFromChord:
				tempSegs(0).type = (track?SEG_STRTRK:SEG_STRLIN);
				tempSegs(0).color = color;
				tempSegs(0).width = width;
				message( _("Drag to other end of chord") );
				break;
			}
			tempSegs(0).u.l.pos[0] = pos;
		return C_CONTINUE;

	case C_MOVE:
		tempSegs(0).u.l.pos[1] = pos;
		d = FindDistance( pos0, pos );
		a = FindAngle( pos0, pos );
		switch ( mode ) {
		case crvCmdFromEP1:
			message( _("Angle=%0.3f"), PutAngle(a) );
			tempSegs_da.cnt = 1;
			break;
		case crvCmdFromTangent:
			message( _("Radius=%s Angle=%0.3f"), FormatDistance(d), PutAngle(a) );
			tempSegs(1).u.c.center = pos;
			DrawArrowHeads( &tempSegs(2), pos0, FindAngle(pos0,pos)+90, TRUE, wDrawColorBlack );
			tempSegs_da.cnt = 7;
			break;
		case crvCmdFromCenter:
			message( _("Radius=%s Angle=%0.3f"), FormatDistance(d), PutAngle(a) );
			tempSegs(1).u.c.center = pos0;
			DrawArrowHeads( &tempSegs(2), pos, FindAngle(pos,pos0)+90, TRUE, wDrawColorBlack );
			tempSegs_da.cnt = 7;
			break;
		case crvCmdFromChord:
			message( _("Length=%s Angle=%0.3f"), FormatDistance(d), PutAngle(a) );
			if ( d > mainD.scale*0.25 ) {
				pos.x = (pos.x+pos0.x)/2.0;
				pos.y = (pos.y+pos0.y)/2.0;
				DrawArrowHeads( &tempSegs(1), pos, FindAngle(pos,pos0)+90, TRUE, wDrawColorBlack );
				tempSegs_da.cnt = 6;
			} else {
				tempSegs_da.cnt = 1;
			}
			break;
		}
		return C_CONTINUE;

	case C_UP:
		switch (mode) {
		case crvCmdFromEP1:
				DrawArrowHeads( &tempSegs(1), pos, FindAngle(pos,pos0)+90, TRUE, drawColorRed );
				tempSegs_da.cnt = 6;
				break;
		case crvCmdFromChord:
				tempSegs(1).color = drawColorRed;
		case crvCmdFromTangent:
		case crvCmdFromCenter:
				tempSegs(2).color = drawColorRed;
				tempSegs(3).color = drawColorRed;
				tempSegs(4).color = drawColorRed;
				tempSegs(5).color = drawColorRed;
				tempSegs(6).color = drawColorRed;
				break;
		}
		message( _("Drag on Red arrows to adjust curve") );
		return C_CONTINUE;

	default:
		return C_CONTINUE;

	}
}
Exemplo n.º 9
0
static STATUS_T CmdCircleCommon( wAction_t action, coOrd pos, BOOL_T helix )
{
	track_p t;
	static coOrd pos0;
	wControl_p controls[2];
	char * labels[1];

	switch (action) {

	case C_START:
		if (helix) {
			if (helixW == NULL)
				helixW = ParamCreateDialog( &helixPG, MakeWindowTitle(_("Helix")), NULL, NULL, HelixCancel, TRUE, NULL, 0, ComputeHelix );
			ParamLoadControls( &helixPG );
			ParamGroupRecord( &helixPG );
			ComputeHelix( NULL, 6, NULL );
			wShow( helixW );
			memset( h_orders, 0, sizeof h_orders );
			h_clock = 0;
		} else {
			ParamLoadControls( &circleRadiusPG );
			ParamGroupRecord( &circleRadiusPG );
			switch ( circleMode ) {
			case circleCmdFixedRadius:
				controls[0] = circleRadiusPLs[0].control;
				controls[1] = NULL;
				labels[0] = N_("Circle Radius");
				InfoSubstituteControls( controls, labels );
				break;
			case circleCmdFromTangent:
				InfoSubstituteControls( NULL, NULL );
				InfoMessage( _("Click on Circle Edge") );
				break;
			case circleCmdFromCenter:
				InfoSubstituteControls( NULL, NULL );
				InfoMessage( _("Click on Circle Center") );
				break;
			}
		}
		tempSegs_da.cnt = 0;
		return C_CONTINUE;

	case C_DOWN:
		DYNARR_SET( trkSeg_t, tempSegs_da, 1 );
		tempSegs_da.cnt = 0;
		if (helix) {
			if (helixRadius <= 0.0) {
				ErrorMessage( MSG_RADIUS_GTR_0 );
				return C_ERROR;
			}
			if (helixTurns <= 0) {
				ErrorMessage( MSG_HELIX_TURNS_GTR_0 );
				return C_ERROR;
			}
			ParamLoadData( &helixPG );
		} else {
			ParamLoadData( &circleRadiusPG );
			switch( circleMode ) {
			case circleCmdFixedRadius:
				if (circleRadius <= 0.0) {
					ErrorMessage( MSG_RADIUS_GTR_0 );
					return C_ERROR;
				}
				break;
			case circleCmdFromTangent:
				InfoSubstituteControls( NULL, NULL );
				InfoMessage( _("Drag to Center") );
				break;
			case circleCmdFromCenter:
				InfoSubstituteControls( NULL, NULL );
				InfoMessage( _("Drag to Edge") );
				break;
			}
		}
		SnapPos( &pos );
		tempSegs(0).u.c.center = pos0 = pos;
		tempSegs(0).color = wDrawColorBlack;
		tempSegs(0).width = 0;
		return C_CONTINUE;

	case C_MOVE:
		DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
		SnapPos( &pos );
		tempSegs(0).u.c.center = pos;
		if ( !helix ) {
			switch ( circleMode ) {
			case circleCmdFixedRadius:
				break;
			case circleCmdFromCenter:
				tempSegs(0).u.c.center = pos0;
				circleRadius = FindDistance( tempSegs(0).u.c.center, pos );
				InfoMessage( _("Radius=%s"), FormatDistance(circleRadius) );
				break;
			case circleCmdFromTangent:
				circleRadius = FindDistance( tempSegs(0).u.c.center, pos0 );
				InfoMessage( _("Radius=%s"), FormatDistance(circleRadius) );
				break;
			}
		}
		tempSegs(0).type = SEG_CRVTRK;
		tempSegs(0).u.c.radius = helix?helixRadius:circleRadius;
		tempSegs(0).u.c.a0 = 0.0;
		tempSegs(0).u.c.a1 = 360.0;
		tempSegs_da.cnt = 1;
		DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
		return C_CONTINUE;

	case C_UP:
		DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
		if ( helix ) {
			UndoStart( _("Create Helix Track"), "newHelix" );
			t = NewCurvedTrack( tempSegs(0).u.c.center, helixRadius, 0.0, 0.0, helixTurns );
		} else {
			if ( circleRadius <= 0 ) {
				ErrorMessage( MSG_RADIUS_GTR_0 );
				return C_ERROR;
			}
			UndoStart( _("Create Circle Track"), "newCircle" );
			t = NewCurvedTrack( tempSegs(0).u.c.center, circleRadius, 0.0, 0.0, 0 );
		}
		UndoEnd();
		DrawNewTrack(t);
		if (helix)
			wHide( helixW );
		else
			InfoSubstituteControls( NULL, NULL );
		tempSegs_da.cnt = 0;
		return C_TERMINATE;

	case C_REDRAW:
		DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
		return C_CONTINUE;

	case C_CANCEL:
		if (helix)
			wHide( helixW );
		else
			InfoSubstituteControls( NULL, NULL );
		return C_CONTINUE;

	default:
		return C_CONTINUE;
	}
}
Exemplo n.º 10
0
static STATUS_T CmdCurve( wAction_t action, coOrd pos )
{
	track_p t;
	DIST_T d;
	static int segCnt;
	STATUS_T rc = C_CONTINUE;

	switch (action) {

	case C_START:
		curveMode = (long)commandContext;
		Da.state = -1;
		tempSegs_da.cnt = 0;
		return CreateCurve( action, pos, TRUE, wDrawColorBlack, 0, curveMode, InfoMessage );
		
	case C_TEXT:
		if ( Da.state == 0 )
			return CreateCurve( action, pos, TRUE, wDrawColorBlack, 0, curveMode, InfoMessage );
		else
			return C_CONTINUE;

	case C_DOWN:
		if ( Da.state == -1 ) {
			SnapPos( &pos );
			Da.pos0 = pos;
			Da.state = 0;
			return CreateCurve( action, pos, TRUE, wDrawColorBlack, 0, curveMode, InfoMessage );
		} else {
			tempSegs_da.cnt = segCnt;
			return C_CONTINUE;
		}

	case C_MOVE:
		mainD.funcs->options = wDrawOptTemp;
		DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
		if ( Da.state == 0 ) {
			SnapPos( &pos );
			Da.pos1 = pos;
			rc = CreateCurve( action, pos, TRUE, wDrawColorBlack, 0, curveMode, InfoMessage );
		} else {
			SnapPos( &pos );
			PlotCurve( curveMode, Da.pos0, Da.pos1, pos, &Da.curveData, TRUE );
			if (Da.curveData.type == curveTypeStraight) {
				tempSegs(0).type = SEG_STRTRK;
				tempSegs(0).u.l.pos[0] = Da.pos0;
				tempSegs(0).u.l.pos[1] = Da.curveData.pos1;
				tempSegs_da.cnt = 1;
				InfoMessage( _("Straight Track: Length=%s Angle=%0.3f"),
						FormatDistance(FindDistance( Da.pos0, Da.curveData.pos1 )),
						PutAngle(FindAngle( Da.pos0, Da.curveData.pos1 )) );
			} else if (Da.curveData.type == curveTypeNone) {
				tempSegs_da.cnt = 0;
				InfoMessage( _("Back") );
			} else if (Da.curveData.type == curveTypeCurve) {
				tempSegs(0).type = SEG_CRVTRK;
				tempSegs(0).u.c.center = Da.curveData.curvePos;
				tempSegs(0).u.c.radius = Da.curveData.curveRadius;
				tempSegs(0).u.c.a0 = Da.curveData.a0;
				tempSegs(0).u.c.a1 = Da.curveData.a1;
				tempSegs_da.cnt = 1;
				d = D2R(Da.curveData.a1);
				if (d < 0.0)
					d = 2*M_PI+d;
				if ( d*Da.curveData.curveRadius > mapD.size.x+mapD.size.y ) {
					ErrorMessage( MSG_CURVE_TOO_LARGE );
					tempSegs_da.cnt = 0;
					Da.curveData.type = curveTypeNone;
					mainD.funcs->options = 0;
					return C_CONTINUE;
				}
				InfoMessage( _("Curved Track: Radius=%s Angle=%0.3f Length=%s"),
						FormatDistance(Da.curveData.curveRadius), Da.curveData.a1,
						FormatDistance(Da.curveData.curveRadius*d) );
			}
		}
		DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
		mainD.funcs->options = 0;
		return rc;


	case C_UP:
		mainD.funcs->options = wDrawOptTemp;
		DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
		if (Da.state == 0) {
			SnapPos( &pos );
			Da.pos1 = pos;
			Da.state = 1;
			CreateCurve( action, pos, TRUE, wDrawColorBlack, 0, curveMode, InfoMessage );
			DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
			mainD.funcs->options = 0;
			segCnt = tempSegs_da.cnt;
			InfoMessage( _("Drag on Red arrows to adjust curve") );
			return C_CONTINUE;
		} else {
			mainD.funcs->options = 0;
			tempSegs_da.cnt = 0;
			Da.state = -1;
			if (Da.curveData.type == curveTypeStraight) {
				if ((d=FindDistance( Da.pos0, Da.curveData.pos1 )) <= minLength) {
					ErrorMessage( MSG_TRK_TOO_SHORT, "Curved ", PutDim(fabs(minLength-d)) );
					return C_TERMINATE;
				}
				UndoStart( _("Create Straight Track"), "newCurve - straight" );
				t = NewStraightTrack( Da.pos0, Da.curveData.pos1 );
				UndoEnd();
			} else if (Da.curveData.type == curveTypeCurve) {
				if ((d= Da.curveData.curveRadius * Da.curveData.a1 *2.0*M_PI/360.0) <= minLength) {
					ErrorMessage( MSG_TRK_TOO_SHORT, "Curved ", PutDim(fabs(minLength-d)) );
					return C_TERMINATE;
				}
				UndoStart( _("Create Curved Track"), "newCurve - curve" );
				t = NewCurvedTrack( Da.curveData.curvePos, Da.curveData.curveRadius,
						Da.curveData.a0, Da.curveData.a1, 0 );
				UndoEnd();
			} else {
				return C_ERROR;
			}
			DrawNewTrack( t );
			return C_TERMINATE;
		}

	case C_REDRAW:
		if ( Da.state >= 0 ) {
			mainD.funcs->options = wDrawOptTemp;
			DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
			mainD.funcs->options = 0;
		}
		return C_CONTINUE;

	case C_CANCEL:
		if (Da.state == 1) {
			mainD.funcs->options = wDrawOptTemp;
			DrawSegs( &mainD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
			mainD.funcs->options = 0;
			tempSegs_da.cnt = 0;
		}
		Da.state = -1;
		return C_CONTINUE;

	}

	return C_CONTINUE;

}
Exemplo n.º 11
0
static STATUS_T CmdHandLaidTurnout( wAction_t action, coOrd pos )
{
	ANGLE_T angle, angle2, angle3, reverseR, pointA, reverseA1, angle0;
	EPINX_T ep, ep1, ep2, ep2a=-1, ep2b=-1, pointEp0, pointEp1;
	DIST_T dist, reverseD, pointD;
	coOrd off, intersectP;
	coOrd pointP, pointC, pointP1, reverseC, point0;
	track_p trk, trk1, trk2, trk2a=NULL, trk2b=NULL, pointT;
	trkSeg_p segP;
	BOOL_T right;
	track_p trks[4], *trkpp;

	switch (action) {

	case C_START:
		InfoMessage( _("Place frog and drag angle") );
		DYNARR_SET( trkSeg_t, tempSegs_da, 1 );
		Dhlt.state = 0;
		Dhlt.normalT = NULL;
		tempSegs_da.cnt = 0;
		DYNARR_SET( trkSeg_t, tempSegs_da, 2 );
		tempSegs(0).color = drawColorBlack;
		tempSegs(0).width = 0;
		tempSegs(1).color = drawColorBlack;
		tempSegs(1).width = 0;
		return C_CONTINUE;

	case C_DOWN:
		if (Dhlt.state == 0) {
			if ((Dhlt.normalT = OnTrack( &pos, TRUE, TRUE )) == NULL)
				break;
			if ( QueryTrack( Dhlt.normalT, Q_NOT_PLACE_FROGPOINTS ) ) {
				ErrorMessage( MSG_CANT_PLACE_FROGPOINTS, _("frog") );
				Dhlt.normalT = NULL;
				break;
			}
			Dhlt.normalP = Dhlt.reverseP = Dhlt.reverseP1 = pos;
			Dhlt.normalA = GetAngleAtPoint( Dhlt.normalT, Dhlt.normalP, NULL, NULL );
			InfoMessage( _("Drag to set angle") );
			DrawLine( &tempD, Dhlt.reverseP, Dhlt.reverseP1, 0, wDrawColorBlack );
			Dhlt.state = 1;
			pointC = pointP = pointP1 = reverseC = zero;
			return C_CONTINUE;
		}

	case C_MOVE:
	case C_UP:
		if (Dhlt.normalT == NULL)
			break;
		if (Dhlt.state == 1) {
			DrawLine( &tempD, Dhlt.reverseP, Dhlt.reverseP1, 0, wDrawColorBlack );
			Dhlt.reverseP1 = pos;
			Dhlt.reverseA = FindAngle( Dhlt.reverseP, Dhlt.reverseP1 );
			Dhlt.frogA = NormalizeAngle( Dhlt.reverseA - Dhlt.normalA );
/*printf( "RA=%0.3f FA=%0.3f ", Dhlt.reverseA, Dhlt.frogA );*/
			if (Dhlt.frogA > 270.0) {
				Dhlt.frogA = 360.0-Dhlt.frogA;
				right = FALSE;
			} else if (Dhlt.frogA > 180) {
				Dhlt.frogA = Dhlt.frogA - 180.0;
				Dhlt.normalA = NormalizeAngle( Dhlt.normalA + 180.0 );
				/*ep = Dhlt.normalEp0; Dhlt.normalEp0 = Dhlt.normalEp1; Dhlt.normalEp1 = ep;*/
				right = TRUE;
			} else if (Dhlt.frogA > 90.0) {
				Dhlt.frogA = 180.0 - Dhlt.frogA;
				Dhlt.normalA = NormalizeAngle( Dhlt.normalA + 180.0 );
				/*ep = Dhlt.normalEp0; Dhlt.normalEp0 = Dhlt.normalEp1; Dhlt.normalEp1 = ep;*/
				right = FALSE;
			} else {
				right = TRUE;
			}
/*printf( "NA=%0.3f FA=%0.3f R=%d\n", Dhlt.normalA, Dhlt.frogA, right );*/
			Dhlt.frogNo = tan(D2R(Dhlt.frogA));
			if (Dhlt.frogNo > 0.01)
				Dhlt.frogNo = 1.0/Dhlt.frogNo;
			else
				Dhlt.frogNo = 0.0;
			if (action == C_MOVE) {
				if (Dhlt.frogNo != 0) {
					InfoMessage( _("Angle = %0.2f Frog# = %0.2f"), Dhlt.frogA, Dhlt.frogNo );
				} else {
					InfoMessage( _("Frog angle is too close to 0") );
				}
			} else {
				InfoMessage( _("Select point position") );
				Dhlt.state = 2;
				Translate( &Dhlt.reverseP, Dhlt.reverseP, Dhlt.normalA+(right?+90:-90), trackGauge );
				Translate( &Dhlt.reverseP1, Dhlt.reverseP1, Dhlt.normalA+(right?+90:-90), trackGauge );
			}
			DrawLine( &tempD, Dhlt.reverseP, Dhlt.reverseP1, 0, wDrawColorBlack );
			return C_CONTINUE;
		} else if ( Dhlt.state == 2 ) {
			DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
			tempSegs_da.cnt = 0;
			pointP = pos;
			if ((pointT = OnTrack( &pointP, TRUE, TRUE )) == NULL)
				break;
			if ( QueryTrack( pointT, Q_NOT_PLACE_FROGPOINTS ) ) {
				ErrorMessage( MSG_CANT_PLACE_FROGPOINTS, _("points") );
				break;
			}
			dist = FindDistance( Dhlt.normalP, pointP );
			pointA = GetAngleAtPoint( pointT, pointP, &pointEp0, &pointEp1 );
			angle = NormalizeAngle( pointA + 180.0 - Dhlt.reverseA );
PTRACE(( "rA=%0.1f pA=%0.1f a=%0.1f ", Dhlt.reverseA, pointA, angle ))
			if ( angle > 90.0 &&  angle < 270.0 ) {
				pointA = NormalizeAngle( pointA + 180.0 );
				angle = NormalizeAngle( angle + 180.0 );
PTRACE(( " {pA=%0.1f a=%0.1f} ", pointA, angle ))
			} else {
Exemplo n.º 12
0
static void ChangeDim( void )
{
	int x, y, x0, x1, y0, y1;
	coOrd p0;
	int size;
	bitmap_t tmpBm;
	BOOL_T selected;

	MapGrid( zero, mapD.size, 0.0, currPrintGrid.orig, currPrintGrid.angle, currPrintGrid.size.x, currPrintGrid.size.y,
		&x0, &x1, &y0, &y1 );
#ifdef LATER
	d0 = sqrt( mapD.size.x * mapD.size.x + mapD.size.y * mapD.size.y );

	Translate( &p1, currPrintGrid.orig, currPrintGrid.angle, d0 );
	p0 = currPrintGrid.orig;
	ClipLine( &p0, &p1, zero, 0.0, mapD.size );
	d1 = FindDistance( currPrintGrid.orig, p1 );
	y1 = (int)ceil(d1/currPrintGrid.size.y);

	Translate( &p1, currPrintGrid.orig, currPrintGrid.angle+180, d0 );
	p0 = currPrintGrid.orig;
	ClipLine( &p0, &p1, zero, 0.0, mapD.size );
	d1 = FindDistance( currPrintGrid.orig, p1 );
	y0 = -(int)floor(d1/currPrintGrid.size.y);

	Translate( &p1, currPrintGrid.orig, currPrintGrid.angle+90, d0 );
	p0 = currPrintGrid.orig;
	ClipLine( &p0, &p1, zero, 0.0, mapD.size );
	d1 = FindDistance( currPrintGrid.orig, p1 );
	x1 = (int)ceil(d1/currPrintGrid.size.x);

	Translate( &p1, currPrintGrid.orig, currPrintGrid.angle+270, d0 );
	p0 = currPrintGrid.orig;
	ClipLine( &p0, &p1, zero, 0.0, mapD.size );
	d1 = FindDistance( currPrintGrid.orig, p1 );
	x0 = -(int)floor(d1/currPrintGrid.size.x);
#endif

	if ( x0==bm.x0 && x1==bm.x1 && y0==bm.y0 && y1==bm.y1 )
		return;
	size = (x1-x0) * (y1-y0);
	if (size > bm0.memsize) {
		bm0.bm = MyRealloc( bm0.bm, size );
		bm0.memsize = size;
	}
	bm0.x0 = x0; bm0.x1 = x1; bm0.y0 = y0; bm0.y1 = y1;
	memset( bm0.bm, 0, bm0.memsize );
	pageCount = 0;
	if (bm.bm) {
		for ( x=bm.x0; x<bm.x1; x++ ) {
			for ( y=bm.y0; y<bm.y1; y++ ) {
				selected = BITMAP( bm, x, y );
				if (selected) {
					p0.x = bm.orig.x + x * bm.size.x + bm.size.x/2.0;
					p0.y = bm.orig.y + y * bm.size.y + bm.size.y/2.0;
					Rotate( &p0, bm.orig, bm.angle );
					p0.x -= currPrintGrid.orig.x;
					p0.y -= currPrintGrid.orig.y;
					Rotate( &p0, zero, -currPrintGrid.angle );
					x0 = (int)floor(p0.x/currPrintGrid.size.x);
					y0 = (int)floor(p0.y/currPrintGrid.size.y);
					if ( x0>=bm0.x0 && x0<bm0.x1 && y0>=bm0.y0 && y0<bm0.y1 ) {
						if ( BITMAP( bm0, x0, y0 ) == FALSE ) {
							pageCount++;
							BITMAP( bm0, x0, y0 ) = TRUE;
						}
					}
				}
			}
		}
	}
	tmpBm = bm0;
	bm0 = bm;
	bm = tmpBm;
	bm.orig = currPrintGrid.orig;
	bm.size = currPrintGrid.size;
	bm.angle = currPrintGrid.angle;
	sprintf( message, _("%d pages"), pageCount );
	ParamLoadMessage( &printPG, I_PAGECNT, message );
	ParamDialogOkActive( &printPG, pageCount!=0 );
}