summaryrefslogtreecommitdiff
path: root/app/bin/cnvdsgn.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/bin/cnvdsgn.c')
-rw-r--r--app/bin/cnvdsgn.c65
1 files changed, 30 insertions, 35 deletions
diff --git a/app/bin/cnvdsgn.c b/app/bin/cnvdsgn.c
index 6f75b11..91a31e5 100644
--- a/app/bin/cnvdsgn.c
+++ b/app/bin/cnvdsgn.c
@@ -1,12 +1,3 @@
-#include <stdio.h>
-#include <math.h>
-#include "common.h"
-#include "utility.h"
-
-#include <string.h>
-#include <stdlib.h>
-
-
/* XTrkCad - Model Railroad CAD
* Copyright (C) 2005 Dave Bullis
*
@@ -22,9 +13,11 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "utility.h"
+
#define GETMAXY \
if (lp->y0 > maxY) maxY = lp->y0; \
if (lp->y1 > maxY) maxY = lp->y1
@@ -32,23 +25,24 @@
static int trackSeparation = 20;
static int arrowHeadLength = 10;
-static double FindCenter(
- coOrd * pos,
- coOrd p0,
- coOrd p1,
- double radius )
+static double FindCenter(
+ coOrd * pos,
+ coOrd p0,
+ coOrd p1,
+ double radius )
{
double d;
double a0, a1;
d = FindDistance( p0, p1 )/2.0;
a0 = FindAngle( p0, p1 );
a1 = NormalizeAngle(R2D(asin( d/radius )));
- if (a1 > 180)
+ if (a1 > 180) {
a1 -= 360;
+ }
/*a0 = NormalizeAngle( a0 + (radius>0 ? +(90.0-a1) : -(90.0-a1) ) );*/
a0 = NormalizeAngle( a0 + (90.0-a1) );
Translate( pos, p0, a0, radius );
-/*fprintf(stderr,"Center = %0.3f %0.3f\n", pos->x, pos->y );*/
+ /*fprintf(stderr,"Center = %0.3f %0.3f\n", pos->x, pos->y );*/
return a1*2.0;
}
@@ -63,35 +57,35 @@ static void buildDesignerLines( FILE * inf, FILE * outf )
double len;
while ( fgets( line, sizeof line, inf ) != NULL ) {
-
+
if ( strncmp( line, "ARROW", 5 ) == 0 ) {
if ( sscanf( line, "ARROW, %lf, %lf, %lf, %lf",
- &p0.x, &p0.y, &p1.x, &p1.y ) != 4) {
+ &p0.x, &p0.y, &p1.x, &p1.y ) != 4) {
fprintf( stderr, "SYNTAX: %s", line );
exit (1);
}
a0 = FindAngle( p1, p0 );
fprintf( outf, " { 1, %ld, %ld, %ld, %ld },\n",
- (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
+ (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
Translate( &p1, p0, a0+135, arrowHeadLength );
fprintf( outf, " { 1, %ld, %ld, %ld, %ld },\n",
- (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
+ (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
Translate( &p1, p0, a0-135, arrowHeadLength );
fprintf( outf, " { 1, %ld, %ld, %ld, %ld },\n",
- (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
+ (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
} else if ( strncmp( line, "LINE", 4 ) == 0 ) {
if ( sscanf( line, "LINE, %lf, %lf, %lf, %lf",
- &p0.x, &p0.y, &p1.x, &p1.y ) != 4) {
+ &p0.x, &p0.y, &p1.x, &p1.y ) != 4) {
fprintf( stderr, "SYNTAX: %s", line );
exit (1);
}
fprintf( outf, " { 1, %ld, %ld, %ld, %ld },\n",
- (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
+ (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
} else if ( strncmp( line, "STRAIGHT", 8 ) == 0 ) {
if ( sscanf( line, "STRAIGHT, %lf, %lf, %lf, %lf",
- &p0.x, &p0.y, &p1.x, &p1.y ) != 4) {
+ &p0.x, &p0.y, &p1.x, &p1.y ) != 4) {
fprintf( stderr, "SYNTAX: %s", line );
exit (1);
}
@@ -99,38 +93,39 @@ static void buildDesignerLines( FILE * inf, FILE * outf )
Translate( &q0, p0, a0+90, trackSeparation/2.0 );
Translate( &q1, p1, a0+90, trackSeparation/2.0 );
fprintf( outf, " { 3, %ld, %ld, %ld, %ld },\n",
- (long)(q0.x+0.5), (long)(q0.y+0.5), (long)(q1.x+0.5), (long)(q1.y+0.5) );
+ (long)(q0.x+0.5), (long)(q0.y+0.5), (long)(q1.x+0.5), (long)(q1.y+0.5) );
Translate( &q0, p0, a0-90, trackSeparation/2.0 );
Translate( &q1, p1, a0-90, trackSeparation/2.0 );
fprintf( outf, " { 3, %ld, %ld, %ld, %ld },\n",
- (long)(q0.x+0.5), (long)(q0.y+0.5), (long)(q1.x+0.5), (long)(q1.y+0.5) );
-
+ (long)(q0.x+0.5), (long)(q0.y+0.5), (long)(q1.x+0.5), (long)(q1.y+0.5) );
+
} else if ( strncmp( line, "CURVE", 5 ) == 0 ) {
if ( sscanf( line, "CURVE, %lf, %lf, %lf, %lf, %lf",
- &p0.x, &p0.y, &p1.x, &p1.y, &radius ) != 5) {
+ &p0.x, &p0.y, &p1.x, &p1.y, &radius ) != 5) {
fprintf( stderr, "SYNTAX: %s", line );
exit (1);
}
a1 = FindCenter( &pc, p0, p1, radius );
a0 = FindAngle( pc, p0 );
-/*fprintf(stderr, "A0 = %0.3f, A1 = %0.3f\n", a0, a1 );*/
+ /*fprintf(stderr, "A0 = %0.3f, A1 = %0.3f\n", a0, a1 );*/
len = radius * M_PI * 2 * ( a1 / 360.0 );
num = len/20;
- if (num < 0) num = - num;
+ if (num < 0) { num = - num; }
num++;
a1 /= num;
- if (radius < 0)
+ if (radius < 0) {
radius = -radius;
+ }
for ( j=0; j<num; j++ ) {
-/*fprintf( stderr, "A0 = %0.3f\n", a0 );*/
+ /*fprintf( stderr, "A0 = %0.3f\n", a0 );*/
Translate( &p0, pc, a0, radius+trackSeparation/2.0 );
Translate( &p1, pc, a0+a1, radius+trackSeparation/2.0 );
fprintf( outf, " { 3, %ld, %ld, %ld, %ld },\n",
- (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
+ (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
Translate( &p0, pc, a0, radius-trackSeparation/2.0 );
Translate( &p1, pc, a0+a1, radius-trackSeparation/2.0 );
fprintf( outf, " { 3, %ld, %ld, %ld, %ld },\n",
- (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
+ (long)(p0.x+0.5), (long)(p0.y+0.5), (long)(p1.x+0.5), (long)(p1.y+0.5) );
a0 += a1;
p0 = p1;
}