Skip to content

Commit

Permalink
Refactor cadence_fp (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwheeler authored Jun 24, 2024
1 parent 742f2ae commit 4862ca5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/brd_gui/brdview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void BrdView::mouseReleaseEvent(QMouseEvent *event) {

void BrdView::drawX01(const T01ArcSegment<kAMax> *inst, QPainterPath *path) {
std::pair<int32_t, int32_t> center = x01_center(inst);
double r = cfp_to_double(inst->r);
double r = static_cast<double>(inst->r);

/*
scene->addEllipse(
Expand Down
3 changes: 2 additions & 1 deletion src/lib/printing/printers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ void print_x01(const void *untyped_inst, File<version> *fs, const int d) {
" center=\x1b[2m(%.0f, %.0f)\x1b[0m"
" r=%.0f width=%d\n",
inst->bbox[0], inst->bbox[1], inst->bbox[2], inst->bbox[3],
center.first, center.second, cfp_to_double(inst->r), inst->width);
center.first, center.second, static_cast<double>(inst->r),
inst->width);

printf_d(d + 1, "next:\n");
if (fs->is_type(inst->next, 0x34)) {
Expand Down
6 changes: 2 additions & 4 deletions src/lib/structure/cadence_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
#include <cstdint>
#include <cstring>

auto cfp_to_double(CadenceDouble r) -> double {
CadenceDouble swapped;
swapped.x = r.y;
swapped.y = r.x;
CadenceDouble::operator double() const {
CadenceDouble swapped(this->y, this->x);
double g;
std::memcpy(&g, &swapped, 8);
return g;
Expand Down
10 changes: 6 additions & 4 deletions src/lib/structure/cadence_fp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
* swap them.
*/
struct CadenceDouble {
uint32_t x;
uint32_t y;
};
uint32_t x{};
uint32_t y{};

auto cfp_to_double(CadenceDouble r) -> double;
CadenceDouble() = default;
CadenceDouble(uint32_t x, uint32_t y) : x(x), y(y) {}
explicit operator double() const;
};

#endif
2 changes: 1 addition & 1 deletion src/lib/structure/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

template <>
T01ArcSegment<kA160>::operator T01ArcSegment<kAMax>() const {
T01ArcSegment<kAMax> new_inst;
T01ArcSegment<kAMax> new_inst{};
new_inst.t = this->t;
new_inst.un0 = this->un0;
new_inst.subtype = this->subtype;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/structure/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <algorithm>

auto x01_center(const T01ArcSegment<kAMax>* inst) -> std::pair<double, double> {
return {cfp_to_double(inst->x), cfp_to_double(inst->y)};
return {static_cast<double>(inst->x), static_cast<double>(inst->y)};
}

auto ordered_stackup_materials(File<kAMax>& f)
Expand Down

0 comments on commit 4862ca5

Please sign in to comment.