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

Go to the source code of this file.

Macros

#define MM2MICRON   1e3
 
#define MM2NANOMETER   1e6
 
#define EE_LINE_THICKNESS   1
 

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

◆ EE_LINE_THICKNESS

#define EE_LINE_THICKNESS   1

◆ MM2MICRON

#define MM2MICRON   1e3

Definition at line 42 of file bitmap2component/bitmap2component.cpp.

◆ MM2NANOMETER

#define MM2NANOMETER   1e6

Definition at line 43 of file bitmap2component/bitmap2component.cpp.

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 513 of file bitmap2component/bitmap2component.cpp.

518 {
519  double dd0, dd1, dd, delta, e2, epsilon, t;
520 
521  // p1 = starting point
522 
523  /* we approximate the curve by small line segments. The interval
524  * size, epsilon, is determined on the fly so that the distance
525  * between the true curve and its approximation does not exceed the
526  * desired accuracy delta. */
527 
528  delta = 0.25; /* desired accuracy, in pixels */
529 
530  /* let dd = maximal value of 2nd derivative over curve - this must
531  * occur at an endpoint. */
532  dd0 = square( p1.x - 2 * p2.x + p3.x ) + square( p1.y - 2 * p2.y + p3.y );
533  dd1 = square( p2.x - 2 * p3.x + p4.x ) + square( p2.y - 2 * p3.y + p4.y );
534  dd = 6 * sqrt( std::max( dd0, dd1 ) );
535  e2 = 8 * delta <= dd ? 8 * delta / dd : 1;
536  epsilon = sqrt( e2 ); /* necessary interval size */
537 
538  for( t = epsilon; t<1; t += epsilon )
539  {
540  potrace_dpoint_t intermediate_point;
541  intermediate_point.x = p1.x * cube( 1 - t ) +
542  3* p2.x* square( 1 - t ) * t +
543  3 * p3.x * (1 - t) * square( t ) +
544  p4.x* cube( t );
545 
546  intermediate_point.y = p1.y * cube( 1 - t ) +
547  3* p2.y* square( 1 - t ) * t +
548  3 * p3.y * (1 - t) * square( t ) + p4.y* cube( t );
549 
550  aCornersBuffer.push_back( intermediate_point );
551  }
552 
553  aCornersBuffer.push_back( p4 );
554 }
double square(double x)
double cube(double x)

References cube(), and square().

Referenced by BITMAPCONV_INFO::createOutputData().

◆ bm_free()

static void bm_free ( potrace_bitmap_t *  bm)
static

Definition at line 46 of file bitmap2component/bitmap2component.cpp.

47 {
48  if( bm != NULL )
49  {
50  free( bm->map );
51  }
52  free( bm );
53 }
#define NULL

References NULL.

Referenced by BITMAPCONV_INFO::ConvertBitmap().

◆ cube()

double cube ( double  x)
inline

Definition at line 507 of file bitmap2component/bitmap2component.cpp.

508 {
509  return x*x*x;
510 }

Referenced by BezierToPolyline().

◆ square()

double square ( double  x)
inline

Definition at line 501 of file bitmap2component/bitmap2component.cpp.

502 {
503  return x*x;
504 }

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