Cleanup some more excess math/util includes
This commit is contained in:
parent
0b4a680dbb
commit
eeb405c196
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <compoundfilereader.h>
|
||||
#include <ki_exception.h>
|
||||
#include <math/util.h>
|
||||
#include <sstream>
|
||||
#include <utf.h>
|
||||
#include <wx/wx.h>
|
||||
|
@ -149,6 +150,29 @@ std::map<wxString, wxString> ALTIUM_PARSER::ReadProperties()
|
|||
return kv;
|
||||
}
|
||||
|
||||
|
||||
int32_t ALTIUM_PARSER::ConvertToKicadUnit( const double aValue )
|
||||
{
|
||||
const double int_limit = ( std::numeric_limits<int>::max() - 1 ) / 2.54;
|
||||
|
||||
int32_t iu = KiROUND( Clamp<double>( -int_limit, aValue, int_limit ) * 2.54 );
|
||||
|
||||
// Altium stores metric units up to 0.001mm (1000nm) in accuracy. This code fixes rounding errors.
|
||||
// Because imperial units > 0.01mil are always even, this workaround should never trigger for them.
|
||||
switch( iu % 1000 )
|
||||
{
|
||||
case 1:
|
||||
case -999:
|
||||
return iu - 1;
|
||||
case 999:
|
||||
case -1:
|
||||
return iu + 1;
|
||||
default:
|
||||
return iu;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ALTIUM_PARSER::PropertiesReadInt(
|
||||
const std::map<wxString, wxString>& aProperties, const wxString& aKey, int aDefault )
|
||||
{
|
||||
|
@ -156,6 +180,7 @@ int ALTIUM_PARSER::PropertiesReadInt(
|
|||
return value == aProperties.end() ? aDefault : wxAtoi( value->second );
|
||||
}
|
||||
|
||||
|
||||
double ALTIUM_PARSER::PropertiesReadDouble(
|
||||
const std::map<wxString, wxString>& aProperties, const wxString& aKey, double aDefault )
|
||||
{
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <math/util.h>
|
||||
#include <wx/gdicmn.h>
|
||||
#include <vector>
|
||||
|
||||
|
@ -138,26 +137,7 @@ public:
|
|||
|
||||
std::map<wxString, wxString> ReadProperties();
|
||||
|
||||
static int32_t ConvertToKicadUnit( const double aValue )
|
||||
{
|
||||
const double int_limit = ( std::numeric_limits<int>::max() - 1 ) / 2.54;
|
||||
|
||||
int32_t iu = KiROUND( Clamp<double>( -int_limit, aValue, int_limit ) * 2.54 );
|
||||
|
||||
// Altium stores metric units up to 0.001mm (1000nm) in accuracy. This code fixes rounding errors.
|
||||
// Because imperial units > 0.01mil are always even, this workaround should never trigger for them.
|
||||
switch( iu % 1000 )
|
||||
{
|
||||
case 1:
|
||||
case -999:
|
||||
return iu - 1;
|
||||
case 999:
|
||||
case -1:
|
||||
return iu + 1;
|
||||
default:
|
||||
return iu;
|
||||
}
|
||||
}
|
||||
static int32_t ConvertToKicadUnit( const double aValue );
|
||||
|
||||
static int PropertiesReadInt(
|
||||
const std::map<wxString, wxString>& aProperties, const wxString& aKey, int aDefault );
|
||||
|
|
|
@ -265,6 +265,12 @@ void LIB_CIRCLE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList
|
|||
}
|
||||
|
||||
|
||||
int LIB_CIRCLE::GetRadius() const
|
||||
{
|
||||
return KiROUND( GetLineLength( m_EndPos, m_Pos ) );
|
||||
}
|
||||
|
||||
|
||||
wxString LIB_CIRCLE::GetSelectMenuText( EDA_UNITS aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Circle, radius %s" ),
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#define LIB_CIRCLE_H
|
||||
|
||||
#include <lib_item.h>
|
||||
#include <math/util.h> // for KiROUND
|
||||
#include <trigo.h> // for GetLineLength
|
||||
|
||||
|
||||
|
@ -81,7 +80,7 @@ public:
|
|||
void SetWidth( int aWidth ) override { m_Width = aWidth; }
|
||||
|
||||
void SetRadius( int aRadius ) { m_EndPos = wxPoint( m_Pos.x + aRadius, m_Pos.y ); }
|
||||
int GetRadius() const { return KiROUND( GetLineLength( m_EndPos, m_Pos ) ); }
|
||||
int GetRadius() const;
|
||||
|
||||
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
|
||||
#include <sch_item.h>
|
||||
#include <math/util.h> // for KiROUND
|
||||
|
||||
|
||||
class NETLIST_OBJECT_LIST;
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <lib_polyline.h>
|
||||
#include <lib_rectangle.h>
|
||||
#include <lib_text.h>
|
||||
#include <math/util.h> // KiROUND, Clamp
|
||||
#include <sch_bitmap.h>
|
||||
#include <sch_bus_entry.h>
|
||||
#include <sch_symbol.h>
|
||||
|
@ -450,6 +451,29 @@ double SCH_SEXPR_PARSER::parseDouble()
|
|||
}
|
||||
|
||||
|
||||
int SCH_SEXPR_PARSER::parseInternalUnits()
|
||||
{
|
||||
auto retval = parseDouble() * IU_PER_MM;
|
||||
|
||||
// Schematic internal units are represented as integers. Any values that are
|
||||
// larger or smaller than the schematic units represent undefined behavior for
|
||||
// the system. Limit values to the largest that can be displayed on the screen.
|
||||
double int_limit = std::numeric_limits<int>::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2)
|
||||
|
||||
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
|
||||
}
|
||||
|
||||
|
||||
int SCH_SEXPR_PARSER::parseInternalUnits( const char* aExpected )
|
||||
{
|
||||
auto retval = parseDouble( aExpected ) * IU_PER_MM;
|
||||
|
||||
double int_limit = std::numeric_limits<int>::max() * 0.7071;
|
||||
|
||||
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
|
||||
}
|
||||
|
||||
|
||||
void SCH_SEXPR_PARSER::parseStroke( STROKE_PARAMS& aStroke )
|
||||
{
|
||||
wxCHECK_RET( CurTok() == T_stroke,
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#define __SCH_SEXPR_PARSER_H__
|
||||
|
||||
#include <convert_to_biu.h> // IU_PER_MM
|
||||
#include <math/util.h> // KiROUND, Clamp
|
||||
|
||||
#include <class_library.h>
|
||||
#include <schematic_lexer.h>
|
||||
|
@ -123,26 +122,9 @@ class SCH_SEXPR_PARSER : public SCHEMATIC_LEXER
|
|||
return parseDouble( GetTokenText( aToken ) );
|
||||
}
|
||||
|
||||
inline int parseInternalUnits()
|
||||
{
|
||||
auto retval = parseDouble() * IU_PER_MM;
|
||||
int parseInternalUnits();
|
||||
|
||||
// Schematic internal units are represented as integers. Any values that are
|
||||
// larger or smaller than the schematic units represent undefined behavior for
|
||||
// the system. Limit values to the largest that can be displayed on the screen.
|
||||
double int_limit = std::numeric_limits<int>::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2)
|
||||
|
||||
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
|
||||
}
|
||||
|
||||
inline int parseInternalUnits( const char* aExpected )
|
||||
{
|
||||
auto retval = parseDouble( aExpected ) * IU_PER_MM;
|
||||
|
||||
double int_limit = std::numeric_limits<int>::max() * 0.7071;
|
||||
|
||||
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
|
||||
}
|
||||
int parseInternalUnits( const char* aExpected );
|
||||
|
||||
inline int parseInternalUnits( TSCHEMATIC_T::T aToken )
|
||||
{
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <settings/color_settings.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <i18n_utility.h>
|
||||
#include <math/util.h> // for KiROUND
|
||||
|
||||
|
||||
PCB_SHAPE::PCB_SHAPE( BOARD_ITEM* aParent, KICAD_T idtype ) :
|
||||
|
@ -440,6 +441,15 @@ double PCB_SHAPE::GetArcAngleEnd() const
|
|||
}
|
||||
|
||||
|
||||
int PCB_SHAPE::GetRadius() const
|
||||
{
|
||||
double radius = GetLineLength( m_start, m_end );
|
||||
|
||||
// don't allow degenerate arcs
|
||||
return std::max( 1, KiROUND( radius ) );
|
||||
}
|
||||
|
||||
|
||||
void PCB_SHAPE::SetArcGeometry( const wxPoint& aStart, const wxPoint& aMid, const wxPoint& aEnd )
|
||||
{
|
||||
SetArcStart( aStart );
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <board_item.h>
|
||||
#include <eda_units.h>
|
||||
#include <convert_to_biu.h>
|
||||
#include <math/util.h> // for KiROUND
|
||||
#include <math_for_graphics.h>
|
||||
#include <trigo.h>
|
||||
#include <geometry/shape_poly_set.h>
|
||||
|
@ -198,13 +197,7 @@ public:
|
|||
* returns the radius of this item
|
||||
* Has meaning only for arc and circle
|
||||
*/
|
||||
int GetRadius() const
|
||||
{
|
||||
double radius = GetLineLength( m_start, m_end );
|
||||
|
||||
// don't allow degenerate arcs
|
||||
return std::max( 1, KiROUND( radius ) );
|
||||
}
|
||||
int GetRadius() const;
|
||||
|
||||
/**
|
||||
* Initialize the start arc point. can be used for circles
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#define PCBPLOT_H_
|
||||
|
||||
#include <layers_id_colors_and_visibility.h>
|
||||
#include <math/util.h> // for KiROUND
|
||||
#include <pad_shapes.h>
|
||||
#include <pcb_plot_params.h>
|
||||
#include <pgm_base.h>
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
#include <plugins/kicad/pcb_parser.h>
|
||||
#include <convert_basic_shapes_to_polygon.h> // for RECT_CHAMFER_POSITIONS definition
|
||||
#include <template_fieldnames.h>
|
||||
#include <math/util.h> // KiROUND, Clamp
|
||||
#include <wx/log.h>
|
||||
|
||||
using namespace PCB_KEYS_T;
|
||||
|
@ -167,6 +168,40 @@ double PCB_PARSER::parseDouble()
|
|||
}
|
||||
|
||||
|
||||
int PCB_PARSER::parseBoardUnits()
|
||||
{
|
||||
// There should be no major rounding issues here, since the values in
|
||||
// the file are in mm and get converted to nano-meters.
|
||||
// See test program tools/test-nm-biu-to-ascii-mm-round-tripping.cpp
|
||||
// to confirm or experiment. Use a similar strategy in both places, here
|
||||
// and in the test program. Make that program with:
|
||||
// $ make test-nm-biu-to-ascii-mm-round-tripping
|
||||
auto retval = parseDouble() * IU_PER_MM;
|
||||
|
||||
// N.B. we currently represent board units as integers. Any values that are
|
||||
// larger or smaller than those board units represent undefined behavior for
|
||||
// the system. We limit values to the largest that is visible on the screen
|
||||
// This is the diagonal distance of the full screen ~1.5m
|
||||
double int_limit = std::numeric_limits<int>::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2)
|
||||
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
|
||||
}
|
||||
|
||||
|
||||
int PCB_PARSER::parseBoardUnits( const char* aExpected )
|
||||
{
|
||||
auto retval = parseDouble( aExpected ) * IU_PER_MM;
|
||||
|
||||
// N.B. we currently represent board units as integers. Any values that are
|
||||
// larger or smaller than those board units represent undefined behavior for
|
||||
// the system. We limit values to the largest that is visible on the screen
|
||||
double int_limit = std::numeric_limits<int>::max() * 0.7071;
|
||||
|
||||
// Use here #KiROUND, not EKIROUND (see comments about them) when having a function as
|
||||
// argument, because it will be called twice with #KIROUND.
|
||||
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
|
||||
}
|
||||
|
||||
|
||||
bool PCB_PARSER::parseBool()
|
||||
{
|
||||
T token = NextTok();
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <convert_to_biu.h> // IU_PER_MM
|
||||
#include <hashtables.h>
|
||||
#include <layers_id_colors_and_visibility.h> // PCB_LAYER_ID
|
||||
#include <math/util.h> // KiROUND, Clamp
|
||||
#include <pcb_lexer.h>
|
||||
|
||||
#include <unordered_map>
|
||||
|
@ -284,37 +283,9 @@ private:
|
|||
return parseDouble( GetTokenText( aToken ) );
|
||||
}
|
||||
|
||||
inline int parseBoardUnits()
|
||||
{
|
||||
// There should be no major rounding issues here, since the values in
|
||||
// the file are in mm and get converted to nano-meters.
|
||||
// See test program tools/test-nm-biu-to-ascii-mm-round-tripping.cpp
|
||||
// to confirm or experiment. Use a similar strategy in both places, here
|
||||
// and in the test program. Make that program with:
|
||||
// $ make test-nm-biu-to-ascii-mm-round-tripping
|
||||
auto retval = parseDouble() * IU_PER_MM;
|
||||
int parseBoardUnits();
|
||||
|
||||
// N.B. we currently represent board units as integers. Any values that are
|
||||
// larger or smaller than those board units represent undefined behavior for
|
||||
// the system. We limit values to the largest that is visible on the screen
|
||||
// This is the diagonal distance of the full screen ~1.5m
|
||||
double int_limit = std::numeric_limits<int>::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2)
|
||||
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
|
||||
}
|
||||
|
||||
inline int parseBoardUnits( const char* aExpected )
|
||||
{
|
||||
auto retval = parseDouble( aExpected ) * IU_PER_MM;
|
||||
|
||||
// N.B. we currently represent board units as integers. Any values that are
|
||||
// larger or smaller than those board units represent undefined behavior for
|
||||
// the system. We limit values to the largest that is visible on the screen
|
||||
double int_limit = std::numeric_limits<int>::max() * 0.7071;
|
||||
|
||||
// Use here #KiROUND, not EKIROUND (see comments about them) when having a function as
|
||||
// argument, because it will be called twice with #KIROUND.
|
||||
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
|
||||
}
|
||||
int parseBoardUnits( const char* aExpected );
|
||||
|
||||
inline int parseBoardUnits( PCB_KEYS_T::T aToken )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue