Сравнить коммиты
6 Коммитов
d7fa671218
...
07c73e5335
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 07c73e5335 | |||
| 86617483be | |||
| 2416376b8b | |||
| 48636765b8 | |||
| c03705d9e6 | |||
| 4d5e66cf96 |
@@ -1,10 +1,13 @@
|
|||||||
|
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "histogram_internal.h"
|
#include "histogram_internal.h"
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void find_minmax(const vector<double>& numbers, double& min, double& max) {
|
bool find_minmax(const vector<double>& numbers, double& min, double& max) {
|
||||||
|
if (numbers.empty())
|
||||||
|
return false;
|
||||||
min = numbers[0];
|
min = numbers[0];
|
||||||
max = numbers[0];
|
max = numbers[0];
|
||||||
for (double x : numbers) {
|
for (double x : numbers) {
|
||||||
@@ -13,6 +16,7 @@ void find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|||||||
if (x > max)
|
if (x > max)
|
||||||
max = x;
|
max = x;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
||||||
@@ -23,7 +27,6 @@ vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
|||||||
|
|
||||||
for (size_t i = 0; i < numbers.size(); i++) {
|
for (size_t i = 0; i < numbers.size(); i++) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (size_t j = 0; j < bin_count - 1 && !found; j++) {
|
for (size_t j = 0; j < bin_count - 1 && !found; j++) {
|
||||||
double lo = min + j * bin_size;
|
double lo = min + j * bin_size;
|
||||||
double hi = min + (j + 1) * bin_size;
|
double hi = min + (j + 1) * bin_size;
|
||||||
@@ -32,9 +35,15 @@ vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
|||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
bins[bin_count - 1]++;
|
bins[bin_count - 1]++;
|
||||||
}
|
}
|
||||||
return bins;
|
return bins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double compute_bin_size(const std::vector<double>& numbers, size_t bin_count) {
|
||||||
|
double min, max;
|
||||||
|
if (!find_minmax(numbers, min, max))
|
||||||
|
return 0.0;
|
||||||
|
return (max - min) / bin_count;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,3 +2,5 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
||||||
|
double compute_bin_size(const std::vector<double>& numbers, size_t bin_count);
|
||||||
|
void show_histogram_svg(const std::vector<size_t>& bins, double bin_size, double min_val);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void find_minmax(const std::vector<double>& numbers,
|
bool find_minmax(const std::vector<double>& numbers, double& min, double& max);
|
||||||
double& min,
|
|
||||||
double& max);
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
|
#include "histogram_internal.h"
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
struct Input {
|
struct Input {
|
||||||
vector<double> numbers;
|
vector<double> numbers;
|
||||||
size_t bin_count{};
|
size_t bin_count{};
|
||||||
@@ -31,14 +31,17 @@ Input input_data() {
|
|||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
auto in = input_data();
|
auto in = input_data();
|
||||||
|
|
||||||
|
double min_val, max_val;
|
||||||
|
find_minmax(in.numbers, min_val, max_val);
|
||||||
|
|
||||||
|
double bin_size = compute_bin_size(in.numbers, in.bin_count);
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
show_histogram_svg(bins);
|
|
||||||
|
show_histogram_svg(bins, bin_size, min_val);
|
||||||
|
|
||||||
show_histogram_text(bins);
|
show_histogram_text(bins);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
147
laba01upd3.vcxproj
Обычный файл
147
laba01upd3.vcxproj
Обычный файл
@@ -0,0 +1,147 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{7aea3de0-791a-40df-b555-ed559221baa2}</ProjectGuid>
|
||||||
|
<RootNamespace>laba01upd3</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="histogram.cpp" />
|
||||||
|
<ClCompile Include="laba01upd3.cpp" />
|
||||||
|
<ClCompile Include="svg.cpp" />
|
||||||
|
<ClCompile Include="text.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include=".gitignore" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="histogram.h" />
|
||||||
|
<ClInclude Include="histogram_internal.h" />
|
||||||
|
<ClInclude Include="svg.h" />
|
||||||
|
<ClInclude Include="text.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
48
laba01upd3.vcxproj.filters
Обычный файл
48
laba01upd3.vcxproj.filters
Обычный файл
@@ -0,0 +1,48 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Исходные файлы">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Файлы заголовков">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Файлы ресурсов">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="laba01upd3.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="histogram.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="text.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="svg.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include=".gitignore" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="histogram.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="text.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="histogram_internal.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="svg.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
48
svg.cpp
48
svg.cpp
@@ -1,19 +1,20 @@
|
|||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void svg_begin(double width, double height) {
|
void svg_begin(double width, double height) {
|
||||||
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||||
cout << "<svg ";
|
cout << "<svg "
|
||||||
cout << "width='" << width << "' ";
|
<< "width='" << width << "' "
|
||||||
cout << "height='" << height << "' ";
|
<< "height='" << height << "' "
|
||||||
cout << "viewBox='0 0 " << width << " " << height << "' ";
|
<< "viewBox='0 0 " << width << " " << height << "' "
|
||||||
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
<< "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void svg_end() {
|
void svg_end() {
|
||||||
cout << "</svg>\n";
|
cout << "</svg>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void svg_text(double left, double baseline, const string& text) {
|
void svg_text(double left, double baseline, const string& text) {
|
||||||
cout << "<text x='" << left
|
cout << "<text x='" << left
|
||||||
<< "' y='" << baseline
|
<< "' y='" << baseline
|
||||||
@@ -31,38 +32,41 @@ void svg_rect(double x, double y, double width, double height,
|
|||||||
<< "' fill='" << fill
|
<< "' fill='" << fill
|
||||||
<< "' />\n";
|
<< "' />\n";
|
||||||
}
|
}
|
||||||
void show_histogram_svg(const vector<size_t>& bins) {
|
|
||||||
|
void show_histogram_svg(const std::vector<size_t>& bins, double bin_size, double min_val) {
|
||||||
const double IMAGE_WIDTH = 400;
|
const double IMAGE_WIDTH = 400;
|
||||||
const double IMAGE_HEIGHT = 300;
|
const double IMAGE_HEIGHT = 300;
|
||||||
const double TEXT_LEFT = 20;
|
const double TEXT_LEFT = 20;
|
||||||
const double TEXT_BASELINE = 20;
|
const double TEXT_BASELINE = 20;
|
||||||
const double TEXT_WIDTH = 50;
|
const double TEXT_WIDTH = 50;
|
||||||
const double BIN_HEIGHT = 30;
|
const double BIN_HEIGHT = 30;
|
||||||
const double BLOCK_WIDTH = 10;
|
const double VSPACE = BIN_HEIGHT + TEXT_BASELINE * 2 + 5;
|
||||||
|
|
||||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||||
|
|
||||||
size_t max_count = 0;
|
size_t max_count = 0;
|
||||||
for (size_t count : bins) {
|
for (size_t c : bins)
|
||||||
if (count > max_count) {
|
if (c > max_count)
|
||||||
max_count = count;
|
max_count = c;
|
||||||
}
|
double max_width = IMAGE_WIDTH - TEXT_WIDTH - 100;
|
||||||
}
|
|
||||||
|
|
||||||
double max_width = IMAGE_WIDTH - TEXT_WIDTH;
|
for (size_t j = 0; j < bins.size(); ++j) {
|
||||||
double top = 0;
|
size_t count = bins[j];
|
||||||
for (size_t count : bins) {
|
double y = j * VSPACE;
|
||||||
double bin_width;
|
|
||||||
|
double width;
|
||||||
if (max_count > 0) {
|
if (max_count > 0) {
|
||||||
bin_width = static_cast<double>(count) / max_count * max_width;
|
width = static_cast<double>(count) / max_count * max_width;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bin_width = 0.0;
|
width = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(count));
|
svg_text(TEXT_LEFT, y + TEXT_BASELINE, to_string(count));
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "blue");
|
svg_rect(TEXT_WIDTH, y, width, BIN_HEIGHT, "blue", "blue");
|
||||||
top += BIN_HEIGHT;
|
double boundary = min_val + bin_size * (j + 1);
|
||||||
|
svg_text(TEXT_WIDTH,y + BIN_HEIGHT + TEXT_BASELINE,to_string(boundary)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
svg_end();
|
svg_end();
|
||||||
|
|||||||
2
svg.h
2
svg.h
@@ -9,4 +9,4 @@ void svg_text(double left, double baseline, const std::string& text);
|
|||||||
void svg_rect(double x, double y, double width, double height,
|
void svg_rect(double x, double y, double width, double height,
|
||||||
const std::string& stroke = "black",
|
const std::string& stroke = "black",
|
||||||
const std::string& fill = "black");
|
const std::string& fill = "black");
|
||||||
void show_histogram_svg(const std::vector<size_t>& bins);
|
void show_histogram_svg(const std::vector<size_t>& bins, double bin_size, double min_val);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void find_minmax(const std::vector<double>& numbers,
|
bool find_minmax(const std::vector<double>& numbers,
|
||||||
double& min,
|
double& min,
|
||||||
double& max);
|
double& max);
|
||||||
|
|||||||
@@ -10,10 +10,9 @@ TEST_CASE("distinct positive numbers") {
|
|||||||
CHECK(max == 2);
|
CHECK(max == 2);
|
||||||
}
|
}
|
||||||
TEST_CASE("empty vector") {
|
TEST_CASE("empty vector") {
|
||||||
double min = 42, max = 42;
|
double min = 0, max = 0;
|
||||||
find_minmax({}, min, max);
|
CHECK(!find_minmax({}, min, max));
|
||||||
CHECK(min == 42);
|
|
||||||
CHECK(max == 42);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("single element") {
|
TEST_CASE("single element") {
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="Файлы заголовков">
|
|
||||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
|
||||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Файлы ресурсов">
|
<Filter Include="Файлы ресурсов">
|
||||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Исходные файлы\Файлы заголовков">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\histogram.cpp">
|
<ClCompile Include="..\histogram.cpp">
|
||||||
@@ -24,13 +24,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\histogram_internal.h">
|
<ClInclude Include="..\histogram_internal.h">
|
||||||
<Filter>Файлы заголовков</Filter>
|
<Filter>Исходные файлы\Файлы заголовков</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\doctest.h">
|
<ClInclude Include="..\doctest.h">
|
||||||
<Filter>Файлы заголовков</Filter>
|
<Filter>Исходные файлы\Файлы заголовков</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\histogram.h">
|
<ClInclude Include="..\histogram.h">
|
||||||
<Filter>Файлы заголовков</Filter>
|
<Filter>Исходные файлы\Файлы заголовков</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Ссылка в новой задаче
Block a user