Skip to content

Commit

Permalink
Zoom coordinates are now floating point values
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crapp committed Mar 23, 2016
1 parent 8a8258a commit 4aa5b73
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ be changed.
![Escape Time colorbars](https://crapp.github.io/geomandel/escape_colorbar_1band.png)

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

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

Expand Down
8 changes: 4 additions & 4 deletions src/buffwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Buffwriter::~Buffwriter() {}
std::string Buffwriter::out_file_name(const std::string &string_pattern,
unsigned int bailout, unsigned int xrange,
unsigned int yrange, unsigned int zoom,
unsigned int cores, unsigned int xcoord,
unsigned int ycoord, double z_real_min,
unsigned int cores, double xcoord,
double ycoord, double z_real_min,
double z_real_max, double z_ima_min,
double z_ima_max)
{
Expand All @@ -36,8 +36,8 @@ std::string Buffwriter::out_file_name(const std::string &string_pattern,
regex_patterns.emplace_back(new Regexpattern<unsigned int>(yrange, "%h"));
regex_patterns.emplace_back(new Regexpattern<unsigned int>(zoom, "%z"));
regex_patterns.emplace_back(new Regexpattern<unsigned int>(cores, "%c"));
regex_patterns.emplace_back(new Regexpattern<unsigned int>(xcoord, "%x"));
regex_patterns.emplace_back(new Regexpattern<unsigned int>(ycoord, "%y"));
regex_patterns.emplace_back(new Regexpattern<double>(xcoord, "%x"));
regex_patterns.emplace_back(new Regexpattern<double>(ycoord, "%y"));
regex_patterns.emplace_back(new Regexpattern<double>(z_real_min, "%Zr"));
regex_patterns.emplace_back(new Regexpattern<double>(z_real_max, "%ZR"));
regex_patterns.emplace_back(new Regexpattern<double>(z_ima_min, "%Zi"));
Expand Down
25 changes: 18 additions & 7 deletions src/buffwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "global.h"

#include "mandelparams.h"

#include <string>
#include <regex>
#include <memory>
#include <type_traits>

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

/**
* @brief Parse the filename string and replace every occurence of regpattern
* @brief Parse the filename string and replace every occurence of regpattern
* with value
*
* @param filename
*/
void parse_filename(std::string &filename)
{
std::regex re(this->regpattern);
filename = std::regex_replace(filename, re, std::to_string(this->value));
std::string val_string = std::to_string(this->value);
if (std::is_same<double, T>::value) {
val_string.erase(val_string.find_last_not_of('0') + 1,
std::string::npos);
// check if last char is a point
if (val_string.back() == '.') {
val_string = val_string.substr(0, val_string.size() - 1);
}
}
filename = std::regex_replace(filename, re, val_string);
}

private:
Expand All @@ -60,7 +72,7 @@ struct Regexpattern : public RegexpatternIface {
};

/**
* @brief Base class of all classes that write the mandelbrot buffer to a
* @brief Base class of all classes that write the mandelbrot buffer to a
* file/stream
*/
class Buffwriter
Expand All @@ -77,10 +89,9 @@ class Buffwriter
std::string out_file_name(const std::string &string_pattern,
unsigned int bailout, unsigned int xrange,
unsigned int yrange, unsigned int zoom,
unsigned int cores, unsigned int xcoord,
unsigned int ycoord, double z_real_min,
double z_real_max, double z_ima_min,
double z_ima_max);
unsigned int cores, double xcoord, double ycoord,
double z_real_min, double z_real_max,
double z_ima_min, double z_ima_max);
};

#endif /* ifndef BUFFWRITER_H */
12 changes: 6 additions & 6 deletions src/main_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ inline void init_mandel_parameters(std::shared_ptr<MandelParameters> &params,
unsigned int yrange = parser["h"].as<unsigned int>();

unsigned int zoomlvl = 0;
unsigned int xcoord = 0;
unsigned int ycoord = 0;
double xcoord = 0;
double ycoord = 0;

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

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

p.add_options("Export")
("p,print", "Print Buffer to terminal")
Expand Down
6 changes: 3 additions & 3 deletions src/mandelparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ struct MandelParameters {
unsigned int bailout;

unsigned int zoom;
unsigned int xcoord;
unsigned int ycoord;
double xcoord;
double ycoord;

std::string image_base;

Expand All @@ -52,7 +52,7 @@ struct MandelParameters {
MandelParameters(unsigned int xrange, double xl, double xh,
unsigned int yrange, double yl, double yh,
unsigned int bailout, unsigned int zoom,
unsigned int xcoord, unsigned int ycoord,
double xcoord, double ycoord,
std::string image_base, unsigned int cores,
constants::COL_ALGO col_algo)
: xrange(xrange),
Expand Down
2 changes: 1 addition & 1 deletion src/mandelzoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Mandelzoom::Mandelzoom() {}
void Mandelzoom::calcalute_zoom_cpane(double &xh, double &xl, double &yh,
double &yl, unsigned int zoom,
unsigned int xcoord, unsigned int ycoord,
double xcoord, double ycoord,
unsigned int width, unsigned int height)
{
/*
Expand Down
4 changes: 2 additions & 2 deletions src/mandelzoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class Mandelzoom
* @param ycoord Y coordinate in the complex plane
*/
void calcalute_zoom_cpane(double &xh, double &xl, double &yh, double &yl,
unsigned int zoom, unsigned int xcoord,
unsigned int ycoord, unsigned int width,
unsigned int zoom, double xcoord,
double ycoord, unsigned int width,
unsigned int height);

private:
Expand Down
2 changes: 1 addition & 1 deletion src/test/buffwriter_mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void BuffwriterMock::write_buffer(){};
std::string BuffwriterMock::test_filename_patterns(
std::string filename_pattern, unsigned int bailout, unsigned int xrange,
unsigned int yrange, unsigned int zoom, unsigned int cores,
unsigned int xcoord, unsigned int ycoord, double z_real_min,
double xcoord, double ycoord, double z_real_min,
double z_real_max, double z_ima_min, double z_ima_max)
{
return this->out_file_name(filename_pattern, bailout, xrange, yrange, zoom,
Expand Down
4 changes: 2 additions & 2 deletions src/test/buffwriter_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class BuffwriterMock : public Buffwriter
std::string test_filename_patterns(std::string filename_pattern,
unsigned int bailout, unsigned int xrange,
unsigned int yrange, unsigned int zoom,
unsigned int cores, unsigned int xcoord,
unsigned int ycoord, double z_real_min,
unsigned int cores, double xcoord,
double ycoord, double z_real_min,
double z_real_max, double z_ima_min,
double z_ima_max);

Expand Down
4 changes: 2 additions & 2 deletions src/test/test_computation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ TEST_CASE("Computation of zoom values", "[computation]")
// zoom level
unsigned int zoom = 30;
// x/y coordinate in the image space
unsigned int xcoord = 200;
unsigned int ycoord = 300;
double xcoord = 200;
double ycoord = 300;

SECTION("Test 30x zoom")
{
Expand Down

0 comments on commit 4aa5b73

Please sign in to comment.