KiCad PCB EDA Suite
bitmap2component.cpp File Reference
#include <algorithm>
#include <cerrno>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <convert_to_biu.h>
#include <layer_ids.h>
#include <locale_io.h>
#include <potracelib.h>
#include "bitmap2component.h"

Go to the source code of this file.

Macros

#define SCH_LINE_THICKNESS_MM   0.01
 

Functions

static void bm_free (potrace_bitmap_t *bm)
 
static void BezierToPolyline (std::vector< potrace_dpoint_t > &aCornersBuffer, potrace_dpoint_t p1, potrace_dpoint_t p2, potrace_dpoint_t p3, potrace_dpoint_t p4)
 
double square (double x)
 
double cube (double x)
 

Macro Definition Documentation

◆ SCH_LINE_THICKNESS_MM

#define SCH_LINE_THICKNESS_MM   0.01

Function Documentation

◆ BezierToPolyline()

void BezierToPolyline ( std::vector< potrace_dpoint_t > &  aCornersBuffer,
potrace_dpoint_t  p1,
potrace_dpoint_t  p2,
potrace_dpoint_t  p3,
potrace_dpoint_t  p4 
)
static

Definition at line 544 of file bitmap2component.cpp.

549 {
550  double dd0, dd1, dd, delta, e2, epsilon, t;
551 
552  // p1 = starting point
553 
554  /* we approximate the curve by small line segments. The interval
555  * size, epsilon, is determined on the fly so that the distance
556  * between the true curve and its approximation does not exceed the
557  * desired accuracy delta. */
558 
559  delta = 0.25; /* desired accuracy, in pixels */
560 
561  /* let dd = maximal value of 2nd derivative over curve - this must
562  * occur at an endpoint. */
563  dd0 = square( p1.x - 2 * p2.x + p3.x ) + square( p1.y - 2 * p2.y + p3.y );
564  dd1 = square( p2.x - 2 * p3.x + p4.x ) + square( p2.y - 2 * p3.y + p4.y );
565  dd = 6 * sqrt( std::max( dd0, dd1 ) );
566  e2 = 8 * delta <= dd ? 8 * delta / dd : 1;
567  epsilon = sqrt( e2 ); /* necessary interval size */
568 
569  for( t = epsilon; t<1; t += epsilon )
570  {
571  potrace_dpoint_t intermediate_point;
572  intermediate_point.x = p1.x * cube( 1 - t ) +
573  3* p2.x* square( 1 - t ) * t +
574  3 * p3.x * (1 - t) * square( t ) +
575  p4.x* cube( t );
576 
577  intermediate_point.y = p1.y * cube( 1 - t ) +
578  3* p2.y* square( 1 - t ) * t +
579  3 * p3.y * (1 - t) * square( t ) + p4.y* cube( t );
580 
581  aCornersBuffer.push_back( intermediate_point );
582  }
583 
584  aCornersBuffer.push_back( p4 );
585 }
double cube(double x)
constexpr int delta
double square(double x)

References cube(), delta, and square().

Referenced by BITMAPCONV_INFO::createOutputData().

◆ bm_free()

static void bm_free ( potrace_bitmap_t *  bm)
static

Definition at line 44 of file bitmap2component.cpp.

45 {
46  if( bm != nullptr )
47  {
48  free( bm->map );
49  }
50 
51  free( bm );
52 }

Referenced by BITMAPCONV_INFO::ConvertBitmap().

◆ cube()

double cube ( double  x)
inline

Definition at line 537 of file bitmap2component.cpp.

538 {
539  return x * x * x;
540 }

Referenced by BezierToPolyline().

◆ square()

double square ( double  x)
inline

Definition at line 530 of file bitmap2component.cpp.

531 {
532  return x * x;
533 }

Referenced by BezierToPolyline(), dummy(), KIGFX::dummy(), and mpLayer::GetColourSquare().