Shape.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "Shape.h"
  2. namespace msdfgen {
  3. Shape::Shape() : inverseYAxis(false) { }
  4. void Shape::addContour(const Contour &contour) {
  5. contours.push_back(contour);
  6. }
  7. #ifdef MSDFGEN_USE_CPP11
  8. void Shape::addContour(Contour &&contour) {
  9. contours.push_back((Contour &&) contour);
  10. }
  11. #endif
  12. Contour & Shape::addContour() {
  13. contours.resize(contours.size()+1);
  14. return contours[contours.size()-1];
  15. }
  16. bool Shape::validate() const {
  17. for (std::vector<Contour>::const_iterator contour = contours.begin(); contour != contours.end(); ++contour) {
  18. if (!contour->edges.empty()) {
  19. Point2 corner = (*(contour->edges.end()-1))->point(1);
  20. for (std::vector<EdgeHolder>::const_iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge) {
  21. if (!*edge)
  22. return false;
  23. if ((*edge)->point(0) != corner)
  24. return false;
  25. corner = (*edge)->point(1);
  26. }
  27. }
  28. }
  29. return true;
  30. }
  31. void Shape::normalize() {
  32. for (std::vector<Contour>::iterator contour = contours.begin(); contour != contours.end(); ++contour)
  33. if (contour->edges.size() == 1) {
  34. EdgeSegment *parts[3] = { };
  35. contour->edges[0]->splitInThirds(parts[0], parts[1], parts[2]);
  36. contour->edges.clear();
  37. contour->edges.push_back(EdgeHolder(parts[0]));
  38. contour->edges.push_back(EdgeHolder(parts[1]));
  39. contour->edges.push_back(EdgeHolder(parts[2]));
  40. }
  41. }
  42. void Shape::bounds(double &l, double &b, double &r, double &t) const {
  43. for (std::vector<Contour>::const_iterator contour = contours.begin(); contour != contours.end(); ++contour)
  44. contour->bounds(l, b, r, t);
  45. }
  46. }