Сравнить коммиты

...

Ничего общего в коммитах. 'main' и '77077881ed00cef276ff234759272ff7b59434da' имеют совершенно разные истории.

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

@ -4,4 +4,3 @@
/lab01.layout /lab01.layout
/unittest.depend /unittest.depend
/unittest.layout /unittest.layout
/curl

@ -5724,7 +5724,7 @@ namespace {
std::tm timeInfo; std::tm timeInfo;
#ifdef DOCTEST_PLATFORM_WINDOWS #ifdef DOCTEST_PLATFORM_WINDOWS
// gmtime_s(&timeInfo, &rawtime); gmtime_s(&timeInfo, &rawtime);
#else // DOCTEST_PLATFORM_WINDOWS #else // DOCTEST_PLATFORM_WINDOWS
gmtime_r(&rawtime, &timeInfo); gmtime_r(&rawtime, &timeInfo);
#endif // DOCTEST_PLATFORM_WINDOWS #endif // DOCTEST_PLATFORM_WINDOWS

@ -13,12 +13,7 @@
<Option compiler="gcc" /> <Option compiler="gcc" />
<Compiler> <Compiler>
<Add option="-g" /> <Add option="-g" />
<Add directory="C:/Users/al/Desktop/cs-lab34/curl/include" />
</Compiler> </Compiler>
<Linker>
<Add library="libcurl.dll.a" />
<Add directory="C:/Users/al/Desktop/cs-lab34/curl/lib" />
</Linker>
</Target> </Target>
<Target title="Release"> <Target title="Release">
<Option output="bin/Release/lab01" prefix_auto="1" extension_auto="1" /> <Option output="bin/Release/lab01" prefix_auto="1" extension_auto="1" />
@ -46,10 +41,6 @@
<Option target="&lt;{~None~}&gt;" /> <Option target="&lt;{~None~}&gt;" />
</Unit> </Unit>
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="text.cpp" /> <Unit filename="text.cpp" />
<Unit filename="text.h"> <Unit filename="text.h">
<Option target="&lt;{~None~}&gt;" /> <Option target="&lt;{~None~}&gt;" />

@ -2,28 +2,19 @@
#include <vector> #include <vector>
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h"
#include <string>
#include <curl/curl.h>
#include <sstream>
using namespace std; using namespace std;
struct Input { struct Input {
vector<double> numbers; vector<double> numbers;
size_t bin_count{}; size_t bin_count{};
string stroke;
string fill;
}; };
Input Input
input_data(istream& Newcin, bool prompt){ input_data() {
size_t number_count; size_t number_count;
cerr << "Enter number count: "; cerr << "Enter number count: ";
cin >> number_count; cin >> number_count;
if (prompt){
cerr << "Prompt" << endl;
}
Input in; Input in;
in.numbers.resize(number_count); in.numbers.resize(number_count);
cerr << "Enter numbers: "; cerr << "Enter numbers: ";
@ -32,46 +23,12 @@ input_data(istream& Newcin, bool prompt){
} }
cerr << "Enter bin count: "; cerr << "Enter bin count: ";
cin >> in.bin_count; cin >> in.bin_count;
cerr << "Enter stroke in format RGB: ";
cin >> in.stroke;
cerr << "Enter fill in format RGB: ";
cin >> in.fill;
return in; return in;
} }
Input
download(const string& address) {
curl_global_init(CURL_GLOBAL_ALL);
stringstream buffer;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, address);
res = curl_easy_perform(curl);
if (res != 0){
cout << curl_easy_strerror(res);
exit(1);
}
}
curl_easy_cleanup(curl);
return input_data(buffer, false);
}
size_t
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
return 0;
}
int int
main(int argc, char* argv[]) { main() {
Input input; auto in = input_data();
if (argc > 1) { auto bins = make_histogram(in.numbers, in.bin_count);
input = download(argv[1]); show_histogram_text(bins);
} else {
input = input_data(cin, true);
}
const auto bins = make_histogram(input.numbers, input.bin_count);
show_histogram_svg(bins);
} }

@ -1,66 +0,0 @@
#include "svg.h"
using namespace std;
void
svg_begin(double width, double height) {
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
cout << "<svg ";
cout << "width='" << width << "' ";
cout << "height='" << height << "' ";
cout << "viewBox='0 0 " << width << " " << height << "' ";
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
}
void
svg_end() {
cout << "</svg>\n";
}
void
svg_text(double left, double baseline, string text) {
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
}
void
svg_rect(double x, double y, double width, double height, string stroke, string fill){
cout << "<rect x='" << x << "' y='" << y <<"' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "'/>";
}
void
show_histogram_svg(const vector<size_t>& bins) {
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
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;
svg_begin(400, 300);
double top = 0;
size_t maxbin = 0;
for (size_t bin : bins){
if (bin > maxbin){
maxbin = bin;
}
}
if (maxbin * BLOCK_WIDTH <= IMAGE_WIDTH - TEXT_WIDTH){
for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;
}
svg_end();
}
else{
float kf = static_cast<double>(IMAGE_WIDTH - TEXT_WIDTH) / (maxbin * BLOCK_WIDTH);
for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin * kf;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;
}
svg_end();
}
}

15
svg.h

@ -1,15 +0,0 @@
#pragma once
#include <iostream>
#include <vector>
#include <string>
void
svg_begin(double width, double height);
void
svg_end();
void
svg_text(double left, double baseline, std::string text);
void
svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black");
void
show_histogram_svg(const std::vector<size_t>& bins);

@ -43,3 +43,4 @@ TEST_CASE("same elements vector"){
CHECK(max == 8); CHECK(max == 8);
} }

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