167 const bool realDepths = depths.size() >= 2;
168 const bool realThickness = realDepths && thicknesses.size() == depths.size();
170 const int lastOrdinal = innerLayers + 1;
173 auto shown = [](
const std::optional<bool>& aFlag )
175 return !aFlag.has_value() || *aFlag;
177 auto mixed = [](
const std::optional<bool>& aFlag )
179 return !aFlag.has_value();
184 auto copperThickness = [&](
int aOrdinal,
double aFallback )
189 return std::max( std::min( 4.0, aFallback ), boardHeight * thicknesses[aOrdinal] );
193 const double outerBottom =
OUTER_TOP + boardHeight;
195 const double coreBottom = outerBottom - copperThickness( lastOrdinal,
COPPER_THICKNESS );
207 auto boreHalf = [&](
double aRatio )
209 return std::clamp( holeHalf * aRatio, holeHalf + 2,
MAX_HALF_WIDTH );
215 for(
int ordinal = 0; ordinal <= lastOrdinal; ordinal++ )
221 else if( ordinal == lastOrdinal )
225 else if( realDepths )
227 double y = outerTop + boardHeight * depths[ordinal];
232 m_layerCentres.push_back( coreTop + ( coreBottom - coreTop ) * ordinal / ( innerLayers + 1 ) );
236 auto layerCentre = [&](
int aOrdinal )
241 double spacing = coreBottom - coreTop;
243 for(
int i = 0; i <= innerLayers; i++ )
244 spacing = std::min( spacing, layerCentre( i + 1 ) - layerCentre( i ) );
246 auto innerThickness = [&](
int aOrdinal )
248 return copperThickness( aOrdinal, std::clamp( spacing / 2, 1.0,
INNER_THICKNESS ) );
252 const int viaTopOrdinal = std::clamp( aState.
m_TopLayer, 0, lastOrdinal );
253 const int viaBottomOrdinal = std::clamp( aState.
m_BottomLayer.value_or( lastOrdinal ), viaTopOrdinal, lastOrdinal );
254 const bool reachesFront = viaTopOrdinal == 0;
255 const bool reachesBack = viaBottomOrdinal == lastOrdinal;
256 const double viaTop = reachesFront ? outerTop : layerCentre( viaTopOrdinal ) - innerThickness( viaTopOrdinal ) / 2;
257 const double viaBottom =
258 reachesBack ? outerBottom : layerCentre( viaBottomOrdinal ) + innerThickness( viaBottomOrdinal ) / 2;
260 auto hasRing = [&](
int aOrdinal )
263 return rings.size() != (size_t) lastOrdinal + 1 || rings[aOrdinal];
266 const bool throughVia = reachesFront && reachesBack;
267 const int frontRemoved = throughVia ? std::clamp( aState.
m_BackdrillFrontLayers.value_or( 0 ), 0, lastOrdinal ) : 0;
268 const int backRemoved = throughVia ? std::clamp( aState.
m_BackdrillBackLayers.value_or( 0 ), 0, lastOrdinal ) : 0;
270 const bool frontBored = frontRemoved > 0;
271 const bool backBored = backRemoved > 0;
274 const double frontOpenHalf = std::max( padHalf, frontBored ? frontBoreHalf : 0.0 ) +
MASK_CLEARANCE;
275 const double backOpenHalf = std::max( padHalf, backBored ? backBoreHalf : 0.0 ) +
MASK_CLEARANCE;
279 const bool frontOpen = reachesFront && !frontBored;
280 const bool backOpen = reachesBack && !backBored;
283 const bool filled = shown( aState.
m_Filled );
298 double depth = ( layerCentre( frontRemoved - 1 ) + layerCentre( frontRemoved ) ) / 2;
299 m_bores.push_back(
rect( centre - frontBoreHalf, coverTop, centre + frontBoreHalf, depth ) );
304 int last = innerLayers + 1 - backRemoved;
305 double depth = ( layerCentre( last ) + layerCentre( last + 1 ) ) / 2;
306 m_bores.push_back(
rect( centre - backBoreHalf, depth, centre + backBoreHalf, coverBottom ) );
313 auto postMachining = [&](
const POST_MACHINING& aCut,
bool aFront )
315 if( !aCut.
m_Mode.has_value() )
319 const double depth = std::clamp( boardHeight * aCut.
m_DepthFraction, 2.0, boardHeight - 2 );
320 const double surface = aFront ? outerTop : outerBottom;
321 const double edge = aFront ? coverTop - 2 : coverBottom + 2;
322 const double floor = aFront ? surface + depth : surface - depth;
328 rect( centre - halfWidth, std::min( edge, floor ), centre + halfWidth, std::max( edge, floor ) ) );
333 { centre + halfWidth, edge },
334 { centre + halfWidth, surface },
335 { centre + holeHalf, floor },
336 { centre - holeHalf, floor },
337 { centre - halfWidth, surface } } ) );
352 auto body = [&](
MATERIAL aMaterial,
CLIP aClip ) -> std::vector<PIECE>&
354 m_bodies.push_back( { aMaterial, aClip, {} } );
358 auto tentShape = [&](
bool aFront,
bool aMixed )
361 return rect( centre - frontOpenHalf, maskTop, centre + frontOpenHalf, outerTop, aMixed );
363 return rect( centre - backOpenHalf, outerBottom, centre + backOpenHalf, maskBottom, aMixed );
369 std::vector<PIECE>& mask = body( MATERIAL::SOLDER_MASK, CLIP::OVER_MASK );
373 mask.push_back(
rect(
BOARD_LEFT, maskTop, centre - frontOpenHalf, outerTop ) );
374 mask.push_back(
rect( centre + frontOpenHalf, maskTop,
BOARD_RIGHT, outerTop ) );
377 mask.push_back( tentShape(
true, mixed( aState.
m_TentFront ) ) );
386 mask.push_back(
rect(
BOARD_LEFT, outerBottom, centre - backOpenHalf, maskBottom ) );
387 mask.push_back(
rect( centre + backOpenHalf, outerBottom,
BOARD_RIGHT, maskBottom ) );
390 mask.push_back( tentShape(
false, mixed( aState.
m_TentBack ) ) );
399 std::vector<PIECE>& core = body( MATERIAL::CORE, CLIP::UNDER_MASK );
411 if( !reachesFront && !reachesBack && !filled )
417 auto plugShape = [&](
bool aFront,
bool aMixed )
419 const double mouth = aFront ? viaTop : viaBottom;
426 for(
int i = 1; i < 8; i++ )
429 double x = ( 1 - t ) * ( 1 - t ) *
HOLE_RIGHT + 2 * ( 1 - t ) * t * centre + t * t *
HOLE_LEFT;
430 double y = ( 1 - t ) * ( 1 - t ) * flat + 2 * ( 1 - t ) * t * tip + t * t * flat;
431 pts.push_back( { x, y } );
435 return polygon( std::move( pts ), aMixed );
439 std::vector<PIECE>& plug = body( MATERIAL::PLUG, CLIP::UNDER_MASK );
444 capped && backOpen ? coreBottom : viaBottom, mixed( aState.
m_Filled ) ) );
448 if( frontOpen && plugFront )
449 plug.push_back( plugShape(
true, mixed( aState.
m_PlugFront ) ) );
451 if( backOpen && plugBack )
452 plug.push_back( plugShape(
false, mixed( aState.
m_PlugBack ) ) );
459 std::vector<PIECE>& copper = body( MATERIAL::COPPER, CLIP::UNDER_MASK );
485 for(
int i = 1; i <= innerLayers; i++ )
487 double t = innerThickness( i );
488 double y = layerCentre( i ) - t / 2;
490 if( i < viaTopOrdinal || i > viaBottomOrdinal )
496 double gap = hasRing( i ) ? 0.0 :
RING_GAP;
515 auto coverShape = [&](
bool aFront,
bool aMixed )
525 coverBottom, aMixed );
530 std::vector<PIECE>& cover = body( MATERIAL::COVER, CLIP::OVER_MASK );
532 if( frontOpen && coverFront )
534 cover.push_back( coverShape(
true, mixed( aState.
m_CoverFront ) ) );
537 cover.push_back( tentShape(
true, mixed( aState.
m_CoverFront ) ) );
540 if( backOpen && coverBack )
542 cover.push_back( coverShape(
false, mixed( aState.
m_CoverBack ) ) );
545 cover.push_back( tentShape(
false, mixed( aState.
m_CoverBack ) ) );