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

..

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

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

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

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

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

@ -2,19 +2,28 @@
#include <vector>
#include "histogram.h"
#include "text.h"
#include "svg.h"
#include <string>
#include <curl/curl.h>
#include <sstream>
using namespace std;
struct Input {
vector<double> numbers;
size_t bin_count{};
string stroke;
string fill;
};
Input
input_data() {
input_data(istream& Newcin, bool prompt){
size_t number_count;
cerr << "Enter number count: ";
cin >> number_count;
if (prompt){
cerr << "Prompt" << endl;
}
Input in;
in.numbers.resize(number_count);
cerr << "Enter numbers: ";
@ -23,12 +32,46 @@ input_data() {
}
cerr << "Enter 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;
}
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
main() {
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins);
main(int argc, char* argv[]) {
Input input;
if (argc > 1) {
input = download(argv[1]);
} else {
input = input_data(cin, true);
}
const auto bins = make_histogram(input.numbers, input.bin_count);
show_histogram_svg(bins);
}

@ -0,0 +1,66 @@
#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

@ -0,0 +1,15 @@
#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,4 +43,3 @@ TEST_CASE("same elements vector"){
CHECK(max == 8);
}

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