1#include <gtest/gtest.h>
14bool has_nan_or_inf(std::string s)
17 c = static_cast<char>(::
tolower(static_cast<unsigned char>(c)));
19 return s.find(
"nan") != std::string::npos or
20 s.find(
"inf") != std::string::npos;
25TEST(TikzPlaneTest, ConstructionAndAccessors)
29 EXPECT_DOUBLE_EQ(plane.
get_wide(), 120.0);
33 EXPECT_EQ(plane.
size(), 0U);
36TEST(TikzPlaneTest, DrawEmptyPlane)
42 const std::string result =
output.str();
44 EXPECT_NE(result.find(
"\\begin{tikzpicture}"), std::string::npos);
45 EXPECT_NE(result.find(
"\\clip (-1.000000,-1.000000) rectangle (101.000000,61.000000);"),
47 EXPECT_NE(result.find(
"\\end{tikzpicture}"), std::string::npos);
48 EXPECT_FALSE(has_nan_or_inf(result));
51TEST(TikzPlaneTest, SinglePointDoesNotCrash)
59 const std::string result =
output.str();
60 EXPECT_NE(result.find(
"\\fill"), std::string::npos);
61 EXPECT_FALSE(has_nan_or_inf(result));
64TEST(TikzPlaneTest, DegenerateRangesVerticalAndHorizontalSegments)
72 const std::string result =
output.str();
73 EXPECT_NE(result.find(
"\\draw"), std::string::npos);
74 EXPECT_FALSE(has_nan_or_inf(result));
83 const std::string result =
output.str();
84 EXPECT_NE(result.find(
"\\draw"), std::string::npos);
85 EXPECT_FALSE(has_nan_or_inf(result));
89TEST(TikzPlaneTest, SupportsCoreGeometryObjects)
110 std::ostringstream
output;
112 const std::string result =
output.str();
114 EXPECT_NE(result.find(
"ellipse [x radius="), std::string::npos);
115 EXPECT_NE(result.find(
"\\node"), std::string::npos);
116 EXPECT_NE(result.find(
"-- cycle;"), std::string::npos);
117 EXPECT_FALSE(has_nan_or_inf(result));
120TEST(TikzPlaneTest, SupportsPolarPointAndRotatedEllipse)
124 const Geom_Number pi_over_four = 0.7853981633974483096;
127 RotatedEllipse rotated(
Point(20, 20), 12, 5, 0.7071067811865475244, 0.7071067811865475244);
130 std::ostringstream
output;
132 const std::string result =
output.str();
134 EXPECT_NE(result.find(
"\\fill"), std::string::npos);
135 EXPECT_NE(result.find(
"-- cycle;"), std::string::npos);
136 EXPECT_FALSE(has_nan_or_inf(result));
139TEST(TikzPlaneTest, OptionalCartesianAxis)
145 std::ostringstream
output;
147 const std::string result =
output.str();
149 EXPECT_NE(result.find(
"\\draw["), std::string::npos);
150 EXPECT_NE(result.find(
"draw=gray"), std::string::npos);
151 EXPECT_NE(result.find(
"->"), std::string::npos);
154TEST(TikzPlaneTest, SupportsRectangleAndLineEq)
160 std::ostringstream
output;
162 const std::string result =
output.str();
164 EXPECT_NE(result.find(
"-- cycle;"), std::string::npos);
165 EXPECT_NE(result.find(
"\\draw"), std::string::npos);
166 EXPECT_FALSE(has_nan_or_inf(result));
169TEST(TikzPlaneTest, EscapesLatexText)
174 std::ostringstream
output;
176 const std::string result =
output.str();
178 EXPECT_NE(result.find(
"A\\_\\%\\$\\#\\&\\{\\}\\textbackslash{}B"), std::string::npos);
181TEST(TikzPlaneTest, ConfigurableClipPadding)
186 std::ostringstream
output;
188 const std::string result =
output.str();
190 EXPECT_NE(result.find(
"\\clip (-3.500000,-3.500000) rectangle (103.500000,63.500000);"),
194TEST(TikzPlaneTest, SupportsBezierHelpers)
200 std::ostringstream
output;
202 const std::string result =
output.str();
204 EXPECT_NE(result.find(
"\\draw"), std::string::npos);
205 EXPECT_FALSE(has_nan_or_inf(result));
208TEST(TikzPlaneTest, SupportsNativeBezierRendering)
216 std::ostringstream
output;
218 const std::string result =
output.str();
220 EXPECT_NE(result.find(
".. controls"), std::string::npos);
221 EXPECT_NE(result.find(
" and "), std::string::npos);
222 EXPECT_FALSE(has_nan_or_inf(result));
225TEST(TikzPlaneTest, SupportsTextPlacementAndAnchor)
233 std::ostringstream
output;
235 const std::string result =
output.str();
237 EXPECT_NE(result.find(
"anchor=west"), std::string::npos);
238 EXPECT_NE(result.find(
"above right"), std::string::npos);
241TEST(TikzPlaneTest, SupportsPatternFillStyle)
245 style.
pattern =
"north east lines";
255 std::ostringstream
output;
257 const std::string result =
output.str();
260 EXPECT_NE(result.find(
"pattern=north east lines"), std::string::npos);
261 EXPECT_NE(result.find(
"pattern color=black"), std::string::npos);
262 ASSERT_EQ(libraries.
size(), 1u);
263 EXPECT_EQ(libraries(0),
"patterns");
266TEST(TikzPlaneTest, SupportsGridTicksLegendLayersAndTikzset)
287 std::ostringstream
output;
289 const std::string result =
output.str();
291 EXPECT_NE(result.find(
"\\pgfdeclarelayer{background}"), std::string::npos);
292 EXPECT_NE(result.find(
"\\begin{pgfonlayer}{foreground}"), std::string::npos);
293 EXPECT_NE(result.find(
"\\tikzset{edgeA/.style="), std::string::npos);
294 EXPECT_NE(result.find(
"edgeA"), std::string::npos);
295 EXPECT_NE(result.find(
"draw=gray!40"), std::string::npos);
296 EXPECT_NE(result.find(
"\\node[anchor=west]"), std::string::npos);
297 EXPECT_FALSE(has_nan_or_inf(result));
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Represents a point with rectangular coordinates in a 2D plane.
Polar representation of a 2D point.
A general (irregular) 2D polygon defined by a sequence of vertices.
void add_vertex(const Point &point)
Add a vertex to the polygon.
void close()
Close the polygon.
An axis-aligned rectangle.
A regular polygon defined by center, side length, and vertex count.
An ellipse with arbitrary rotation.
Represents a line segment between two points.
Represents a text string positioned at a 2D point.
2D TikZ canvas storing geometry objects and emitting LaTeX output.
Array< std::string > required_tikz_libraries() const
Collect TikZ libraries required by currently emitted features.
void draw(std::ostream &output, const bool squarize=true) const
Emit a complete tikzpicture with all inserted objects.
void set_clip_padding_mm(const double &padding_mm)
Configure clip expansion around frame borders.
void put_cartesian_axis()
Enable Cartesian axes drawing (only when 0 lies in range).
const double & get_wide() const
Plane width in millimeters.
const double & get_height() const
Plane height in millimeters.
static constexpr int Layer_Foreground
void enable_auto_legend(const bool enabled=true)
Enable auto-legend generation from style colors.
void enable_native_tikz_layers(const bool enabled=true)
Enable native PGF layers (\pgfdeclarelayer).
size_t size() const
Number of currently inserted objects.
void put_coordinate_grid(const double step_x=1.0, const double step_y=1.0, const bool draw_ticks=true)
Enable coordinate grid/ticks with user step sizes.
const double & get_yoffset() const
Vertical scope offset in millimeters.
static constexpr int Layer_Background
void register_tikz_style(const std::string &name, const Tikz_Style &style)
Register a reusable \tikzset style for the rendered picture.
const double & get_xoffset() const
Horizontal scope offset in millimeters.
A non-degenerate triangle defined by three points.
Main namespace for Aleph-w library functions.
std::string tolower(const char *str)
Convert a C std::string to lower-case.
void put_cubic_bezier_native_in_plane(Tikz_Plane &plane, const Point &p0, const Point &p1, const Point &p2, const Point &p3, const Tikz_Style &style={}, const int layer=Tikz_Plane::Layer_Default)
Insert a cubic Bézier using native TikZ controls syntax.
void put_quadratic_bezier_native_in_plane(Tikz_Plane &plane, const Point &p0, const Point &p1, const Point &p2, const Tikz_Style &style={}, const int layer=Tikz_Plane::Layer_Default)
Insert a quadratic Bézier using native TikZ controls syntax.
void put_cubic_bezier_in_plane(Tikz_Plane &plane, const Point &p0, const Point &p1, const Point &p2, const Point &p3, const size_t subdivisions=64, const Tikz_Style &style={}, const int layer=Tikz_Plane::Layer_Default)
Approximate and insert a cubic Bézier as an open polyline.
void put_in_plane(Tikz_Plane &plane, const Geom &geom_obj)
Insert any supported geometry type in a Tikz_Plane.
void put_quadratic_bezier_in_plane(Tikz_Plane &plane, const Point &p0, const Point &p1, const Point &p2, const size_t subdivisions=64, const Tikz_Style &style={}, const int layer=Tikz_Plane::Layer_Default)
Approximate and insert a quadratic Bézier as an open polyline.
Tikz_Style make_tikz_draw_style(const std::string &draw_color)
Create a basic draw style with a custom color.
Tikz_Style make_tikz_fill_style(const std::string &draw_color, const std::string &fill_color)
Create a basic fill style with custom draw/fill colors.
2D infinite line in slope-intercept form.
Style descriptor for TikZ primitives.
std::string text_anchor
TikZ node anchor (anchor=<value>)
std::string pattern
TikZ pattern (e.g. north east lines)
std::string text_placement
TikZ placement (above, below left, ...)
std::string tikz_style_name
Optional named style (from \tikzset)
std::string draw_color
TikZ draw color (draw=<color>)
std::string pattern_color
TikZ pattern color (pattern color=<color>)
TikZ/LaTeX geometric drawing utilities.