#include #include #include #include #include #include #include "studio/geometry.h" #include "unreliableobjects.h" static void print_(void * const device, const char * const format, ...) { assert(format); va_list arguments = {0}; va_start(arguments, format); (void)output(device, format, arguments); va_end(arguments); } int bom(void * const output, const int choice) { const struct material { double length; double width; double weight; double price; char *description; char *source; } materials[] = { {1000.0, 15.0, 60.0, 0.95, "1mm PVC angle 15mm x 15mm x 1000mm", ""}, {1000.0, 15.0, 271.0, 3.69, "1.2mm mild steel angle 15mm x 15mm x 1000mm", ""}, {1000.0, 15.0, 640.0, 2.80, "3mm mild steel angle 15mm x 15mm x 1000mm", ""}, {2000.0, 50.0, 4600.0, 32.20, "3mm mild steel angle 50mm x 50mm x 2000mm", ""} }; if (choice < 1 || (size_t)choice > count(materials)) { for (size_t number = 0; number < count(materials); ++number) print_(output, "%lu: %s\n", number + 1, materials[number].description); return 0; } const struct material material = materials[choice - 1]; const double size = material.width * 100.0; const double proportion = 9.0 / 11.0; const double columns = 3.0; const double scale = size * proportion * (proportion / columns) * (1.0 - ((1.0 - proportion) / columns)); const double weight = material.weight / material.length; print_( output, "%s\n" "%.2fmm x %.2fmm %.2fg %.2fg/mm €%.2f\n" "%s\n" "\n" "display size = %.2f\n" "\n" "sides sections length angle total weight\n" "------------------------------------------------\n", material.description, material.length, material.width, material.weight, weight, material.price, material.source, size ); double total = 0.0; for (size_t sides = 1; sides <= 9; ++sides) { const double angle = 180.0 / (double)sides; const double cut = fmod(angle, 90.0); const double length = ( (sides > 1) ? sine(angle) * scale : material.width ) + ( tangent(cut) * material.width ); const size_t sections = (sides > 2) ? sides : 1; const double required = (double)sections * length; print_( output, " %lu %lu %7.2f %6.2f %8.2f%8.2f\n", sides, sections, length, cut, required, required * weight ); total += required; } const double quantity = ceil(total / material.length); print_( output, "------------------------------------------------\n" "total %8.2f\n" "weight %8.2f\n" "quantity (estimate) %8.0f\n" "cost %8.2f\n", total, total * weight, quantity, quantity * material.price ); return 1; }