7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 00:21:25 +00:00

Namespace KiGfx->KIGFX.

template<> -> template <>
Some more reformatting according to uncrustify results.
This commit is contained in:
Maciej Suminski 2013-10-14 16:13:35 +02:00
parent 22045b61ea
commit 0ac3e1fbf2
139 changed files with 1120 additions and 965 deletions
CMakeModules
common
include
pcbnew

View File

@ -24,7 +24,8 @@ file( WRITE ${outputFile} "// Do not edit this file, it is autogenerated by CMak
#define SHADER_SRC_H
const unsigned int shaders_number = ${shadersNumber};
const char *shaders_src[] = {\n" )
const char* shaders_src[] =
{\n" )
foreach( inputFile ${inputFiles} )
# put the input file name into the output file

View File

@ -231,7 +231,7 @@ void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent )
if( m_galCanvasActive )
{
m_galCanvas->GetGAL()->SetGridVisibility( IsGridVisible() );
m_galCanvas->GetView()->MarkTargetDirty( KiGfx::TARGET_NONCACHED );
m_galCanvas->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
}
m_canvas->Refresh();
@ -391,7 +391,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
{
m_galCanvas->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size.x,
screen->GetGrid().m_Size.y ) );
m_galCanvas->GetView()->MarkTargetDirty( KiGfx::TARGET_NONCACHED );
m_galCanvas->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
}
m_canvas->Refresh();
@ -425,8 +425,8 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
if( m_galCanvasActive )
{
// Apply computed view settings to GAL
KiGfx::VIEW* view = m_galCanvas->GetView();
KiGfx::GAL* gal = m_galCanvas->GetGAL();
KIGFX::VIEW* view = m_galCanvas->GetView();
KIGFX::GAL* gal = m_galCanvas->GetGAL();
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
double zoom = 1.0 / ( zoomFactor * GetZoom() );
@ -954,8 +954,8 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
{
KiGfx::VIEW* view = m_galCanvas->GetView();
KiGfx::GAL* gal = m_galCanvas->GetGAL();
KIGFX::VIEW* view = m_galCanvas->GetView();
KIGFX::GAL* gal = m_galCanvas->GetGAL();
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();

View File

@ -66,13 +66,13 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
m_gal->SetZoomFactor( 1.0 );
m_gal->ComputeWorldScreenMatrix();
m_painter = new KiGfx::PCB_PAINTER( m_gal );
m_painter = new KIGFX::PCB_PAINTER( m_gal );
m_view = new KiGfx::VIEW( true );
m_view = new KIGFX::VIEW( true );
m_view->SetPainter( m_painter );
m_view->SetGAL( m_gal );
m_viewControls = new KiGfx::WX_VIEW_CONTROLS( m_view, this );
m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this );
Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this );
@ -90,7 +90,7 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this );
Connect( KiGfx::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE,
Connect( KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE,
wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
m_refreshTimer.SetOwner( this );
@ -122,12 +122,12 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
m_lastRefresh = wxGetLocalTimeMillis();
m_gal->BeginDrawing();
m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) );
m_gal->SetBackgroundColor( KIGFX::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) );
m_gal->ClearScreen();
m_view->ClearTargets();
// Grid has to be redrawn only when the NONCACHED target is redrawn
if( m_view->IsTargetDirty( KiGfx::TARGET_NONCACHED ) )
if( m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) )
m_gal->DrawGrid();
m_view->Redraw();
m_gal->DrawCursor( m_viewControls->GetCursorPosition() );
@ -139,8 +139,8 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent )
{
m_gal->ResizeScreen( aEvent.GetSize().x, aEvent.GetSize().y );
m_view->MarkTargetDirty( KiGfx::TARGET_CACHED );
m_view->MarkTargetDirty( KiGfx::TARGET_NONCACHED );
m_view->MarkTargetDirty( KIGFX::TARGET_CACHED );
m_view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
}
@ -189,11 +189,11 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
switch( aGalType )
{
case GAL_TYPE_OPENGL:
m_gal = new KiGfx::OPENGL_GAL( this, this, this );
m_gal = new KIGFX::OPENGL_GAL( this, this, this );
break;
case GAL_TYPE_CAIRO:
m_gal = new KiGfx::CAIRO_GAL( this, this, this );
m_gal = new KIGFX::CAIRO_GAL( this, this, this );
break;
case GAL_TYPE_NONE:

View File

@ -31,7 +31,7 @@
#include <gal/cairo/cairo_compositor.h>
#include <wx/log.h>
using namespace KiGfx;
using namespace KIGFX;
CAIRO_COMPOSITOR::CAIRO_COMPOSITOR( cairo_t** aMainContext ) :
m_current( 0 ), m_currentContext( aMainContext ), m_mainContext( *aMainContext )
@ -67,6 +67,7 @@ unsigned int CAIRO_COMPOSITOR::CreateBuffer()
{
// Pixel storage
BitmapPtr bitmap( new unsigned int[m_bufferSize] );
memset( bitmap.get(), 0x00, m_bufferSize * sizeof(int) );
// Create the Cairo surface

View File

@ -33,10 +33,10 @@
#include <limits>
using namespace KiGfx;
using namespace KIGFX;
CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
wxEvtHandler* aPaintListener, const wxString& aName ) :
wxEvtHandler* aPaintListener, const wxString& aName ) :
wxWindow( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, aName )
{
parentWindow = aParent;
@ -92,6 +92,7 @@ CAIRO_GAL::~CAIRO_GAL()
void CAIRO_GAL::BeginDrawing()
{
initSurface();
if( !validCompositor )
setCompositor();
@ -284,6 +285,7 @@ void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight )
if( validCompositor )
compositor->Resize( aWidth, aHeight );
validCompositor = false;
SetSize( wxSize( aWidth, aHeight ) );
@ -788,6 +790,7 @@ void CAIRO_GAL::ClearTarget( RenderTarget aTarget )
compositor->SetBuffer( overlayBuffer );
break;
}
compositor->ClearBuffer();
// Restore the previous state

View File

@ -26,7 +26,7 @@
#include <gal/color4d.h>
using namespace KiGfx;
using namespace KIGFX;
COLOR4D::COLOR4D( EDA_COLOR_T aColor )
{
@ -85,14 +85,14 @@ void COLOR4D::ToHSV( double& aOutH, double& aOutS, double& aOutV ) const
return;
}
if( r >= max ) // > is bogus, just keeps compiler happy
aOutH = ( g - b ) / delta; // between yellow & magenta
if( r >= max ) // > is bogus, just keeps compiler happy
aOutH = ( g - b ) / delta; // between yellow & magenta
else if( g >= max )
aOutH = 2.0 + ( b - r ) / delta; // between cyan & yellow
aOutH = 2.0 + ( b - r ) / delta; // between cyan & yellow
else
aOutH = 4.0 + ( r - g ) / delta; // between magenta & cyan
aOutH = 4.0 + ( r - g ) / delta; // between magenta & cyan
aOutH *= 60.0; // degrees
aOutH *= 60.0; // degrees
if( aOutH < 0.0 )
aOutH += 360.0;
@ -104,7 +104,7 @@ void COLOR4D::FromHSV( double aInH, double aInS, double aInV )
double hh, p, q, t, ff;
long i;
if( aInS <= 0.0 ) // < is bogus, just shuts up warnings
if( aInS <= 0.0 ) // < is bogus, just shuts up warnings
{
r = aInV;
g = aInV;
@ -113,8 +113,10 @@ void COLOR4D::FromHSV( double aInH, double aInS, double aInV )
}
hh = aInH;
if( hh >= 360.0 )
hh = 0.0;
hh /= 60.0;
i = (long) hh;
@ -124,18 +126,20 @@ void COLOR4D::FromHSV( double aInH, double aInS, double aInV )
q = aInV * ( 1.0 - ( aInS * ff ) );
t = aInV * ( 1.0 - ( aInS * ( 1.0 - ff ) ) );
switch (i)
switch( i )
{
case 0:
r = aInV;
g = t;
b = p;
break;
case 1:
r = q;
g = aInV;
b = p;
break;
case 2:
r = p;
g = aInV;
@ -147,11 +151,13 @@ void COLOR4D::FromHSV( double aInH, double aInS, double aInV )
g = q;
b = aInV;
break;
case 4:
r = t;
g = p;
b = aInV;
break;
case 5:
default:
r = aInV;
@ -165,9 +171,9 @@ void COLOR4D::FromHSV( double aInH, double aInS, double aInV )
COLOR4D& COLOR4D::Saturate( double aFactor )
{
double h, s, v;
ToHSV( h, s, v );
FromHSV( h, aFactor, 1.0 );
return *this;
}

View File

@ -29,10 +29,10 @@
#include <gal/graphics_abstraction_layer.h>
#include <gal/definitions.h>
using namespace KiGfx;
using namespace KIGFX;
GAL::GAL() :
strokeFont( this )
strokeFont( this )
{
// Set the default values for the internal variables
SetIsFill( false );

View File

@ -39,7 +39,7 @@
#include <profile.h>
#endif /* __WXDEBUG__ */
using namespace KiGfx;
using namespace KIGFX;
CACHED_CONTAINER::CACHED_CONTAINER( unsigned int aSize ) :
VERTEX_CONTAINER( aSize ), m_item( NULL )
@ -88,7 +88,7 @@ void CACHED_CONTAINER::FinishItem()
#if CACHED_CONTAINER_TEST > 1
wxLogDebug( wxT( "Finishing item 0x%08lx (size %d)" ), (long) m_item, m_itemSize );
test();
m_item = NULL; // electric fence
m_item = NULL; // electric fence
#endif
}
@ -157,6 +157,7 @@ void CACHED_CONTAINER::Delete( VERTEX_ITEM* aItem )
// Indicate that the item is not stored in the container anymore
aItem->setSize( 0 );
}
m_items.erase( aItem );
#if CACHED_CONTAINER_TEST > 1
@ -371,6 +372,7 @@ void CACHED_CONTAINER::mergeFreeChunks()
std::list<Chunk> freeChunks;
FreeChunkMap::const_iterator it, it_end;
for( it = m_freeChunks.begin(), it_end = m_freeChunks.end(); it != it_end; ++it )
{
freeChunks.push_back( std::make_pair( it->second, it->first ) );
@ -527,6 +529,7 @@ void CACHED_CONTAINER::test()
// Free space check
unsigned int freeSpace = 0;
FreeChunkMap::iterator itf;
for( itf = m_freeChunks.begin(); itf != m_freeChunks.end(); ++itf )
freeSpace += getChunkSize( *itf );
@ -543,4 +546,5 @@ void CACHED_CONTAINER::test()
// Overlapping check TBD
}
#endif /* CACHED_CONTAINER_TEST */

View File

@ -37,7 +37,7 @@
#include <profile.h>
#endif
using namespace KiGfx;
using namespace KIGFX;
GPU_MANAGER* GPU_MANAGER::MakeManager( VERTEX_CONTAINER* aContainer )
{

View File

@ -31,7 +31,7 @@
#include <gal/opengl/noncached_container.h>
#include <cstdlib>
using namespace KiGfx;
using namespace KIGFX;
NONCACHED_CONTAINER::NONCACHED_CONTAINER( unsigned int aSize ) :
VERTEX_CONTAINER( aSize ), m_freePtr( 0 )

View File

@ -31,7 +31,7 @@
#include <gal/opengl/opengl_compositor.h>
#include <wx/log.h>
using namespace KiGfx;
using namespace KIGFX;
OPENGL_COMPOSITOR::OPENGL_COMPOSITOR() :
m_initialized( false ), m_current( 0 )
@ -95,12 +95,12 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer()
{
wxASSERT( m_initialized );
//if( usedBuffers() >= m_maxBuffers )
if( usedBuffers() >= m_maxBuffers )
{
wxLogError( wxT( "Cannot create more framebuffers. OpenGL rendering backend requires at"
"least 3 framebuffers. You may try to update/change "
"your graphic drivers." ) );
return 0; // Unfortunately we have no more free buffers left
return 0; // Unfortunately we have no more free buffers left
}
// GL_COLOR_ATTACHMENTn are consecutive integers
@ -145,7 +145,7 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer()
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
wxLogFatalError( wxT( "The framebuffer does not have at least "
"one image attached to it." ) );
"one image attached to it." ) );
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
@ -225,6 +225,7 @@ void OPENGL_COMPOSITOR::ClearBuffer()
void OPENGL_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle )
{
wxASSERT( m_initialized );
if( aBufferHandle == 0 || aBufferHandle > usedBuffers() )
{
wxLogError( wxT( "Wrong framebuffer handle" ) );
@ -281,6 +282,7 @@ void OPENGL_COMPOSITOR::clean()
glDeleteRenderbuffers( 1, &m_depthBuffer );
OPENGL_BUFFERS::const_iterator it;
for( it = m_buffers.begin(); it != m_buffers.end(); ++it )
{
glDeleteTextures( 1, &it->textureTarget );

View File

@ -37,7 +37,7 @@
#include <limits>
using namespace KiGfx;
using namespace KIGFX;
// Prototypes
void InitTesselatorCallbacks( GLUtesselator* aTesselator );
@ -90,10 +90,12 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
// Tesselator initialization
tesselator = gluNewTess();
InitTesselatorCallbacks( tesselator );
if( tesselator == NULL )
{
wxLogFatalError( wxT( "Could not create the tesselator" ) );
}
gluTessProperty( tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
}
@ -367,7 +369,8 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a
currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a );
VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
double alpha;
double alpha;
for( alpha = aStartAngle + alphaIncrement; alpha < aEndAngle; alpha += alphaIncrement )
{
VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
@ -570,7 +573,7 @@ void OPENGL_GAL::ClearScreen()
void OPENGL_GAL::SetStrokeColor( const COLOR4D& aColor )
{
strokeColor = aColor;
strokeColor = aColor;
// This is the default drawing color
currentManager->Color( aColor.r, aColor.g, aColor.b, aColor.a );
@ -734,6 +737,7 @@ void OPENGL_GAL::ClearTarget( RenderTarget aTarget )
compositor.SetBuffer( overlayBuffer );
break;
}
compositor.ClearBuffer();
// Restore the previous state

View File

@ -34,7 +34,7 @@
#include <gal/opengl/shader.h>
#include "shader_src.h"
using namespace KiGfx;
using namespace KIGFX;
SHADER::SHADER() :
isProgramCreated( false ),
@ -101,17 +101,19 @@ bool SHADER::Link()
(GLint*) &isShaderLinked );
#ifdef __WXDEBUG__
if( !isShaderLinked )
{
int maxLength;
glGetProgramiv( programNumber, GL_INFO_LOG_LENGTH, &maxLength );
maxLength = maxLength + 1;
char *linkInfoLog = new char[maxLength];
char* linkInfoLog = new char[maxLength];
glGetProgramInfoLog( programNumber, maxLength, &maxLength, linkInfoLog );
std::cerr << "Shader linking error:" << std::endl;
std::cerr << linkInfoLog;
delete[] linkInfoLog;
}
#endif /* __WXDEBUG__ */
return isShaderLinked;

View File

@ -73,4 +73,3 @@ void main()
gl_FragColor = gl_Color;
}
}

View File

@ -96,4 +96,3 @@ void main()
gl_FrontColor = gl_Color;
}

View File

@ -33,7 +33,7 @@
#include <gal/opengl/shader.h>
#include <wx/log.h>
using namespace KiGfx;
using namespace KIGFX;
VERTEX_CONTAINER* VERTEX_CONTAINER::MakeContainer( bool aCached )
{

View File

@ -31,7 +31,7 @@
#include <gal/opengl/vertex_manager.h>
#include <cstring>
using namespace KiGfx;
using namespace KIGFX;
VERTEX_ITEM::VERTEX_ITEM( const VERTEX_MANAGER& aManager ) :
m_manager( aManager ), m_offset( 0 ), m_size( 0 )

View File

@ -34,7 +34,7 @@
#include <gal/opengl/gpu_manager.h>
#include <gal/opengl/vertex_item.h>
using namespace KiGfx;
using namespace KIGFX;
VERTEX_MANAGER::VERTEX_MANAGER( bool aCached ) :
m_noTransform( true ), m_transform( 1.0f )
@ -106,6 +106,7 @@ void VERTEX_MANAGER::ChangeItemColor( const VERTEX_ITEM& aItem, const COLOR4D& a
unsigned int offset = aItem.GetOffset();
VERTEX* vertex = m_container->GetVertices( offset );
for( unsigned int i = 0; i < size; ++i )
{
vertex->r = aColor.r * 255.0;
@ -125,6 +126,7 @@ void VERTEX_MANAGER::ChangeItemDepth( const VERTEX_ITEM& aItem, GLfloat aDepth )
unsigned int offset = aItem.GetOffset();
VERTEX* vertex = m_container->GetVertices( offset );
for( unsigned int i = 0; i < size; ++i )
{
vertex->z = aDepth;

View File

@ -27,7 +27,7 @@
#include <gal/stroke_font.h>
#include <gal/graphics_abstraction_layer.h>
using namespace KiGfx;
using namespace KIGFX;
const double STROKE_FONT::LINE_HEIGHT_RATIO = 1.6;
@ -177,11 +177,13 @@ void STROKE_FONT::Draw( std::string aText, const VECTOR2D& aPosition, double aRo
case GR_TEXT_HJUSTIFY_RIGHT:
if( !m_mirrored )
m_gal->Translate( VECTOR2D( -textsize.x, 0 ) );
break;
case GR_TEXT_HJUSTIFY_LEFT:
if( m_mirrored )
m_gal->Translate( VECTOR2D( -textsize.x, 0 ) );
break;
default:

View File

@ -25,7 +25,9 @@
#include <geometry/seg.h>
template<typename T> int sgn( T val ) {
template<typename T>
int sgn( T val )
{
return ( T( 0 ) < val ) - ( val < T( 0 ) );
}
@ -64,8 +66,8 @@ bool SEG::PointCloserThan( const VECTOR2I& aP, int dist ) const
}
VECTOR2I nearest;
nearest.x = a.x + rescale( t, (ecoord)d.x, l_squared );
nearest.y = a.y + rescale( t, (ecoord)d.y, l_squared );
nearest.x = a.x + rescale( t, (ecoord) d.x, l_squared );
nearest.y = a.y + rescale( t, (ecoord) d.y, l_squared );
return ( nearest - aP ).SquaredEuclideanNorm() <= dist_sq;
}
@ -86,6 +88,7 @@ SEG::ecoord SEG::SquaredDistance( const SEG& aSeg ) const
};
ecoord m = VECTOR2I::ECOORD_MAX;
for( int i = 0; i < 4; i++ )
m = std::min( m, pts[i].SquaredEuclideanNorm() );
@ -95,9 +98,9 @@ SEG::ecoord SEG::SquaredDistance( const SEG& aSeg ) const
OPT_VECTOR2I SEG::Intersect( const SEG& aSeg, bool aIgnoreEndpoints, bool aLines ) const
{
const VECTOR2I e ( b - a );
const VECTOR2I f ( aSeg.b - aSeg.a );
const VECTOR2I ac ( aSeg.a - a );
const VECTOR2I e( b - a );
const VECTOR2I f( aSeg.b - aSeg.a );
const VECTOR2I ac( aSeg.a - a );
ecoord d = f.Cross( e );
ecoord p = f.Cross( ac );
@ -105,15 +108,18 @@ OPT_VECTOR2I SEG::Intersect( const SEG& aSeg, bool aIgnoreEndpoints, bool aLines
if( d == 0 )
return OPT_VECTOR2I();
if ( !aLines && d > 0 && ( q < 0 || q > d || p < 0 || p > d ) )
return OPT_VECTOR2I();
if ( !aLines && d < 0 && ( q < d || p < d || p > 0 || q > 0 ) )
return OPT_VECTOR2I();
if ( !aLines && aIgnoreEndpoints && ( q == 0 || q == d ) && ( p == 0 || p == d ) )
if( !aLines && d > 0 && ( q < 0 || q > d || p < 0 || p > d ) )
return OPT_VECTOR2I();
VECTOR2I ip( aSeg.a.x + rescale( q, (ecoord)f.x, d ),
aSeg.a.y + rescale( q, (ecoord)f.y, d ) );
if( !aLines && d < 0 && ( q < d || p < d || p > 0 || q > 0 ) )
return OPT_VECTOR2I();
if( !aLines && aIgnoreEndpoints && ( q == 0 || q == d ) && ( p == 0 || p == d ) )
return OPT_VECTOR2I();
VECTOR2I ip( aSeg.a.x + rescale( q, (ecoord) f.x, d ),
aSeg.a.y + rescale( q, (ecoord) f.y, d ) );
return ip;
}
@ -121,7 +127,7 @@ OPT_VECTOR2I SEG::Intersect( const SEG& aSeg, bool aIgnoreEndpoints, bool aLines
bool SEG::ccw( const VECTOR2I& a, const VECTOR2I& b, const VECTOR2I& c ) const
{
return (ecoord)( c.y - a.y ) * ( b.x - a.x ) > (ecoord)( b.y - a.y ) * ( c.x - a.x );
return (ecoord) ( c.y - a.y ) * ( b.x - a.x ) > (ecoord) ( b.y - a.y ) * ( c.x - a.x );
}
@ -133,8 +139,8 @@ bool SEG::Collide( const SEG& aSeg, int aClearance ) const
ccw( a, b, aSeg.a ) != ccw( a, b, aSeg.b ) )
return true;
#define CHK(_seg, _pt) \
if( (_seg).PointCloserThan (_pt, aClearance ) ) return true;
#define CHK( _seg, _pt ) \
if( (_seg).PointCloserThan( _pt, aClearance ) ) return true;
CHK( *this, aSeg.a );
CHK( *this, aSeg.b );

View File

@ -41,11 +41,11 @@ static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_CIRCLE& aB, int
ecoord dist_sq = delta.SquaredEuclideanNorm();
if ( dist_sq >= min_dist_sq )
if( dist_sq >= min_dist_sq )
return false;
if ( aNeedMTV )
aMTV = delta.Resize( sqrt ( abs( min_dist_sq - dist_sq ) ) + 1 );
if( aNeedMTV )
aMTV = delta.Resize( sqrt( abs( min_dist_sq - dist_sq ) ) + 1 );
return true;
}
@ -60,28 +60,29 @@ static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_CIRCLE& aB, int a
const ecoord min_dist = aClearance + r;
const ecoord min_dist_sq = min_dist * min_dist;
if ( aA.BBox( 0 ).Contains( c ) )
if( aA.BBox( 0 ).Contains( c ) )
return true;
const VECTOR2I vts[] = {
VECTOR2I(p0.x, p0.y),
VECTOR2I(p0.x, p0.y + size.y),
VECTOR2I(p0.x + size.x, p0.y + size.y),
VECTOR2I(p0.x + size.x, p0.y),
VECTOR2I(p0.x, p0.y) };
const VECTOR2I vts[] =
{
VECTOR2I( p0.x, p0.y ),
VECTOR2I( p0.x, p0.y + size.y ),
VECTOR2I( p0.x + size.x, p0.y + size.y ),
VECTOR2I( p0.x + size.x, p0.y ),
VECTOR2I( p0.x, p0.y )
};
ecoord nearest_seg_dist_sq = VECTOR2I::ECOORD_MAX;
VECTOR2I nearest;
bool inside = c.x >= p0.x && c.x <= ( p0.x + size.x )
&& c.y >= p0.y && c.y <= ( p0.y + size.y );
bool inside = c.x >= p0.x && c.x <= ( p0.x + size.x )
&& c.y >= p0.y && c.y <= ( p0.y + size.y );
if( !inside )
{
for( int i = 0; i < 4; i++ )
{
const SEG seg( vts[i], vts[i+1] );
const SEG seg( vts[i], vts[i + 1] );
ecoord dist_sq = seg.SquaredDistance( c );
if( dist_sq < min_dist_sq )
@ -119,7 +120,7 @@ static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_LINE_CHAIN& aB,
{
for( int s = 0; s < aB.SegmentCount(); s++ )
{
if ( aA.Collide( aB.CSegment( s ), aClearance ) )
if( aA.Collide( aB.CSegment( s ), aClearance ) )
return true;
}
@ -131,8 +132,9 @@ static inline bool Collide( const SHAPE_LINE_CHAIN& aA, const SHAPE_LINE_CHAIN&
bool aNeedMTV, VECTOR2I& aMTV )
{
for( int i = 0; i < aB.SegmentCount(); i++ )
if( aA.Collide( aB.CSegment(i), aClearance ) )
if( aA.Collide( aB.CSegment( i ), aClearance ) )
return true;
return false;
}
@ -143,8 +145,9 @@ static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_LINE_CHAIN& aB, in
for( int s = 0; s < aB.SegmentCount(); s++ )
{
SEG seg = aB.CSegment( s );
if( aA.Collide( seg, aClearance ) )
return true;
if( aA.Collide( seg, aClearance ) )
return true;
}
return false;
@ -222,12 +225,13 @@ bool CollideShapes( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeed
bool SHAPE::Collide( const SHAPE* aShape, int aClerance, VECTOR2I& aMTV ) const
{
return CollideShapes( this, aShape, aClerance, true, aMTV);
return CollideShapes( this, aShape, aClerance, true, aMTV );
}
bool SHAPE::Collide ( const SHAPE* aShape, int aClerance ) const
bool SHAPE::Collide( const SHAPE* aShape, int aClerance ) const
{
VECTOR2I dummy;
return CollideShapes( this, aShape, aClerance, false, dummy );
}

View File

@ -47,12 +47,12 @@ bool SHAPE_LINE_CHAIN::Collide( const SEG& aSeg, int aClearance ) const
BOX2I box_a( aSeg.a, aSeg.b - aSeg.a );
BOX2I::ecoord_type dist_sq = (BOX2I::ecoord_type) aClearance * aClearance;
for( int i = 0; i < SegmentCount() ;i++ )
for( int i = 0; i < SegmentCount(); i++ )
{
const SEG& s = CSegment( i );
BOX2I box_b( s.a, s.b - s.a );
BOX2I::ecoord_type d = box_a.SquaredDistance ( box_b );
BOX2I::ecoord_type d = box_a.SquaredDistance( box_b );
if( d < dist_sq )
{
@ -64,9 +64,11 @@ bool SHAPE_LINE_CHAIN::Collide( const SEG& aSeg, int aClearance ) const
return false;
}
const SHAPE_LINE_CHAIN SHAPE_LINE_CHAIN::Reverse() const
{
SHAPE_LINE_CHAIN a( *this );
reverse( a.m_points.begin(), a.m_points.end() );
a.m_closed = m_closed;
@ -77,6 +79,7 @@ const SHAPE_LINE_CHAIN SHAPE_LINE_CHAIN::Reverse() const
int SHAPE_LINE_CHAIN::Length() const
{
int l = 0;
for( int i = 0; i < SegmentCount(); i++ )
l += CSegment( i ).Length();
@ -88,11 +91,12 @@ void SHAPE_LINE_CHAIN::Replace( int aStartIndex, int aEndIndex, const VECTOR2I&
{
if( aEndIndex < 0 )
aEndIndex += PointCount();
if( aStartIndex < 0 )
aStartIndex += PointCount();
if( aStartIndex == aEndIndex )
m_points [aStartIndex] = aP;
m_points[aStartIndex] = aP;
else
{
m_points.erase( m_points.begin() + aStartIndex + 1, m_points.begin() + aEndIndex + 1 );
@ -105,6 +109,7 @@ void SHAPE_LINE_CHAIN::Replace( int aStartIndex, int aEndIndex, const SHAPE_LINE
{
if( aEndIndex < 0 )
aEndIndex += PointCount();
if( aStartIndex < 0 )
aStartIndex += PointCount();
@ -115,9 +120,10 @@ void SHAPE_LINE_CHAIN::Replace( int aStartIndex, int aEndIndex, const SHAPE_LINE
void SHAPE_LINE_CHAIN::Remove( int aStartIndex, int aEndIndex )
{
if(aEndIndex < 0)
if( aEndIndex < 0 )
aEndIndex += PointCount();
if(aStartIndex < 0)
if( aStartIndex < 0 )
aStartIndex += PointCount();
m_points.erase( m_points.begin() + aStartIndex, m_points.begin() + aEndIndex + 1 );
@ -127,6 +133,7 @@ void SHAPE_LINE_CHAIN::Remove( int aStartIndex, int aEndIndex )
int SHAPE_LINE_CHAIN::Distance( const VECTOR2I& aP ) const
{
int d = INT_MAX;
for( int s = 0; s < SegmentCount(); s++ )
d = min( d, CSegment( s ).Distance( aP ) );
@ -185,6 +192,7 @@ const SHAPE_LINE_CHAIN SHAPE_LINE_CHAIN::Slice( int aStartIndex, int aEndIndex )
if( aEndIndex < 0 )
aEndIndex += PointCount();
if( aStartIndex < 0 )
aStartIndex += PointCount();
@ -197,7 +205,7 @@ const SHAPE_LINE_CHAIN SHAPE_LINE_CHAIN::Slice( int aStartIndex, int aEndIndex )
struct compareOriginDistance
{
compareOriginDistance( VECTOR2I& aOrigin ):
compareOriginDistance( VECTOR2I& aOrigin ) :
m_origin( aOrigin ) {};
bool operator()( const SHAPE_LINE_CHAIN::Intersection& aA,
@ -215,6 +223,7 @@ int SHAPE_LINE_CHAIN::Intersect( const SEG& aSeg, Intersections& aIp ) const
for( int s = 0; s < SegmentCount(); s++ )
{
OPT_VECTOR2I p = CSegment( s ).Intersect( aSeg );
if( p )
{
Intersection is;
@ -236,7 +245,7 @@ int SHAPE_LINE_CHAIN::Intersect( const SHAPE_LINE_CHAIN& aChain, Intersections&
{
BOX2I bb_other = aChain.BBox();
for ( int s1 = 0; s1 < SegmentCount(); s1++ )
for( int s1 = 0; s1 < SegmentCount(); s1++ )
{
const SEG& a = CSegment( s1 );
const BOX2I bb_cur( a.a, a.b - a.a );
@ -305,7 +314,6 @@ int SHAPE_LINE_CHAIN::Intersect( const SHAPE_LINE_CHAIN& aChain, Intersections&
is.their = b;
aIp.push_back( is );
}
}
}
}
@ -317,6 +325,7 @@ int SHAPE_LINE_CHAIN::Intersect( const SHAPE_LINE_CHAIN& aChain, Intersections&
int SHAPE_LINE_CHAIN::PathLength( const VECTOR2I& aP ) const
{
int sum = 0;
for( int i = 0; i < SegmentCount(); i++ )
{
const SEG seg = CSegment( i );
@ -340,7 +349,7 @@ bool SHAPE_LINE_CHAIN::PointInside( const VECTOR2I& aP ) const
if( !m_closed || SegmentCount() < 3 )
return false;
int cur = CSegment(0).Side( aP );
int cur = CSegment( 0 ).Side( aP );
if( cur == 0 )
return false;
@ -352,7 +361,7 @@ bool SHAPE_LINE_CHAIN::PointInside( const VECTOR2I& aP ) const
if( aP == s.a || aP == s.b ) // edge does not belong to the interior!
return false;
if( s.Side(aP) != cur )
if( s.Side( aP ) != cur )
return false;
}
@ -372,7 +381,7 @@ bool SHAPE_LINE_CHAIN::PointOnEdge( const VECTOR2I& aP ) const
if( s.a == aP || s.b == aP )
return true;
if( s.Distance(aP) <= 1 )
if( s.Distance( aP ) <= 1 )
return true;
}
@ -387,6 +396,7 @@ const optional<SHAPE_LINE_CHAIN::Intersection> SHAPE_LINE_CHAIN::SelfIntersectin
for( int s2 = s1 + 1; s2 < SegmentCount(); s2++ )
{
const VECTOR2I s2a = CSegment( s2 ).a, s2b = CSegment( s2 ).b;
if( s1 + 1 != s2 && CSegment( s1 ).Contains( s2a ) )
{
Intersection is;
@ -395,7 +405,7 @@ const optional<SHAPE_LINE_CHAIN::Intersection> SHAPE_LINE_CHAIN::SelfIntersectin
is.p = s2a;
return is;
}
else if( CSegment( s1 ).Contains(s2b ) )
else if( CSegment( s1 ).Contains( s2b ) )
{
Intersection is;
is.our = CSegment( s1 );
@ -443,10 +453,11 @@ SHAPE_LINE_CHAIN& SHAPE_LINE_CHAIN::Simplify()
int np = PointCount();
// stage 1: eliminate duplicate vertices
while ( i < np )
while( i < np )
{
int j = i + 1;
while( j < np && CPoint(i) == CPoint( j ) )
while( j < np && CPoint( i ) == CPoint( j ) )
j++;
pts_unique.push_back( CPoint( i ) );
@ -457,17 +468,19 @@ SHAPE_LINE_CHAIN& SHAPE_LINE_CHAIN::Simplify()
np = pts_unique.size();
i = 0;
// stage 1: eliminate collinear segments
while( i < np - 2 )
{
const VECTOR2I p0 = pts_unique[i];
const VECTOR2I p1 = pts_unique[i+1];
const VECTOR2I p1 = pts_unique[i + 1];
int n = i;
while( n < np - 2 && SEG( p0, p1 ).LineDistance( pts_unique[n + 2] ) <= 1 )
n++;
m_points.push_back( p0 );
if( n > i )
i = n;
@ -493,9 +506,11 @@ const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const VECTOR2I& aP ) const
{
int min_d = INT_MAX;
int nearest = 0;
for ( int i = 0; i < SegmentCount(); i++ )
for( int i = 0; i < SegmentCount(); i++ )
{
int d = CSegment( i ).Distance( aP );
if( d < min_d )
{
min_d = d;
@ -511,10 +526,10 @@ const string SHAPE_LINE_CHAIN::Format() const
{
stringstream ss;
ss << m_points.size() << " " << ( m_closed ? 1 : 0 ) << " " ;
ss << m_points.size() << " " << ( m_closed ? 1 : 0 ) << " ";
for( int i = 0; i < PointCount(); i++ )
ss << m_points[i].x << " " << m_points[i].y << " ";// Format() << " ";
ss << m_points[i].x << " " << m_points[i].y << " "; // Format() << " ";
return ss.str();
}

View File

@ -28,16 +28,18 @@
#include <climits>
#include <math/math_util.h>
template<> int rescale( int numerator, int value, int denominator )
template<>
int rescale( int numerator, int value, int denominator )
{
return (int) ( (int64_t) numerator * (int64_t) value / (int64_t) denominator );
}
template<> int64_t rescale( int64_t numerator, int64_t value, int64_t denominator )
template<>
int64_t rescale( int64_t numerator, int64_t value, int64_t denominator )
{
int64_t r = 0;
int64_t sign = ( ( numerator < 0) ? -1 : 1 ) * ( denominator < 0 ? - 1: 1 ) * (value < 0 ? - 1 : 1);
int64_t sign = ( ( numerator < 0) ? -1 : 1 ) * ( denominator < 0 ? -1 : 1 ) * ( value < 0 ? -1 : 1 );
int64_t a = std::abs( numerator );
int64_t b = std::abs( value );
@ -51,7 +53,9 @@ template<> int64_t rescale( int64_t numerator, int64_t value, int64_t denominato
return sign * ( (a * b + r ) / c );
else
return sign * (a / c * b + (a % c * b + r) / c);
} else {
}
else
{
uint64_t a0 = a & 0xFFFFFFFF;
uint64_t a1 = a >> 32;
uint64_t b0 = b & 0xFFFFFFFF;
@ -61,16 +65,16 @@ template<> int64_t rescale( int64_t numerator, int64_t value, int64_t denominato
int i;
a0 = a0 * b0 + t1a;
a1 = a1 * b1 + (t1 >> 32) + (a0 < t1a);
a1 = a1 * b1 + ( t1 >> 32 ) + ( a0 < t1a );
a0 += r;
a1 += ((uint64_t)a0) < r;
a1 += ( (uint64_t) a0 ) < r;
for( i = 63; i >= 0; i-- )
{
a1 += a1 + ( (a0 >> i) & 1 );
a1 += a1 + ( ( a0 >> i ) & 1 );
t1 += t1;
if( (uint64_t)c <= a1 )
if( (uint64_t) c <= a1 )
{
a1 -= c;
t1++;

View File

@ -27,7 +27,7 @@
#include <painter.h>
#include <gal/graphics_abstraction_layer.h>
using namespace KiGfx;
using namespace KIGFX;
RENDER_SETTINGS::RENDER_SETTINGS()
{

View File

@ -36,7 +36,7 @@ ACTION_MANAGER::ACTION_MANAGER( TOOL_MANAGER* aToolManager ) :
void ACTION_MANAGER::RegisterAction( TOOL_ACTION* aAction )
{
assert( aAction->GetId() == -1 ); // Check if the TOOL_ACTION was not registered before
assert( aAction->GetId() == -1 ); // Check if the TOOL_ACTION was not registered before
aAction->setId( MakeActionId( aAction->m_name ) );
@ -67,6 +67,7 @@ void ACTION_MANAGER::UnregisterAction( TOOL_ACTION* aAction )
int ACTION_MANAGER::MakeActionId( const std::string& aActionName )
{
static int currentActionId = 1;
return currentActionId++;
}
@ -76,7 +77,7 @@ bool ACTION_MANAGER::RunAction( const std::string& aActionName ) const
std::map<std::string, TOOL_ACTION*>::const_iterator it = m_actionNameIndex.find( aActionName );
if( it == m_actionNameIndex.end() )
return false; // no action with given name found
return false; // no action with given name found
runAction( it->second );
@ -89,7 +90,7 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const
std::map<int, TOOL_ACTION*>::const_iterator it = m_actionHotKeys.find( aHotKey );
if( it == m_actionHotKeys.end() )
return false; // no appropriate action found for the hotkey
return false; // no appropriate action found for the hotkey
runAction( it->second );

Some files were not shown because too many files have changed in this diff Show More