a few functions useful in geometry calculations.
More...
#include <math.h>
#include <stdlib.h>
#include <math/vector2d.h>
Go to the source code of this file.
|
enum | ERROR_LOC { ERROR_OUTSIDE
, ERROR_INSIDE
} |
| When approximating an arc or circle, should the error be placed on the outside or inside of the curve? (Generally speaking filled shape errors go on the inside and knockout errors go on the outside. More...
|
|
|
int | GetArcToSegmentCount (int aRadius, int aErrorMax, double aArcAngleDegree) |
|
int | CircleToEndSegmentDeltaRadius (int aInnerCircleRadius, int aSegCount) |
|
int | GetCircleToPolyCorrection (int aMaxError) |
|
template<typename T > |
VECTOR2< T > | GetVectorSnapped45 (const VECTOR2< T > &aVec, bool only45=false) |
| Snap a vector onto the nearest 0, 45 or 90 degree line.
|
|
bool | ClipLine (const EDA_RECT *aClipBox, int &x1, int &y1, int &x2, int &y2) |
| Test if any part of a line falls within the bounds of a rectangle.
|
|
constexpr double | dot_mark_len (double aLineWidth) |
| Dashed and dotted line patterns.
|
|
constexpr double | dash_gap_len (double aLineWidth) |
|
constexpr double | dash_mark_len (double aLineWidth) |
|
a few functions useful in geometry calculations.
◆ ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve? (Generally speaking filled shape errors go on the inside and knockout errors go on the outside.
This preserves minimum clearances.)
◆ CircleToEndSegmentDeltaRadius()
int CircleToEndSegmentDeltaRadius |
( |
int |
aInnerCircleRadius, |
|
|
int |
aSegCount |
|
) |
| |
- Returns
- the radius diffence of the circle defined by segments inside the circle and the radius of the circle tangent to the middle of segments (defined by segments outside this circle)
- Parameters
-
aInnerCircleRadius | is the radius of the circle tangent to the middle of segments |
aSegCount | is the seg count to approximate the circle |
◆ ClipLine()
bool ClipLine |
( |
const EDA_RECT * |
aClipBox, |
|
|
int & |
x1, |
|
|
int & |
y1, |
|
|
int & |
x2, |
|
|
int & |
y2 |
|
) |
| |
Test if any part of a line falls within the bounds of a rectangle.
Please note that this is only accurate for lines that are one pixel wide.
- Parameters
-
aClipBox | - The rectangle to test. |
x1 | - X coordinate of one end of a line. |
y1 | - Y coordinate of one end of a line. |
x2 | - X coordinate of the other end of a line. |
y2 | - Y coordinate of the other end of a line. |
- Returns
- - False if any part of the line lies within the rectangle.
◆ GetArcToSegmentCount()
int GetArcToSegmentCount |
( |
int |
aRadius, |
|
|
int |
aErrorMax, |
|
|
double |
aArcAngleDegree |
|
) |
| |
- Returns
- the number of segments to approximate a arc by segments with a given max error (this number is >= 1)
- Parameters
-
aRadius | is the radius od the circle or arc |
aErrorMax | is the max error This is the max distance between the middle of a segment and the circle. |
aArcAngleDegree | is the arc angle in degrees |
◆ GetCircleToPolyCorrection()
int GetCircleToPolyCorrection |
( |
int |
aMaxError | ) |
|
- Returns
- the radius correction to approximate a circle.
- Parameters
-
aMaxError | is the same error value used to calculate the number of segments. |
When creating a polygon from a circle, the polygon is inside the circle. Only corners are on the circle. This is incorrect when building clearance areas of circles, that need to build the equivalent polygon outside the circle.
◆ GetVectorSnapped45()
template<typename T >
VECTOR2< T > GetVectorSnapped45 |
( |
const VECTOR2< T > & |
aVec, |
|
|
bool |
only45 = false |
|
) |
| |
Snap a vector onto the nearest 0, 45 or 90 degree line.
The magnitude of the vector is NOT kept, instead the coordinates are set equal (and/or opposite) or to zero as needed. The effect of this is that if the starting vector is on a square grid, the resulting snapped vector will still be on the same grid.
- Parameters
-
- Returns
- the snapped vector