Skip to content

Commit 85de583

Browse files
Update to new coding standards.
1 parent 589c9ec commit 85de583

File tree

4 files changed

+77
-78
lines changed

4 files changed

+77
-78
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ G-code or SVG. This would be a big change to the library and would
3333
introduce a lot of new code. It would also be a big testing issue.
3434
* Add circles and arcs to the PenDownDistance and plot time calculations.
3535
* Make plot time take into account pen speed if '-v' is used.
36-
* Add Doxygen comments to the library source.
36+
* Add Doxygen comments to the library source and add a Makefile rule for Doxygen.
3737

3838
## Turtle library
3939
* Implement run-time option setting in all Turtle plots, and in the

pin_and_cotton.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define LEFT 8
1717

1818

19-
int main (int argc, char * const argv[])
19+
int main(int argc, char * const argv[])
2020
{
2121
/* High-Resolution Computer Graphics Using C, by Ian O. Angell, 1989.
2222
Exercise 1.10, page 21. */
@@ -45,32 +45,31 @@ int main (int argc, char * const argv[])
4545
double xc;
4646
double maxx, maxy;
4747

48-
while ((opt = getopt (argc, argv, "no:p:s:t:v:")) != -1) {
48+
while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
4949
switch (opt) {
5050
case 'n':
5151
case 'o':
5252
case 'p':
5353
case 's':
5454
case 't':
5555
case 'v':
56-
plotopt (opt, optarg);
56+
plotopt(opt, optarg);
5757
break;
5858
default: /* '?' */
59-
fprintf (stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n",
60-
argv[0]);
61-
fprintf (stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
62-
exit (EXIT_FAILURE);
59+
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
60+
fprintf(stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
61+
exit(EXIT_FAILURE);
6362
}
6463
}
6564

66-
plotbegin (0);
65+
plotbegin(0);
6766

68-
getplotsize (&maxx, &maxy);
67+
getplotsize(&maxx, &maxy);
6968

7069
xc = maxx / 2.0;
7170

7271
/* Draw square border */
73-
rectangle (xc - (maxy / 2.0), 0.0, xc + (maxy / 2.0), maxy);
72+
rectangle(xc - (maxy / 2.0), 0.0, xc + (maxy / 2.0), maxy);
7473

7574
xoff = (maxx - maxy) / 2.0;
7675

@@ -145,28 +144,28 @@ int main (int argc, char * const argv[])
145144
else
146145
pin2 = line[j].p1;
147146

148-
// printf ("Drawing to pin %d.\n", pin2);
147+
// printf("Drawing to pin %d.\n", pin2);
149148
}
150149
else {
151150
pin1 = (pin1 + 1) % (n * 4);
152151
needmove = 1;
153-
// printf ("Moving to pin %d\n", pin1);
152+
// printf("Moving to pin %d\n", pin1);
154153
}
155154
} while (j >= nlines);
156155

157156
if (needmove)
158-
moveto (pin[pin1].x, pin[pin1].y);
157+
moveto(pin[pin1].x, pin[pin1].y);
159158

160-
lineto (pin[pin2].x, pin[pin2].y);
159+
lineto(pin[pin2].x, pin[pin2].y);
161160
line[j].drawn = 1;
162161
pin1 = pin2;
163162
needmove = 0;
164163
}
165164

166165

167-
plotend ();
166+
plotend();
168167

169-
printf ("%d pins, %d lines drawn\n", n * 4, nlines);
168+
printf("%d pins, %d lines drawn\n", n * 4, nlines);
170169

171170
return (0);
172171
}

spiralsq.c

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
#define RADIANS (M_PI / 180.0)
1111

12-
void ringoboxes2 (double x0, double y0, double radius, int nboxes, int ninner, int offset, double slant);
12+
#define SLANT_DEGREES (20.0)
1313

14+
void ringoboxes2(const double x0, const double y0, const double radius, int nboxes, const int ninner, const int offset, const double slant);
1415

15-
int main (int argc, char * const argv[])
16+
17+
int main(int argc, char * const argv[])
1618
{
1719
int opt;
1820
int i;
@@ -23,69 +25,68 @@ int main (int argc, char * const argv[])
2325
double r;
2426
double slant;
2527

26-
while ((opt = getopt (argc, argv, "no:p:s:t:v:")) != -1) {
28+
while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
2729
switch (opt) {
2830
case 'n':
2931
case 'o':
3032
case 'p':
3133
case 's':
3234
case 't':
3335
case 'v':
34-
plotopt (opt, optarg);
36+
plotopt(opt, optarg);
3537
break;
3638
default: /* '?' */
37-
fprintf (stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n",
38-
argv[0]);
39-
fprintf (stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
40-
// exit (EXIT_FAILURE);
39+
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
40+
fprintf(stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
41+
// exit(EXIT_FAILURE);
4142
}
4243
}
4344

44-
plotbegin (0);
45+
plotbegin(0);
4546

46-
getplotsize (&maxx, &maxy);
47+
getplotsize(&maxx, &maxy);
4748

4849
xc = maxx / 2.0;
4950
yc = maxy / 2.0;
5051

5152
height = maxy;
5253

5354
/* Draw square border */
54-
rectangle (xc - (height / 2.0), 0.0, xc + (height / 2.0), maxy);
55+
rectangle(xc - (height / 2.0), 0.0, xc + (height / 2.0), maxy);
5556

5657
radius = height / 12.0;
5758

5859
/* Draw four concentric circles of squares */
5960
for (i = 0; i < 4; i++) {
6061
if (i & 1)
61-
slant = 20.0;
62+
slant = SLANT_DEGREES;
6263
else
63-
slant = -20.0;
64+
slant = -SLANT_DEGREES;
6465

6566
r = radius * (i + 1.5);
66-
ringoboxes2 (xc, yc, r, 18 * (i + 1), 1, 0, slant * RADIANS);
67+
ringoboxes2(xc, yc, r, 18 * (i + 1), 1, 0, slant * RADIANS);
6768
}
6869

69-
pencolr (1);
70+
pencolr(1);
7071

7172
/* Draw four concentric circles of squares */
7273
for (i = 0; i < 4; i++) {
7374
if (i & 1)
74-
slant = 20.0;
75+
slant = SLANT_DEGREES;
7576
else
76-
slant = -20.0;
77+
slant = -SLANT_DEGREES;
7778

7879
r = radius * (i + 1.5);
79-
ringoboxes2 (xc, yc, r, 18 * (i + 1), 1, 1, slant * RADIANS);
80+
ringoboxes2(xc, yc, r, 18 * (i + 1), 1, 1, slant * RADIANS);
8081
}
8182

82-
plotend ();
83+
plotend();
8384

8485
return (0);
8586
}
8687

8788

88-
void ringoboxes2 (double x0, double y0, double radius, int nboxes, int ninner, int offset, double slant)
89+
void ringoboxes2(const double x0, const double y0, const double radius, int nboxes, const int ninner, const int offset, const double slant)
8990
{
9091
int i, j, k, n;
9192
double side, s2;
@@ -113,12 +114,12 @@ void ringoboxes2 (double x0, double y0, double radius, int nboxes, int ninner, i
113114
if (offset)
114115
theta += delta / 2.0;
115116

116-
s = sin (theta);
117-
c = cos (theta);
117+
s = sin(theta);
118+
c = cos(theta);
118119

119120
for (k = 0; k < ninner; k++) {
120-
sr = sin (slant);
121-
cr = cos (slant);
121+
sr = sin(slant);
122+
cr = cos(slant);
122123

123124
/* Set up a square */
124125
x[0] = -s2;
@@ -158,11 +159,11 @@ void ringoboxes2 (double x0, double y0, double radius, int nboxes, int ninner, i
158159
}
159160

160161
/* Draw the rotated square */
161-
moveto (rx[0], ry[0]);
162-
lineto (rx[1], ry[1]);
163-
lineto (rx[2], ry[2]);
164-
lineto (rx[3], ry[3]);
165-
lineto (rx[0], ry[0]);
162+
moveto(rx[0], ry[0]);
163+
lineto(rx[1], ry[1]);
164+
lineto(rx[2], ry[2]);
165+
lineto(rx[3], ry[3]);
166+
lineto(rx[0], ry[0]);
166167
}
167168
}
168169
}

superellipse.c

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#include "hpgllib.h"
99

1010

11-
void superellipse (double x0, double y0, double a, double b, double theta, double d);
11+
void superellipse(const double x0, const double y0, const double a, const double b, const double theta, const double d);
1212

1313

14-
int main (int argc, char * const argv[])
14+
int main(int argc, char * const argv[])
1515
{
1616
int opt;
1717
double xc, yc;
@@ -33,39 +33,38 @@ int main (int argc, char * const argv[])
3333
#endif
3434
int i;
3535

36-
while ((opt = getopt (argc, argv, "no:p:s:t:v:")) != -1) {
36+
while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
3737
switch (opt) {
3838
case 'n':
3939
case 'o':
4040
case 'p':
4141
case 's':
4242
case 't':
4343
case 'v':
44-
plotopt (opt, optarg);
44+
plotopt(opt, optarg);
4545
break;
4646
default: /* '?' */
47-
fprintf (stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n",
48-
argv[0]);
49-
fprintf (stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
50-
exit (EXIT_FAILURE);
47+
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
48+
fprintf(stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
49+
exit(EXIT_FAILURE);
5150
}
5251
}
5352

5453
/* Select first pen and draw border */
55-
plotbegin (1);
54+
plotbegin(1);
5655

57-
getplotsize (&maxx, &maxy);
56+
getplotsize(&maxx, &maxy);
5857

5958
xc = maxx / 2.0;
6059
yc = maxy / 2.0;
6160

6261
/* Draw axes */
63-
moveto (0.0, yc);
64-
lineto (maxx, yc);
65-
moveto (xc, 0.0);
66-
lineto (xc, maxy);
62+
moveto(0.0, yc);
63+
lineto(maxx, yc);
64+
moveto(xc, 0.0);
65+
lineto(xc, maxy);
6766

68-
pencolr (1);
67+
pencolr(1);
6968

7069
#ifndef DEVELOPMENT
7170
theta = 0.0;
@@ -75,40 +74,40 @@ int main (int argc, char * const argv[])
7574
/* if a==b, we'll get squares and circles */
7675
a = (45.0 + (5.0 * i)) * 40.0;
7776
b = (45.0 + (5.0 * i)) * 40.0;
78-
superellipse (xc, yc, a, b, theta, sq[i]);
77+
superellipse(xc, yc, a, b, theta, sq[i]);
7978
}
8079

8180
a = (45.0 + (5.0 * i)) * 40.0;
8281
b = (45.0 + (5.0 * i)) * 40.0;
83-
rectangle (xc - a, yc - b, xc + a, yc + b);
82+
rectangle(xc - a, yc - b, xc + a, yc + b);
8483
#else
8584
delta = (M_PI * 2.0) / 5.0;
8685

8786
for (i = 0; i < 5; i++) {
8887
a = 87.0 * 40.0;
8988
b = 87.0 * 40.0;
9089
theta = delta * (double)i;
91-
superellipse (xc, yc, a, b, theta, 2.8);
90+
superellipse(xc, yc, a, b, theta, 2.8);
9291
}
9392

94-
twroot2 = pow (2.0, 1.0 / 12.0);
93+
twroot2 = pow(2.0, 1.0 / 12.0);
9594
theta = M_PI / 4.0;
9695

9796
for (i = 0; i <= 12; i++) {
9897
/* if a==b, we'll get squares and circles */
9998
a = (100.0 + (6.0 * i)) * 40.0;
10099
b = (100.0 + (6.0 * i)) * 40.0;
101-
superellipse (X0, Y0, a, b, theta, pow (twroot2, (double)(12 - i)));
100+
superellipse(X0, Y0, a, b, theta, pow(twroot2, (double)(12 - i)));
102101
}
103102
#endif
104103

105-
plotend ();
104+
plotend();
106105

107106
return (0);
108107
}
109108

110109

111-
void superellipse (double x0, double y0, double a, double b, double theta, double d)
110+
void superellipse(const double x0, const double y0, const double a, const double b, const double theta, const double d)
112111
{
113112
double t;
114113
double delta;
@@ -121,31 +120,31 @@ void superellipse (double x0, double y0, double a, double b, double theta, doubl
121120

122121
delta = (2.0 * M_PI) / (double)npts;
123122

124-
sintheta = sin (theta);
125-
costheta = cos (theta);
123+
sintheta = sin(theta);
124+
costheta = cos(theta);
126125

127126
for (i = 0; i <= npts; i++) {
128127
t = (double)i * delta;
129128

130-
st = sin (t);
131-
ct = cos (t);
129+
st = sin(t);
130+
ct = cos(t);
132131

133132
if (st < 0.0)
134-
sinpt = -pow (-st, 2.0 / d);
133+
sinpt = -pow(-st, 2.0 / d);
135134
else
136-
sinpt = pow (st, 2.0 / d);
135+
sinpt = pow(st, 2.0 / d);
137136

138137
if (ct < 0.0)
139-
cospt = -pow (-ct, 2.0 / d);
138+
cospt = -pow(-ct, 2.0 / d);
140139
else
141-
cospt = pow (ct, 2.0 / d);
140+
cospt = pow(ct, 2.0 / d);
142141

143142
x = (a * cospt * costheta) - (b * sinpt * sintheta);
144143
y = (a * cospt * sintheta) + (b * sinpt * costheta);
145144

146145
if (i == 0)
147-
moveto (x0 + x, y0 + y);
146+
moveto(x0 + x, y0 + y);
148147
else
149-
lineto (x0 + x, y0 + y);
148+
lineto(x0 + x, y0 + y);
150149
}
151150
}

0 commit comments

Comments
 (0)