Excise deci-degrees from trigo.
This commit is contained in:
parent
92dae4646e
commit
f310a5b986
|
@ -446,7 +446,7 @@ int SCH_LINE::GetAngleFrom( const VECTOR2I& aPoint ) const
|
|||
else
|
||||
vec = m_start - aPoint;
|
||||
|
||||
return KiROUND( ArcTangente( vec.y, vec.x ) );
|
||||
return KiROUND( EDA_ANGLE( vec ).AsDegrees() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -459,7 +459,7 @@ int SCH_LINE::GetReverseAngleFrom( const VECTOR2I& aPoint ) const
|
|||
else
|
||||
vec = m_end - aPoint;
|
||||
|
||||
return KiROUND( ArcTangente( vec.y, vec.x ) );
|
||||
return KiROUND( EDA_ANGLE( vec ).AsDegrees() );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -59,73 +59,44 @@ bool SegmentIntersectsSegment( const VECTOR2I& a_p1_l1, const VECTOR2I& a_p2_l1,
|
|||
VECTOR2I* aIntersectionPoint = nullptr );
|
||||
|
||||
/*
|
||||
* Calculate the new point of coord coord pX, pY,
|
||||
* for a rotation center 0, 0, and angle in (1/10 degree)
|
||||
* Calculate the new point of coord coord pX, pY, for a rotation center 0, 0
|
||||
*/
|
||||
void RotatePoint( int *pX, int *pY, double angle );
|
||||
void RotatePoint( int *pX, int *pY, const EDA_ANGLE& aAngle );
|
||||
|
||||
inline void RotatePoint( int *pX, int *pY, const EDA_ANGLE& angle )
|
||||
inline void RotatePoint( VECTOR2I& point, const EDA_ANGLE& aAngle )
|
||||
{
|
||||
RotatePoint( pX, pY, angle.AsTenthsOfADegree() );
|
||||
RotatePoint( &point.x, &point.y, aAngle );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Calculate the new point of coord coord pX, pY,
|
||||
* for a rotation center cx, cy, and angle in (1/10 degree)
|
||||
* Calculate the new point of coord coord pX, pY, for a rotation center cx, cy
|
||||
*/
|
||||
void RotatePoint( int *pX, int *pY, int cx, int cy, double angle );
|
||||
void RotatePoint( int *pX, int *pY, int cx, int cy, const EDA_ANGLE& aAngle );
|
||||
|
||||
inline void RotatePoint( int *pX, int *pY, int cx, int cy, const EDA_ANGLE& angle )
|
||||
inline void RotatePoint( VECTOR2I& point, const VECTOR2I& centre, const EDA_ANGLE& aAngle )
|
||||
{
|
||||
RotatePoint( pX, pY, cx, cy, angle.AsTenthsOfADegree() );
|
||||
RotatePoint( &point.x, &point.y, centre.x, centre.y, aAngle );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Calculate the new coord point point for a rotation angle in (1/10 degree).
|
||||
*/
|
||||
inline void RotatePoint( VECTOR2I& point, double angle )
|
||||
{
|
||||
RotatePoint( &point.x, &point.y, angle );
|
||||
}
|
||||
|
||||
inline void RotatePoint( VECTOR2I& point, const EDA_ANGLE& angle )
|
||||
{
|
||||
RotatePoint( &point.x, &point.y, angle.AsTenthsOfADegree() );
|
||||
}
|
||||
|
||||
void RotatePoint( VECTOR2I& point, const VECTOR2I& centre, double angle );
|
||||
|
||||
inline void RotatePoint( VECTOR2I& point, const VECTOR2I& centre, const EDA_ANGLE& angle )
|
||||
{
|
||||
RotatePoint( point, centre, angle.AsTenthsOfADegree() );
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the new coord point point for a center rotation center and angle in (1/10 degree).
|
||||
* Calculate the new coord point point for a rotation center 0, 0
|
||||
*/
|
||||
|
||||
void RotatePoint( double* pX, double* pY, double angle );
|
||||
void RotatePoint( double* pX, double* pY, const EDA_ANGLE& aAngle );
|
||||
|
||||
inline void RotatePoint( double* pX, double* pY, const EDA_ANGLE& angle )
|
||||
inline void RotatePoint( VECTOR2D& point, const EDA_ANGLE& aAngle )
|
||||
{
|
||||
RotatePoint( pX, pY, angle.AsTenthsOfADegree() );
|
||||
RotatePoint( &point.x, &point.y, aAngle );
|
||||
}
|
||||
|
||||
inline void RotatePoint( VECTOR2D& point, const EDA_ANGLE& angle )
|
||||
{
|
||||
RotatePoint( &point.x, &point.y, angle.AsTenthsOfADegree() );
|
||||
}
|
||||
|
||||
void RotatePoint( double* pX, double* pY, double cx, double cy, double angle );
|
||||
void RotatePoint( double* pX, double* pY, double cx, double cy, const EDA_ANGLE& aAngle );
|
||||
|
||||
inline void RotatePoint( double* pX, double* pY, double cx, double cy, const EDA_ANGLE& angle )
|
||||
inline void RotatePoint( VECTOR2D& point, const VECTOR2D& aCenter, const EDA_ANGLE& aAngle )
|
||||
{
|
||||
RotatePoint( pX, pY, cx, cy, angle.AsTenthsOfADegree() );
|
||||
}
|
||||
|
||||
inline void RotatePoint( VECTOR2D& point, const VECTOR2D& aCenter, const EDA_ANGLE& angle )
|
||||
{
|
||||
RotatePoint( &point.x, &point.y, aCenter.x, aCenter.y, angle.AsTenthsOfADegree() );
|
||||
RotatePoint( &point.x, &point.y, aCenter.x, aCenter.y, aAngle );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,16 +126,6 @@ const VECTOR2I CalcArcCenter( const VECTOR2I& aStart, const VECTOR2I& aEnd,
|
|||
const VECTOR2I CalcArcMid( const VECTOR2I& aStart, const VECTOR2I& aEnd, const VECTOR2I& aCenter,
|
||||
bool aMinArcAngle = true );
|
||||
|
||||
/* Return the arc tangent of 0.1 degrees coord vector dx, dy
|
||||
* between -1800 and 1800
|
||||
* Equivalent to atan2 (but faster for calculations if
|
||||
* the angle is 0 to -1800, or + - 900)
|
||||
* Lorenzo: In fact usually atan2 already has to do these optimizations
|
||||
* (due to the discontinuity in tan) but this function also returns
|
||||
* in decidegrees instead of radians, so it's handier
|
||||
*/
|
||||
double ArcTangente( int dy, int dx );
|
||||
|
||||
inline double EuclideanNorm( const VECTOR2I& vector )
|
||||
{
|
||||
// this is working with doubles
|
||||
|
@ -179,10 +140,9 @@ inline double EuclideanNorm( const VECTOR2I& vector )
|
|||
inline double DistanceLinePoint( const VECTOR2I& linePointA, const VECTOR2I& linePointB,
|
||||
const VECTOR2I& referencePoint )
|
||||
{
|
||||
// Some of the multiple double casts are redundant. However in the previous
|
||||
// definition the cast was (implicitly) done too late, just before
|
||||
// the division (EuclideanNorm gives a double so from int it would
|
||||
// be promoted); that means that the whole expression were
|
||||
// Some of the multiple double casts are redundant. However in the previous definition
|
||||
// the cast was (implicitly) done too late, just before the division (EuclideanNorm gives
|
||||
// a double so from int it would be promoted); that means that the whole expression were
|
||||
// vulnerable to overflow during int multiplications
|
||||
return fabs( ( static_cast<double>( linePointB.x - linePointA.x ) *
|
||||
static_cast<double>( linePointA.y - referencePoint.y ) -
|
||||
|
@ -200,8 +160,8 @@ inline bool HitTestPoints( const VECTOR2I& pointA, const VECTOR2I& pointB, doubl
|
|||
{
|
||||
VECTOR2I vectorAB = pointB - pointA;
|
||||
|
||||
// Compare the distances squared. The double is needed to avoid
|
||||
// overflow during int multiplication
|
||||
// Compare the distances squared. The double is needed to avoid overflow during int
|
||||
// multiplication
|
||||
double sqdistance = (double)vectorAB.x * vectorAB.x + (double)vectorAB.y * vectorAB.y;
|
||||
|
||||
return sqdistance < threshold * threshold;
|
||||
|
|
|
@ -180,93 +180,45 @@ const VECTOR2I CalcArcMid( const VECTOR2I& aStart, const VECTOR2I& aEnd, const V
|
|||
}
|
||||
|
||||
|
||||
double ArcTangente( int dy, int dx )
|
||||
void RotatePoint( int* pX, int* pY, const EDA_ANGLE& aAngle )
|
||||
{
|
||||
VECTOR2I pt;
|
||||
EDA_ANGLE angle = aAngle;
|
||||
|
||||
/* gcc is surprisingly smart in optimizing these conditions in
|
||||
a tree! */
|
||||
|
||||
if( dx == 0 && dy == 0 )
|
||||
return 0;
|
||||
|
||||
if( dy == 0 )
|
||||
{
|
||||
if( dx >= 0 )
|
||||
return 0;
|
||||
else
|
||||
return -1800;
|
||||
}
|
||||
|
||||
if( dx == 0 )
|
||||
{
|
||||
if( dy >= 0 )
|
||||
return 900;
|
||||
else
|
||||
return -900;
|
||||
}
|
||||
|
||||
if( dx == dy )
|
||||
{
|
||||
if( dx >= 0 )
|
||||
return 450;
|
||||
else
|
||||
return -1800 + 450;
|
||||
}
|
||||
|
||||
if( dx == -dy )
|
||||
{
|
||||
if( dx >= 0 )
|
||||
return -450;
|
||||
else
|
||||
return 1800 - 450;
|
||||
}
|
||||
|
||||
// Of course dy and dx are treated as double
|
||||
return RAD2DECIDEG( std::atan2( (double) dy, (double) dx ) );
|
||||
}
|
||||
|
||||
|
||||
void RotatePoint( int* pX, int* pY, double angle )
|
||||
{
|
||||
int tmp;
|
||||
|
||||
NORMALIZE_ANGLE_POS( angle );
|
||||
angle.Normalize();
|
||||
|
||||
// Cheap and dirty optimizations for 0, 90, 180, and 270 degrees.
|
||||
if( angle == 0 )
|
||||
return;
|
||||
|
||||
if( angle == 900 ) /* sin = 1, cos = 0 */
|
||||
if( angle == ANGLE_0 )
|
||||
{
|
||||
tmp = *pX;
|
||||
*pX = *pY;
|
||||
*pY = -tmp;
|
||||
pt = VECTOR2I( *pX, *pY );
|
||||
}
|
||||
else if( angle == 1800 ) /* sin = 0, cos = -1 */
|
||||
else if( angle == ANGLE_90 ) /* sin = 1, cos = 0 */
|
||||
{
|
||||
*pX = -*pX;
|
||||
*pY = -*pY;
|
||||
pt = VECTOR2I( *pY, -*pX );
|
||||
}
|
||||
else if( angle == 2700 ) /* sin = -1, cos = 0 */
|
||||
else if( angle == ANGLE_180 ) /* sin = 0, cos = -1 */
|
||||
{
|
||||
tmp = *pX;
|
||||
*pX = -*pY;
|
||||
*pY = tmp;
|
||||
pt = VECTOR2I( -*pX, -*pY );
|
||||
}
|
||||
else if( angle == ANGLE_270 ) /* sin = -1, cos = 0 */
|
||||
{
|
||||
pt = VECTOR2I( -*pY, *pX );
|
||||
}
|
||||
else
|
||||
{
|
||||
double fangle = DECIDEG2RAD( angle );
|
||||
double sinus = sin( fangle );
|
||||
double cosinus = cos( fangle );
|
||||
double fpx = (*pY * sinus ) + (*pX * cosinus );
|
||||
double fpy = (*pY * cosinus ) - (*pX * sinus );
|
||||
*pX = KiROUND( fpx );
|
||||
*pY = KiROUND( fpy );
|
||||
double sinus = angle.Sin();
|
||||
double cosinus = angle.Cos();
|
||||
|
||||
pt.x = KiROUND( ( *pY * sinus ) + ( *pX * cosinus ) );
|
||||
pt.y = KiROUND( ( *pY * cosinus ) - ( *pX * sinus ) );
|
||||
}
|
||||
|
||||
*pX = pt.x;
|
||||
*pY = pt.y;
|
||||
}
|
||||
|
||||
|
||||
void RotatePoint( int* pX, int* pY, int cx, int cy, double angle )
|
||||
void RotatePoint( int* pX, int* pY, int cx, int cy, const EDA_ANGLE& angle )
|
||||
{
|
||||
int ox, oy;
|
||||
|
||||
|
@ -280,7 +232,7 @@ void RotatePoint( int* pX, int* pY, int cx, int cy, double angle )
|
|||
}
|
||||
|
||||
|
||||
void RotatePoint( wxPoint* point, const wxPoint& centre, double angle )
|
||||
void RotatePoint( wxPoint* point, const wxPoint& centre, const EDA_ANGLE& angle )
|
||||
{
|
||||
int ox, oy;
|
||||
|
||||
|
@ -288,24 +240,13 @@ void RotatePoint( wxPoint* point, const wxPoint& centre, double angle )
|
|||
oy = point->y - centre.y;
|
||||
|
||||
RotatePoint( &ox, &oy, angle );
|
||||
|
||||
point->x = ox + centre.x;
|
||||
point->y = oy + centre.y;
|
||||
}
|
||||
|
||||
void RotatePoint( VECTOR2I& point, const VECTOR2I& centre, double angle )
|
||||
{
|
||||
int ox, oy;
|
||||
|
||||
ox = point.x - centre.x;
|
||||
oy = point.y - centre.y;
|
||||
|
||||
RotatePoint( &ox, &oy, angle );
|
||||
point.x = ox + centre.x;
|
||||
point.y = oy + centre.y;
|
||||
}
|
||||
|
||||
|
||||
void RotatePoint( double* pX, double* pY, double cx, double cy, double angle )
|
||||
void RotatePoint( double* pX, double* pY, double cx, double cy, const EDA_ANGLE& angle )
|
||||
{
|
||||
double ox, oy;
|
||||
|
||||
|
@ -319,44 +260,41 @@ void RotatePoint( double* pX, double* pY, double cx, double cy, double angle )
|
|||
}
|
||||
|
||||
|
||||
void RotatePoint( double* pX, double* pY, double angle )
|
||||
void RotatePoint( double* pX, double* pY, const EDA_ANGLE& aAngle )
|
||||
{
|
||||
double tmp;
|
||||
EDA_ANGLE angle = aAngle;
|
||||
VECTOR2D pt;
|
||||
|
||||
NORMALIZE_ANGLE_POS( angle );
|
||||
angle.Normalize();
|
||||
|
||||
// Cheap and dirty optimizations for 0, 90, 180, and 270 degrees.
|
||||
if( angle == 0 )
|
||||
return;
|
||||
|
||||
if( angle == 900 ) /* sin = 1, cos = 0 */
|
||||
if( angle == ANGLE_0 )
|
||||
{
|
||||
tmp = *pX;
|
||||
*pX = *pY;
|
||||
*pY = -tmp;
|
||||
pt = VECTOR2D( *pX, *pY );
|
||||
}
|
||||
else if( angle == 1800 ) /* sin = 0, cos = -1 */
|
||||
else if( angle == ANGLE_90 ) /* sin = 1, cos = 0 */
|
||||
{
|
||||
*pX = -*pX;
|
||||
*pY = -*pY;
|
||||
pt = VECTOR2D( *pY, -*pX );
|
||||
}
|
||||
else if( angle == 2700 ) /* sin = -1, cos = 0 */
|
||||
else if( angle == ANGLE_180 ) /* sin = 0, cos = -1 */
|
||||
{
|
||||
tmp = *pX;
|
||||
*pX = -*pY;
|
||||
*pY = tmp;
|
||||
pt = VECTOR2D( -*pX, -*pY );
|
||||
}
|
||||
else if( angle == ANGLE_270 ) /* sin = -1, cos = 0 */
|
||||
{
|
||||
pt = VECTOR2D( -*pY, *pX );
|
||||
}
|
||||
else
|
||||
{
|
||||
double fangle = DECIDEG2RAD( angle );
|
||||
double sinus = sin( fangle );
|
||||
double cosinus = cos( fangle );
|
||||
double sinus = angle.Sin();
|
||||
double cosinus = angle.Cos();
|
||||
|
||||
double fpx = (*pY * sinus ) + (*pX * cosinus );
|
||||
double fpy = (*pY * cosinus ) - (*pX * sinus );
|
||||
*pX = fpx;
|
||||
*pY = fpy;
|
||||
pt.x = ( *pY * sinus ) + ( *pX * cosinus );
|
||||
pt.y = ( *pY * cosinus ) - ( *pX * sinus );
|
||||
}
|
||||
|
||||
*pX = pt.x;
|
||||
*pY = pt.y;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -591,7 +591,7 @@ void AR_MATRIX::traceArc( int ux0, int uy0, int ux1, int uy1, double ArcAngle, i
|
|||
|
||||
x0 = ux1 - ux0;
|
||||
y0 = uy1 - uy0;
|
||||
StAngle = ArcTangente( uy1 - uy0, ux1 - ux0 );
|
||||
StAngle = EDA_ANGLE( VECTOR2I( ux1, uy1 ) - VECTOR2I( ux0, uy0 ) ).AsTenthsOfADegree();
|
||||
|
||||
if( lg < 1 )
|
||||
lg = 1;
|
||||
|
|
Loading…
Reference in New Issue