Fix drag-select hit-testing of LibEdit items.
This commit is contained in:
parent
5e08be7018
commit
b83dac68d0
|
@ -109,16 +109,24 @@ bool LIB_ARC::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) c
|
||||||
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
EDA_RECT rect = DefaultTransform.TransformCoordinate( aRect );
|
wxPoint center = DefaultTransform.TransformCoordinate( GetPosition() );
|
||||||
|
int radius = GetRadius();
|
||||||
|
int lineWidth = GetWidth();
|
||||||
|
EDA_RECT sel = aRect ;
|
||||||
|
|
||||||
if ( aAccuracy )
|
if ( aAccuracy )
|
||||||
rect.Inflate( aAccuracy );
|
sel.Inflate( aAccuracy );
|
||||||
|
|
||||||
if( aContained )
|
if( aContained )
|
||||||
return rect.Contains( GetBoundingBox() );
|
return sel.Contains( GetBoundingBox() );
|
||||||
|
|
||||||
return rect.Intersects( GetBoundingBox() ); // JEY TODO somewhat coarse for filled arcs,
|
EDA_RECT arcRect = GetBoundingBox().Common( sel );
|
||||||
// egregiously coarse for unfilled...
|
|
||||||
|
/* All following tests must pass:
|
||||||
|
* 1. Rectangle must intersect arc BoundingBox
|
||||||
|
* 2. Rectangle must cross the outside of the arc
|
||||||
|
*/
|
||||||
|
return arcRect.Intersects( sel ) && arcRect.IntersectsCircleEdge( center, radius, lineWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -289,16 +289,37 @@ bool LIB_BEZIER::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy
|
||||||
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
EDA_RECT rect = DefaultTransform.TransformCoordinate( aRect );
|
EDA_RECT sel = aRect;
|
||||||
|
|
||||||
if ( aAccuracy )
|
if ( aAccuracy )
|
||||||
rect.Inflate( aAccuracy );
|
sel.Inflate( aAccuracy );
|
||||||
|
|
||||||
if( aContained )
|
if( aContained )
|
||||||
return rect.Contains( GetBoundingBox() );
|
return sel.Contains( GetBoundingBox() );
|
||||||
|
|
||||||
return rect.Intersects( GetBoundingBox() ); // JEY TODO somewhat coarse for filled beziers,
|
// Fast test: if aRect is outside the polygon bounding box, rectangles cannot intersect
|
||||||
// egregiously coarse for unfilled...
|
if( !sel.Intersects( GetBoundingBox() ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Account for the width of the line
|
||||||
|
sel.Inflate( GetWidth() / 2 );
|
||||||
|
unsigned count = m_BezierPoints.size();
|
||||||
|
|
||||||
|
for( unsigned ii = 1; ii < count; ii++ )
|
||||||
|
{
|
||||||
|
wxPoint vertex = DefaultTransform.TransformCoordinate( m_BezierPoints[ii-1] );
|
||||||
|
wxPoint vertexNext = DefaultTransform.TransformCoordinate( m_BezierPoints[ii] );
|
||||||
|
|
||||||
|
// Test if the point is within aRect
|
||||||
|
if( sel.Contains( vertex ) )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Test if this edge intersects aRect
|
||||||
|
if( sel.Intersects( vertex, vertexNext ) )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -68,15 +68,22 @@ bool LIB_CIRCLE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy
|
||||||
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
EDA_RECT rect = DefaultTransform.TransformCoordinate( aRect );
|
wxPoint center = DefaultTransform.TransformCoordinate( GetPosition() );
|
||||||
|
int radius = GetRadius();
|
||||||
|
int lineWidth = GetWidth();
|
||||||
|
EDA_RECT sel = aRect ;
|
||||||
|
|
||||||
if ( aAccuracy )
|
if ( aAccuracy )
|
||||||
rect.Inflate( aAccuracy );
|
sel.Inflate( aAccuracy );
|
||||||
|
|
||||||
if( aContained )
|
if( aContained )
|
||||||
return rect.Contains( GetBoundingBox() );
|
return sel.Contains( GetBoundingBox() );
|
||||||
|
|
||||||
return rect.Intersects( GetBoundingBox() ); // JEY TODO somewhat coarse...
|
// If the rectangle does not intersect the bounding box, this is a much quicker test
|
||||||
|
if( !sel.Intersects( GetBoundingBox() ) )
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return sel.IntersectsCircleEdge( center, radius, lineWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -112,15 +112,15 @@ bool LIB_ITEM::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
|
||||||
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
EDA_RECT rect = DefaultTransform.TransformCoordinate( aRect );
|
EDA_RECT sel = aRect;
|
||||||
|
|
||||||
if ( aAccuracy )
|
if ( aAccuracy )
|
||||||
rect.Inflate( aAccuracy );
|
sel.Inflate( aAccuracy );
|
||||||
|
|
||||||
if( aContained )
|
if( aContained )
|
||||||
return rect.Contains( GetBoundingBox() );
|
return sel.Contains( GetBoundingBox() );
|
||||||
|
|
||||||
return rect.Intersects( GetBoundingBox() );
|
return sel.Intersects( GetBoundingBox() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -263,16 +263,37 @@ bool LIB_POLYLINE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccurac
|
||||||
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
EDA_RECT rect = aRect;
|
EDA_RECT sel = aRect;
|
||||||
|
|
||||||
if ( aAccuracy )
|
if ( aAccuracy )
|
||||||
rect.Inflate( aAccuracy );
|
sel.Inflate( aAccuracy );
|
||||||
|
|
||||||
if( aContained )
|
if( aContained )
|
||||||
return rect.Contains( GetBoundingBox() );
|
return sel.Contains( GetBoundingBox() );
|
||||||
|
|
||||||
return rect.Intersects( GetBoundingBox() ); // JEY TODO somewhat coarse for filled polylines,
|
// Fast test: if rect is outside the polygon bounding box, then they cannot intersect
|
||||||
// egregiously coarse for unfilled...
|
if( !sel.Intersects( GetBoundingBox() ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Account for the width of the line
|
||||||
|
sel.Inflate( GetWidth() / 2 );
|
||||||
|
int count = m_PolyPoints.size();
|
||||||
|
|
||||||
|
for( int ii = 0; ii < count; ii++ )
|
||||||
|
{
|
||||||
|
wxPoint pt = DefaultTransform.TransformCoordinate( m_PolyPoints[ ii ] );
|
||||||
|
wxPoint ptNext = DefaultTransform.TransformCoordinate( m_PolyPoints[ (ii+1) % count ] );
|
||||||
|
|
||||||
|
// Test if the point is within aRect
|
||||||
|
if( sel.Contains( pt ) )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Test if this edge intersects aRect
|
||||||
|
if( sel.Intersects( pt, ptNext ) )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -740,7 +740,6 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy
|
||||||
{
|
{
|
||||||
return arect.IntersectsCircleEdge( GetCenter(), GetRadius(), GetWidth() );
|
return arect.IntersectsCircleEdge( GetCenter(), GetRadius(), GetWidth() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue