build: корректировка

main
Daniil (FilippovDY) 1 год назад
Родитель dc8c2fbab9
Сommit 5712ffea77

4
.gitignore поставляемый

@ -1,4 +0,0 @@
/bin
/obj
*.layout
*.depend

@ -1,47 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Lab01" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Lab01" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Lab01" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="doctest.h" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h" />
<Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Unit filename="unittest.cbp" />
<Unit filename="unittest.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>

@ -7082,7 +7082,7 @@ namespace detail {
#ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4007) // 'function' : must be 'attribute' - see issue #182 DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4007) // 'function' : must be 'attribute' - see issue #182
int main(int argc, char** argv) { return doctest::Context(argc, argv).run(); }
DOCTEST_MSVC_SUPPRESS_WARNING_POP DOCTEST_MSVC_SUPPRESS_WARNING_POP
#endif // DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #endif // DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN

@ -36,10 +36,3 @@ main()
show_histogram_svg(bins); show_histogram_svg(bins);
return 0; return 0;
} }

@ -1,66 +1,66 @@
#include <iostream> #include <iostream>
#include <vector>
#include "svg.h" #include "svg.h"
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 310;
const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20;
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
void void
svg_begin(double width, double height) { svg_begin(double width, double height)
{
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n"; std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
std::cout << "<svg "; std::cout << "<svg ";
std::cout << "width='" << width << "' "; std::cout << "width='" << width << "' ";
std::cout << "height='" << height << "' "; std::cout << "height='" << height << "' ";
std::cout << "viewBox='0 0 " << width << " " << height << "' "; std::cout << "viewBox='0 0 " << width << " " << height << "' ";
std::cout << "xmlns='http://www.w3.org/2000/svg'>\n"; std::cout << "xmlns='http://www.w3.org/2000/svg'>\n";
std::cout << "<line x1='10' y1='2' x2='" << width + 10 <<"' y2='2' stroke-dasharray = '10 10' stroke='black'/>\n";
} }
void void
svg_end() { svg_end(double top)
{
std::cout << "<line x1='10' y1='" << top << "' x2='" << IMAGE_WIDTH <<"' y2='" << top << "' stroke-dasharray = '10 10' stroke='black'/>\n";
std::cout << "</svg>\n"; std::cout << "</svg>\n";
} }
void void
svg_text(double left, double baseline, std::string text) { svg_text(double left, double baseline, std::string text)
{
std::cout << "<line x1='10' y1='" << baseline - TEXT_BASELINE << "' x2='10' y2='" << baseline <<"' stroke-dasharray = '10 10' stroke='black'/>\n";
std::cout << "<text x='" << left << "' y='"<< baseline << "' > " << text << " </text>"; std::cout << "<text x='" << left << "' y='"<< baseline << "' > " << text << " </text>";
} }
void svg_rect(double x, double y, double width, double height){ void svg_rect(double x, double y, double width, double height)
{
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << " ' stroke='black' fill='#33A220' ></rect>"; std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << " ' stroke='black' fill='#33A220' ></rect>";
std::cout << "<line x1='" << IMAGE_WIDTH <<"' y1='" << y << "' x2='" << IMAGE_WIDTH <<"' y2='" << y + height <<"' stroke-dasharray = '10 10' stroke='black'/>\n";
} }
void void show_histogram_svg(const std::vector<std::size_t>& bins) {
show_histogram_svg(const std::vector<std::size_t>& bins) { double max = 0, scale = 1;
int maxlen = IMAGE_WIDTH - TEXT_WIDTH;
const auto IMAGE_WIDTH = 400; for (auto el: bins)
const auto IMAGE_HEIGHT = 300; {
const auto TEXT_LEFT = 20; if (max < el)
const auto TEXT_BASELINE = 20; {
const auto TEXT_WIDTH = 50; max = el;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
const std::size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
double top = 0;
std::size_t maxbin=bins[0];
for (std::size_t i=0; i < bins.size(); i++){
if (maxbin < bins[i]){
maxbin=bins[i];
} }
} }
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
if (maxbin<=76){ double top = 5;
for (std::size_t i=0; i < bins.size(); i++) { scale = max * BLOCK_WIDTH / maxlen;
double bin_width = BLOCK_WIDTH * bins[i]; for (size_t bin : bins)
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i])); {
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); const double bin_width = BLOCK_WIDTH * bin;
top += BIN_HEIGHT; svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
} svg_rect(TEXT_WIDTH, top, bin_width / scale, BIN_HEIGHT);
svg_end();
} else {
for (std::size_t i=0; i < bins.size(); i++) {
double bin_width= MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT; top += BIN_HEIGHT;
} }
svg_end(); svg_end(top);
}
} }

@ -31,10 +31,11 @@
<Compiler> <Compiler>
<Add option="-Wall" /> <Add option="-Wall" />
</Compiler> </Compiler>
<Unit filename="doctest.h" />
<Unit filename="histogram.cpp" /> <Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h" /> <Unit filename="histogram_internal.h" />
<Unit filename="unittest.cpp" /> <Unit filename="unittest.cpp" />
<Extensions /> <Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project> </Project>
</CodeBlocks_project_file> </CodeBlocks_project_file>

Загрузка…
Отмена
Сохранить