-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SimpleSets: basic implementation #46
Changes from all commits
94a340e
648b276
0db582a
0a33517
9d3362a
f2c478e
a5622bf
11a39dd
a2b25a8
4ccbec1
2c8b31c
28e995d
fed5322
2c8e349
749fc7d
41766a0
20a7682
3b47849
f4bf79a
32bdfab
e622395
551286d
fbd5780
2d3674a
0226c06
2194234
86fd6e9
0ad729e
f2ab5dd
ee81e19
f51d5aa
ea0b9db
79e2aec
af5924f
7c3444e
696aa65
51a845f
d096ece
88f3da9
a97f3ac
8395d51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "function_painting.h" | ||
|
||
namespace cartocrow::renderer { | ||
FunctionPainting::FunctionPainting(const std::function<void(GeometryRenderer&)>& draw_function) | ||
: m_draw_function(draw_function) {} | ||
|
||
void FunctionPainting::paint(GeometryRenderer& renderer) const { | ||
m_draw_function(renderer); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef CARTOCROW_FUNCTION_PAINTING_H | ||
#define CARTOCROW_FUNCTION_PAINTING_H | ||
|
||
#include "geometry_renderer.h" | ||
#include "geometry_painting.h" | ||
|
||
namespace cartocrow::renderer { | ||
class FunctionPainting : public GeometryPainting { | ||
public: | ||
FunctionPainting(const std::function<void(GeometryRenderer&)>& draw_function); | ||
void paint(renderer::GeometryRenderer& renderer) const override; | ||
|
||
private: | ||
const std::function<void(GeometryRenderer&)> m_draw_function; | ||
}; | ||
} | ||
|
||
#endif //CARTOCROW_FUNCTION_PAINTING_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. | |
#include "geometry_renderer.h" | ||
#include "ipe_renderer.h" | ||
|
||
#include "function_painting.h" | ||
|
||
#include <QFileDialog> | ||
#include <QGuiApplication> | ||
#include <QPainterPath> | ||
|
@@ -541,7 +543,7 @@ void GeometryWidget::draw(const BezierSpline& s) { | |
|
||
void GeometryWidget::draw(const Ray<Inexact>& r) { | ||
Box bounds = inverseConvertBox(rect()); | ||
auto result = intersection(r, CGAL::Iso_rectangle_2<Inexact>(Point<Inexact>(bounds.xmin(), bounds.ymin()), Point<Inexact>(bounds.xmax(), bounds.ymax()))); | ||
auto result = intersection(r, Rectangle<Inexact>(Point<Inexact>(bounds.xmin(), bounds.ymin()), Point<Inexact>(bounds.xmax(), bounds.ymax()))); | ||
if (result) { | ||
if (const Segment<Inexact>* s = boost::get<Segment<Inexact>>(&*result)) { | ||
int oldMode = m_style.m_mode; | ||
|
@@ -680,6 +682,11 @@ void GeometryWidget::addPainting(std::shared_ptr<GeometryPainting> painting, con | |
updateLayerList(); | ||
} | ||
|
||
void GeometryWidget::addPainting(const std::function<void(renderer::GeometryRenderer&)>& draw_function, const std::string& name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (see comment about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid this while keeping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not think of that.
because you need to still create a shared pointer, which I would like to avoid having to do. |
||
auto painting = std::make_shared<FunctionPainting>(draw_function); | ||
addPainting(painting, name); | ||
} | ||
|
||
void GeometryWidget::clear() { | ||
m_paintings.clear(); | ||
updateLayerList(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
set(SOURCES | ||
cat_point.cpp | ||
types.cpp | ||
parse_input.cpp | ||
patterns/pattern.cpp | ||
patterns/single_point.cpp | ||
patterns/matching.cpp | ||
patterns/island.cpp | ||
patterns/bank.cpp | ||
dilated/dilated_poly.cpp | ||
helpers/approximate_convex_hull.cpp | ||
helpers/cs_curve_helpers.cpp | ||
helpers/cs_polygon_helpers.cpp | ||
helpers/cs_polyline_helpers.cpp | ||
helpers/poly_line_gon_intersection.cpp | ||
partition_algorithm.cpp | ||
partition_painting.cpp | ||
drawing_algorithm.cpp | ||
grow_circles.cpp | ||
) | ||
set(HEADERS | ||
types.h | ||
settings.h | ||
cat_point.h | ||
parse_input.h | ||
patterns/pattern.h | ||
patterns/poly_pattern.h | ||
patterns/single_point.h | ||
patterns/matching.h | ||
patterns/island.h | ||
patterns/bank.h | ||
dilated/dilated_poly.h | ||
helpers/approximate_convex_hull.h | ||
helpers/arrangement_helpers.h | ||
helpers/point_voronoi_helpers.h | ||
helpers/poly_line_gon_intersection.h | ||
helpers/cropped_voronoi.h | ||
helpers/cs_curve_helpers.h | ||
helpers/cs_polygon_helpers.h | ||
helpers/cs_polyline_helpers.h | ||
partition_algorithm.h | ||
partition_painting.h | ||
partition.h | ||
drawing_algorithm.h | ||
general_polyline.h | ||
grow_circles.h | ||
) | ||
|
||
add_library(simplesets ${SOURCES}) | ||
target_link_libraries(simplesets | ||
PUBLIC core | ||
) | ||
|
||
cartocrow_install_module(simplesets) | ||
install(FILES ${HEADERS} DESTINATION ${CARTOCROW_INSTALL_DIR}/simplesets) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "cat_point.h" | ||
|
||
namespace cartocrow::simplesets { | ||
std::ostream& operator<<(std::ostream& os, CatPoint const& catPoint) { | ||
return os << catPoint.category << " " << catPoint.point; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef CARTOCROW_CAT_POINT_H | ||
#define CARTOCROW_CAT_POINT_H | ||
|
||
#include "types.h" | ||
|
||
namespace cartocrow::simplesets { | ||
/// Categorical point | ||
struct CatPoint { | ||
unsigned int category; | ||
Point<Inexact> point; | ||
CatPoint(unsigned int category, Point<Inexact> point) : category(category), point(point) {}; | ||
bool operator==(const CatPoint&) const = default; | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream& os, CatPoint const& catPoint); | ||
} | ||
|
||
#endif //CARTOCROW_CAT_POINT_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I don't grok the purpose of a
FunctionPainting
. One can already make an ad-hoc painting by subclassingGeometryPainting
, for example:I guess with
FunctionPainting
slightly less code is needed:but I'm not sure if the added complexity is worth it?
Anyway, did I miss a use case where using
FunctionPainting
would be significantly easier?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not use FunctionPainting on its own, but use the helper function (or the implicitly converting constructor that you suggest below).
Then you go from:
to
I don't have a specific use case in mind that is way simpler this way, I added it only as a more concise way of drawing something simple. For me, having to create a class, derive from a specific other one, and override one specific method, in order to draw something is boiler plate and an obstacle when programming. Generally I would also define this painting class in a header, and have the implementation in the cpp file, though I see your point that you can also define it locally just in the cpp file. Part of the reason that I find this much simpler is probably that I'm more used to functional programming than object oriented programming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An argument for adding this: a lambda function makes it easy to capture variables that are in scope. When debugging a function, I sometimes use IpeRenderer together with a lambda function to draw some debug info and save it to a file.