1 #include "hash.hpp" 2 #include "pool/padstack.hpp" 3 4 namespace horizon { GerberHash()5GerberHash::GerberHash() : checksum(Glib::Checksum::CHECKSUM_SHA256) 6 { 7 } update(const Padstack & ps)8void GerberHash::update(const Padstack &ps) 9 { 10 for (const auto &it : ps.holes) { 11 update(it.second); 12 } 13 for (const auto &it : ps.shapes) { 14 update(it.second); 15 } 16 for (const auto &it : ps.polygons) { 17 update(it.second); 18 } 19 } 20 get_digest()21std::string GerberHash::get_digest() 22 { 23 return checksum.get_string(); 24 } 25 hash(const Padstack & ps)26std::string GerberHash::hash(const Padstack &ps) 27 { 28 GerberHash h; 29 h.update(ps); 30 return h.get_digest(); 31 } 32 update(const Hole & h)33void GerberHash::update(const Hole &h) 34 { 35 update(h.diameter); 36 update(static_cast<int>(h.shape)); 37 if (h.shape == Hole::Shape::SLOT) { 38 update(h.length); 39 } 40 update(h.plated); 41 update(h.placement); 42 } 43 update(const Shape & s)44void GerberHash::update(const Shape &s) 45 { 46 update(static_cast<int>(s.form)); 47 update(s.placement); 48 update(s.layer); 49 for (const auto it : s.params) { 50 update(it); 51 } 52 } 53 update(const Polygon & p)54void GerberHash::update(const Polygon &p) 55 { 56 update(p.layer); 57 for (const auto &it : p.vertices) { 58 update(it.position); 59 update(static_cast<int>(it.type)); 60 if (it.type == Polygon::Vertex::Type::ARC) 61 update(it.arc_center); 62 } 63 } 64 update(int64_t i)65void GerberHash::update(int64_t i) 66 { 67 checksum.update(reinterpret_cast<const guchar *>(&i), sizeof(i)); 68 } 69 update(const Coordi & c)70void GerberHash::update(const Coordi &c) 71 { 72 update(c.x); 73 update(c.y); 74 } 75 update(const Placement & p)76void GerberHash::update(const Placement &p) 77 { 78 update(p.shift); 79 update(p.get_angle()); 80 update(p.mirror); 81 } 82 } // namespace horizon 83