Skip to content

Commit

Permalink
Adds basic support for filled polygons.
Browse files Browse the repository at this point in the history
  • Loading branch information
pazmivaniye committed Jul 10, 2024
1 parent f952ca8 commit 71535a1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ void pgfplotter::Axis::matrix(const std::vector<double>& x, const std::vector<
matrixSurf.push_back(true);
}

void pgfplotter::Axis::fill(const std::array<int, 3>& color, const std::vector<
double>& x, const std::vector<double>& y)
{
fillX.push_back(x);
fillY.push_back(y);
fillColors.push_back(color);
}

void pgfplotter::Axis::legend(unsigned int location)
{
legendPos = location;
Expand Down Expand Up @@ -1147,6 +1155,33 @@ std::string pgfplotter::Axis::plot_src(const std::string& path, int subplot) con
}
}

for(std::size_t i = 0; i < fillX.size(); ++i)
{
const std::size_t numPoints = fillX[i].size();
if(fillY[i].size() != numPoints)
{
throw std::runtime_error("Number of points in x and y must match.");
}
src += "\\fill[";
if(fillColors[i][0] >= 0)
{
src += "rgb color = {" + std::to_string(fillColors[i][0]) + ", " +
std::to_string(fillColors[i][1]) + ", " + std::to_string(
fillColors[i][2]) + "}";
}
else
{
src += "black";
}
src += "] ";
for(std::size_t j = 0; j < numPoints; ++j)
{
src += "(" + ToString(fillX[i][j]) + ", " + ToString(fillY[i][j]) +
")--";
}
src += "cycle;" + endl;
}

for(std::size_t i = 0, sz = data.size(); i < sz; ++i)
{
const std::size_t numPoints = data[i][0].size();
Expand Down
6 changes: 6 additions & 0 deletions pgfplotter
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ namespace pgfplotter
std::vector<LineStyle> lineStyles;
std::vector<double> lineWidths;
std::vector<double> opacities;
std::vector<std::vector<double>> fillX;
std::vector<std::vector<double>> fillY;
std::vector<std::array<int, 3>> fillColors;

std::array<double, 2> _viewAngles = {0., 90.};

Expand Down Expand Up @@ -227,6 +230,9 @@ namespace pgfplotter
void matrix(const std::vector<double>& x, const std::vector<double>& y,
const std::vector<double>& z, const std::string& name = "");

void fill(const std::array<int, 3>& color, const std::vector<double>& x,
const std::vector<double>& y);

void legend(unsigned int location = Northeast);
void squeeze();
void squeezeX();
Expand Down

0 comments on commit 71535a1

Please sign in to comment.