Skip to content

Commit 4aa5b73

Browse files
committed
Zoom coordinates are now floating point values
I have added the possibility to use floating point values as zoom coordinates. This allows for much greater precision when trying to zoom at a specific phenomenon. File names do no longer suffer from excessive trailing zeros when performing pattern substitution.
1 parent 8a8258a commit 4aa5b73

File tree

10 files changed

+41
-30
lines changed

10 files changed

+41
-30
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ be changed.
382382
![Escape Time colorbars](https://crapp.github.io/geomandel/escape_colorbar_1band.png)
383383

384384
The next three colorbars were created with the same base color and the same frequency
385-
values for the green primary. Additionally I have added a frequency of 4 for the
386-
blue primary.
385+
values for the green channel. Additionally I have added a frequency of 4 for the
386+
blue channel.
387387

388388
![Escape Time colorbars two color components](https://crapp.github.io/geomandel/escape_colorbar_2band.png)
389389

src/buffwriter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Buffwriter::~Buffwriter() {}
2323
std::string Buffwriter::out_file_name(const std::string &string_pattern,
2424
unsigned int bailout, unsigned int xrange,
2525
unsigned int yrange, unsigned int zoom,
26-
unsigned int cores, unsigned int xcoord,
27-
unsigned int ycoord, double z_real_min,
26+
unsigned int cores, double xcoord,
27+
double ycoord, double z_real_min,
2828
double z_real_max, double z_ima_min,
2929
double z_ima_max)
3030
{
@@ -36,8 +36,8 @@ std::string Buffwriter::out_file_name(const std::string &string_pattern,
3636
regex_patterns.emplace_back(new Regexpattern<unsigned int>(yrange, "%h"));
3737
regex_patterns.emplace_back(new Regexpattern<unsigned int>(zoom, "%z"));
3838
regex_patterns.emplace_back(new Regexpattern<unsigned int>(cores, "%c"));
39-
regex_patterns.emplace_back(new Regexpattern<unsigned int>(xcoord, "%x"));
40-
regex_patterns.emplace_back(new Regexpattern<unsigned int>(ycoord, "%y"));
39+
regex_patterns.emplace_back(new Regexpattern<double>(xcoord, "%x"));
40+
regex_patterns.emplace_back(new Regexpattern<double>(ycoord, "%y"));
4141
regex_patterns.emplace_back(new Regexpattern<double>(z_real_min, "%Zr"));
4242
regex_patterns.emplace_back(new Regexpattern<double>(z_real_max, "%ZR"));
4343
regex_patterns.emplace_back(new Regexpattern<double>(z_ima_min, "%Zi"));

src/buffwriter.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121

2222
#include "global.h"
2323

24+
#include "mandelparams.h"
25+
2426
#include <string>
2527
#include <regex>
2628
#include <memory>
29+
#include <type_traits>
2730

2831
/**
2932
* @brief Simple interface to be able to use objects with different
@@ -43,15 +46,24 @@ struct Regexpattern : public RegexpatternIface {
4346
virtual ~Regexpattern(){};
4447

4548
/**
46-
* @brief Parse the filename string and replace every occurence of regpattern
49+
* @brief Parse the filename string and replace every occurence of regpattern
4750
* with value
4851
*
4952
* @param filename
5053
*/
5154
void parse_filename(std::string &filename)
5255
{
5356
std::regex re(this->regpattern);
54-
filename = std::regex_replace(filename, re, std::to_string(this->value));
57+
std::string val_string = std::to_string(this->value);
58+
if (std::is_same<double, T>::value) {
59+
val_string.erase(val_string.find_last_not_of('0') + 1,
60+
std::string::npos);
61+
// check if last char is a point
62+
if (val_string.back() == '.') {
63+
val_string = val_string.substr(0, val_string.size() - 1);
64+
}
65+
}
66+
filename = std::regex_replace(filename, re, val_string);
5567
}
5668

5769
private:
@@ -60,7 +72,7 @@ struct Regexpattern : public RegexpatternIface {
6072
};
6173

6274
/**
63-
* @brief Base class of all classes that write the mandelbrot buffer to a
75+
* @brief Base class of all classes that write the mandelbrot buffer to a
6476
* file/stream
6577
*/
6678
class Buffwriter
@@ -77,10 +89,9 @@ class Buffwriter
7789
std::string out_file_name(const std::string &string_pattern,
7890
unsigned int bailout, unsigned int xrange,
7991
unsigned int yrange, unsigned int zoom,
80-
unsigned int cores, unsigned int xcoord,
81-
unsigned int ycoord, double z_real_min,
82-
double z_real_max, double z_ima_min,
83-
double z_ima_max);
92+
unsigned int cores, double xcoord, double ycoord,
93+
double z_real_min, double z_real_max,
94+
double z_ima_min, double z_ima_max);
8495
};
8596

8697
#endif /* ifndef BUFFWRITER_H */

src/main_helper.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ inline void init_mandel_parameters(std::shared_ptr<MandelParameters> &params,
5353
unsigned int yrange = parser["h"].as<unsigned int>();
5454

5555
unsigned int zoomlvl = 0;
56-
unsigned int xcoord = 0;
57-
unsigned int ycoord = 0;
56+
double xcoord = 0;
57+
double ycoord = 0;
5858

5959
// check if user wants to zoom
6060
if (parser.count("zoom")) {
@@ -67,8 +67,8 @@ inline void init_mandel_parameters(std::shared_ptr<MandelParameters> &params,
6767
parser["zoom"].as<unsigned int>() == 0
6868
? zoomlvl = 1
6969
: zoomlvl = parser["zoom"].as<unsigned int>();
70-
xcoord = parser["xcoord"].as<unsigned int>();
71-
ycoord = parser["ycoord"].as<unsigned int>();
70+
xcoord = parser["xcoord"].as<double>();
71+
ycoord = parser["ycoord"].as<double>();
7272

7373
if (xcoord > xrange) {
7474
std::cerr << "X Coordinate outside of the image space"
@@ -161,9 +161,9 @@ inline void configure_command_line_parser(cxxopts::Options &p)
161161
("zoom", "Zoom level. Use together with xcoord, ycoord",
162162
cxxopts::value<unsigned int>())
163163
("xcoord", "Image X coordinate where you want to zoom into the fractal",
164-
cxxopts::value<unsigned int>())
164+
cxxopts::value<double>())
165165
("ycoord", "Image Y coordinate where you want to zoom into the fractal",
166-
cxxopts::value<unsigned int>());
166+
cxxopts::value<double>());
167167

168168
p.add_options("Export")
169169
("p,print", "Print Buffer to terminal")

src/mandelparams.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct MandelParameters {
3939
unsigned int bailout;
4040

4141
unsigned int zoom;
42-
unsigned int xcoord;
43-
unsigned int ycoord;
42+
double xcoord;
43+
double ycoord;
4444

4545
std::string image_base;
4646

@@ -52,7 +52,7 @@ struct MandelParameters {
5252
MandelParameters(unsigned int xrange, double xl, double xh,
5353
unsigned int yrange, double yl, double yh,
5454
unsigned int bailout, unsigned int zoom,
55-
unsigned int xcoord, unsigned int ycoord,
55+
double xcoord, double ycoord,
5656
std::string image_base, unsigned int cores,
5757
constants::COL_ALGO col_algo)
5858
: xrange(xrange),

src/mandelzoom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
Mandelzoom::Mandelzoom() {}
2222
void Mandelzoom::calcalute_zoom_cpane(double &xh, double &xl, double &yh,
2323
double &yl, unsigned int zoom,
24-
unsigned int xcoord, unsigned int ycoord,
24+
double xcoord, double ycoord,
2525
unsigned int width, unsigned int height)
2626
{
2727
/*

src/mandelzoom.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class Mandelzoom
4040
* @param ycoord Y coordinate in the complex plane
4141
*/
4242
void calcalute_zoom_cpane(double &xh, double &xl, double &yh, double &yl,
43-
unsigned int zoom, unsigned int xcoord,
44-
unsigned int ycoord, unsigned int width,
43+
unsigned int zoom, double xcoord,
44+
double ycoord, unsigned int width,
4545
unsigned int height);
4646

4747
private:

src/test/buffwriter_mock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void BuffwriterMock::write_buffer(){};
2828
std::string BuffwriterMock::test_filename_patterns(
2929
std::string filename_pattern, unsigned int bailout, unsigned int xrange,
3030
unsigned int yrange, unsigned int zoom, unsigned int cores,
31-
unsigned int xcoord, unsigned int ycoord, double z_real_min,
31+
double xcoord, double ycoord, double z_real_min,
3232
double z_real_max, double z_ima_min, double z_ima_max)
3333
{
3434
return this->out_file_name(filename_pattern, bailout, xrange, yrange, zoom,

src/test/buffwriter_mock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class BuffwriterMock : public Buffwriter
3131
std::string test_filename_patterns(std::string filename_pattern,
3232
unsigned int bailout, unsigned int xrange,
3333
unsigned int yrange, unsigned int zoom,
34-
unsigned int cores, unsigned int xcoord,
35-
unsigned int ycoord, double z_real_min,
34+
unsigned int cores, double xcoord,
35+
double ycoord, double z_real_min,
3636
double z_real_max, double z_ima_min,
3737
double z_ima_max);
3838

src/test/test_computation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ TEST_CASE("Computation of zoom values", "[computation]")
8080
// zoom level
8181
unsigned int zoom = 30;
8282
// x/y coordinate in the image space
83-
unsigned int xcoord = 200;
84-
unsigned int ycoord = 300;
83+
double xcoord = 200;
84+
double ycoord = 300;
8585

8686
SECTION("Test 30x zoom")
8787
{

0 commit comments

Comments
 (0)