Skip to content

Commit

Permalink
Improve the geometry structures
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Aug 31, 2024
1 parent e4a2c88 commit 55431bb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
32 changes: 22 additions & 10 deletions MandelbrotDiscovery/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,29 @@
template<typename T>
struct point_type
{
public:
using value_type = T;

explicit point_type(const value_type& x_val = value_type(),
const value_type& y_val = value_type())
: my_x(x_val),
my_y(y_val) { }

auto get_x() const noexcept -> const value_type& { return my_x; }
auto get_y() const noexcept -> const value_type& { return my_y; }

auto set_x(const value_type& new_x) noexcept -> void { my_x = new_x; }
auto set_y(const value_type& new_y) noexcept -> void { my_y = new_y; }

private:
value_type my_x { };
value_type my_y { };
};

template<typename PointType>
struct rectangle_type
{
public:
using point_type = PointType;
using value_type = typename point_type::value_type;

Expand Down Expand Up @@ -64,8 +73,8 @@
return
point_type
(
my_center.my_x - my_dx_half,
my_center.my_y + my_dy_half
my_center.get_x() - my_dx_half,
my_center.get_y() + my_dy_half
);
}

Expand All @@ -74,14 +83,16 @@
return
point_type
(
my_center.my_x + my_dx_half,
my_center.my_y - my_dy_half
my_center.get_x() + my_dx_half,
my_center.get_y() - my_dy_half
);
}

auto dx_half() const noexcept -> value_type { return my_dx_half; }
auto dy_half() const noexcept -> value_type { return my_dy_half; }

auto center() const noexcept -> point_type { return my_center; }

auto recenter(const point_type& new_center) noexcept -> void
{
my_center = new_center;
Expand All @@ -98,11 +109,11 @@
my_pixels_x = pa_x;
my_pixels_y = pa_y;

const auto lo_right = lower_right();
const auto up_left = upper_left ();
const auto& lo_right = lower_right();
const auto& up_left = upper_left ();

my_dx_pixel = (lo_right.my_x - up_left.my_x ) / my_pixels_x;
my_dy_pixel = (up_left.my_y - lo_right.my_y) / my_pixels_y;
my_dx_pixel = (lo_right.get_x() - up_left.get_x() ) / my_pixels_x;
my_dy_pixel = (up_left.get_y() - lo_right.get_y()) / my_pixels_y;
}

return result_is_ok;
Expand Down Expand Up @@ -132,13 +143,14 @@

const auto up_left = upper_left();

pt_val.my_x = up_left.my_x + delta_x;
pt_val.my_y = up_left.my_y - delta_y;
pt_val.set_x(up_left.get_x() + delta_x);
pt_val.set_y(up_left.get_y() - delta_y);
}

return result_is_ok;
}

private:
point_type my_center { };
value_type my_dx_half { };
value_type my_dy_half { };
Expand Down
16 changes: 8 additions & 8 deletions MandelbrotDiscovery/mandelbrot_discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
::HWND my_handle_to_window { nullptr };
::HINSTANCE my_handle_to_instance { nullptr };

static point_type my_rectangle_center;
static point_type my_rectangle_center;
static rectangle_ref_type my_ref_to_rectangle;

static std::thread my_thread;
Expand Down Expand Up @@ -316,10 +316,10 @@
const local_mandelbrot_config_type
mandelbrot_config_object
(
my_ref_to_rectangle.get().my_center.my_x - my_ref_to_rectangle.get().my_dx_half,
my_ref_to_rectangle.get().my_center.my_x + my_ref_to_rectangle.get().my_dx_half,
my_ref_to_rectangle.get().my_center.my_y - my_ref_to_rectangle.get().my_dy_half,
my_ref_to_rectangle.get().my_center.my_y + my_ref_to_rectangle.get().my_dy_half,
my_ref_to_rectangle.get().center().get_x() - my_ref_to_rectangle.get().dx_half(),
my_ref_to_rectangle.get().center().get_x() + my_ref_to_rectangle.get().dx_half(),
my_ref_to_rectangle.get().center().get_y() - my_ref_to_rectangle.get().dy_half(),
my_ref_to_rectangle.get().center().get_y() + my_ref_to_rectangle.get().dy_half(),
my_mandelbrot_iterations
);

Expand Down Expand Up @@ -454,10 +454,10 @@

if(result_is_ok)
{
result_is_ok = (write_number("x_val : ", my_rectangle_center.my_x) && result_is_ok);
result_is_ok = (write_number("y_val : ", my_rectangle_center.my_y) && result_is_ok);
result_is_ok = (write_number("x_val : ", my_rectangle_center.get_x()) && result_is_ok);
result_is_ok = (write_number("y_val : ", my_rectangle_center.get_y()) && result_is_ok);
result_is_ok = (write_number("dx_half: ", my_ref_to_rectangle.get().dx_half(), 3) && result_is_ok);
result_is_ok = (write_string("\n") && result_is_ok);
result_is_ok = (write_string("\n") && result_is_ok);
}

const auto lresult =
Expand Down

0 comments on commit 55431bb

Please sign in to comment.