# kicad-developers team mailing list archive

## Re: HPGL

```OK, take a look at this one, it clamps the sweep of degrees within the range you mentioned.

```
```=== modified file 'common/common_plotHPGL_functions.cpp'
--- common/common_plotHPGL_functions.cpp	2012-10-13 18:54:33 +0000
+++ common/common_plotHPGL_functions.cpp	2013-02-01 21:56:54 +0000
@@ -373,6 +373,31 @@
}

+/**
+ * Function NormalizeDegrees
+ * limits @a aDegrees within the range @a lower <= @a aDegrees <= @a upper.  It will work
+ * on temporary expressions, since they are evaluated only once, and it should work
+ * on most if not all numeric types, string types, or any type for which "operator < ()"
+ * is present. The arguments are accepted in this order so you can remember the
+ * expression as a memory aid:
+ * <p>
+ * result is:  lower <= value <= upper
+ */
+template <typename T> inline T NormalizeDegrees( T lower, T aDegrees, T upper )
+{
+    wxASSERT( lower <= upper );
+
+    while( aDegrees < lower )
+
+    while( upper < aDegrees )
+
+}
+// @todo move this to some place more useful, like fctsys.h
+
+
/* Plot an arc:
* Center = center coord
* Stangl, endAngle = angle of beginning and end
@@ -385,7 +410,7 @@
FILL_T fill, int width )
{
wxASSERT( outputFile );
-    double angle;
+    double degrees;

return;
@@ -393,14 +418,17 @@
DPOINT centre_dev = userToDeviceCoordinates( centre );

if( plotMirror )
-        angle = (StAngle - EndAngle) / 10.0;
+        degrees = (StAngle - EndAngle) / 10.0;
else
-        angle = (EndAngle - StAngle) / 10.0;
+        degrees = (EndAngle - StAngle) / 10.0;
+
+    degrees = NormalizeDegrees( -180.0, degrees, +179.0 );

// Calculate start point,
wxPoint cmap;
-    cmap.x  = (int) ( centre.x + ( radius * cos( RAD2DEG( StAngle / 10.0 ) ) ) );
-    cmap.y  = (int) ( centre.y - ( radius * sin( RAD2DEG( StAngle / 10.0 ) ) ) );
+    cmap.x  = int( centre.x + ( radius * cos( DEG2RAD( StAngle / 10.0 ) ) ) );
+    cmap.y  = int( centre.y - ( radius * sin( DEG2RAD( StAngle / 10.0 ) ) ) );
+
DPOINT  cmap_dev = userToDeviceCoordinates( cmap );

fprintf( outputFile,
@@ -409,7 +437,7 @@
cmap_dev.y,
centre_dev.x,
centre_dev.y );
-    fprintf( outputFile, "%.0f", angle );
+    fprintf( outputFile, "%.0f", degrees );
fprintf( outputFile, ";PU;\n" );
PenFinish();
}
@@ -478,7 +506,7 @@

double rsize = userToDeviceSize( radius );

-    fprintf( outputFile, "PA %.0f,%.0fd;CI %.0f;\n",
+    fprintf( outputFile, "PA %.0f,%.0f;CI %.0f;\n",
pos_dev.x, pos_dev.y, rsize );

if( trace_mode == FILLED )        // Plot in filled mode.

```

### References

• HPGL
From: Andreas Beutling, 2013-02-01