TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
style.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Style metric (doc 05 §39.2): how tidy a set of tracks is, per connection and per board. It only measures; no
4// pass optimises it. Everything is counted in integers (nm, cross and dot products), so the numbers are the same
5// on every machine and at every thread count.
6//
7// The patterns follow what layout reviewers flag by eye; tscircuit's pcb-trace-linter (segments off the 45 degree
8// directions) and check-ugly-traces (removable jogs) were read for which patterns to count. No code of theirs is
9// used.
10#include <vector>
11
12#include <nlohmann/json.hpp>
13
14#include "model/board.hpp"
15
16namespace tmk::passes {
17
19 // A stair-step is a run of at least `stair_min_segments` consecutive segments on one layer, each shorter than
20 // `stair_widths` track widths, whose bends turn alternately left and right.
21 int stair_widths = 4;
23 // A connection is a long detour when its copper is longer than this many per cent of the shortest octilinear
24 // path between its ends.
25 int long_detour_pc = 150;
26};
27
28// One connection: copper of one net from one end to the next. An end is a pad of the net, a junction (three or
29// more track ends, or a track end on the middle of another track) or a loose end; a via with exactly two track
30// ends is passed through.
33 model::Point a, b; // the two ends
34 int layer_a = -1, layer_b = -1;
35 int segments = 0; // after joining collinear pieces
36 int bends = 0; // direction changes between consecutive segments on one layer
37 int acute = 0; // bends sharper than 90 degrees (the two segments enclose less than 90 degrees)
38 int stair_steps = 0; // runs, see StyleOptions
39 int short_segments = 0; // segments shorter than their own width
40 int off_angle = 0; // segments more than 0.1 degree off the eight octilinear directions
41 int arcs = 0; // arc tracks (not judged for bends or angles)
42 int vias = 0; // layer changes passed through
43 Coord length = 0; // nm, each piece rounded to the nanometre
44 Coord octile = 0; // shortest octilinear distance between the ends, nm (0 for a closed loop)
45};
46
48 std::vector<ConnectionStyle> connections; // sorted by net, then end points
49 int segments = 0, bends = 0, acute = 0, stair_steps = 0, short_segments = 0, off_angle = 0, arcs = 0, vias = 0;
50 int long_detours = 0;
52 Coord detour_length = 0, detour_octile = 0; // summed over the connections with distinct ends
53 double bends_per_connection() const { return connections.empty() ? 0.0 : static_cast<double>(bends) / static_cast<double>(connections.size()); }
54 double detour_ratio() const { return detour_octile > 0 ? static_cast<double>(detour_length) / static_cast<double>(detour_octile) : 1.0; }
55};
56
57// Measures `tracks`, `arcs` and `vias` (any subset of a board's copper, e.g. only what a run added). `b` supplies
58// the pads that end connections. The result does not depend on the order of the three lists.
59StyleReport measure_style(const model::Board& b, const std::vector<model::Track>& tracks, const std::vector<model::ArcTrack>& arcs,
60 const std::vector<model::Via>& vias, const StyleOptions& opt = {});
61
62// The `style` object of the route summary and of `tracemaker style --json`. `per_connection` adds one row per
63// connection.
64nlohmann::json style_json(const model::Board& b, const StyleReport& r, bool per_connection = false);
65
66} // namespace tmk::passes
The board model (design doc 02 §3): every object TraceMaker reads from a .kicad_pcb,...
std::int32_t NetId
0 = no net
Definition board.hpp:21
nlohmann::json style_json(const model::Board &b, const StyleReport &r, bool per_connection=false)
The style object of the route summary and of tracemaker style --json.
StyleReport measure_style(const model::Board &b, const std::vector< model::Track > &tracks, const std::vector< model::ArcTrack > &arcs, const std::vector< model::Via > &vias, const StyleOptions &opt={})
Measures tracks, arcs and vias (any subset of a board's copper, e.g.
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Definition units.hpp:12
One connection: copper of one net from one end to the next.
Definition style.hpp:31
int arcs
arc tracks (not judged for bends or angles)
Definition style.hpp:41
int stair_steps
runs, see StyleOptions
Definition style.hpp:38
model::Point b
the two ends
Definition style.hpp:33
Coord length
nm, each piece rounded to the nanometre
Definition style.hpp:43
Coord octile
shortest octilinear distance between the ends, nm (0 for a closed loop)
Definition style.hpp:44
int short_segments
segments shorter than their own width
Definition style.hpp:39
int off_angle
segments more than 0.1 degree off the eight octilinear directions
Definition style.hpp:40
int bends
direction changes between consecutive segments on one layer
Definition style.hpp:36
int acute
bends sharper than 90 degrees (the two segments enclose less than 90 degrees)
Definition style.hpp:37
int vias
layer changes passed through
Definition style.hpp:42
int segments
after joining collinear pieces
Definition style.hpp:35
int long_detour_pc
A connection is a long detour when its copper is longer than this many per cent of the shortest octil...
Definition style.hpp:25
int stair_widths
A stair-step is a run of at least stair_min_segments consecutive segments on one layer,...
Definition style.hpp:21
double detour_ratio() const
Definition style.hpp:54
std::vector< ConnectionStyle > connections
sorted by net, then end points
Definition style.hpp:48
Coord detour_octile
summed over the connections with distinct ends
Definition style.hpp:52
double bends_per_connection() const
Definition style.hpp:53