MCPcopy Create free account
hub / github.com/alandefreitas/matplotplusplus / fill_border_jump

Method fill_border_jump

source/matplot/axes_objects/contours.cpp:625–734  ·  view source on GitHub ↗

Generate points to close a polygon if not closed yet Some polygons might not be closed yet. Large polygons that end on borders might not be going around the borders properly as it should. That's fine for lines but it's not fine for filled curves. In these cases, we have to sanitize and continue clockwise or anticlockwise around the borders until we reach the initial point. If they start or end o

Source from the content-addressed store, hash-verified

623 /// go around the borders. In these cases, the contourc
624 /// algorithm does not close the polygons for us.
625 std::pair<vector_1d, vector_1d>
626 contours::fill_border_jump(double start_x, double start_y, double end_x,
627 double end_y, double x_min, double x_max,
628 double y_min, double y_max, bool is_parent) {
629 // start_b = identify if starting border W,S,E,N
630 constexpr uint8_t NONE = 0;
631 constexpr uint8_t NORTH = 1;
632 constexpr uint8_t SOUTH = 2;
633 constexpr uint8_t WEST = 3;
634 constexpr uint8_t EAST = 4;
635 uint8_t xy1_border = NONE;
636 if (start_x <= x_min) {
637 xy1_border = WEST;
638 } else if (start_x >= x_max) {
639 xy1_border = EAST;
640 } else if (start_y <= y_min) {
641 xy1_border = SOUTH;
642 } else if (start_y >= y_max) {
643 xy1_border = NORTH;
644 }
645 if (xy1_border == NONE) {
646 return {};
647 }
648
649 // end_b = identify if closing border border W,S,E,N
650 uint8_t xy2_border = NONE;
651 if (end_x <= x_min) {
652 xy2_border = WEST;
653 } else if (end_x >= x_max) {
654 xy2_border = EAST;
655 } else if (end_y <= y_min) {
656 xy2_border = SOUTH;
657 } else if (end_y >= y_max) {
658 xy2_border = NORTH;
659 }
660 if (xy2_border == NONE) {
661 return {};
662 }
663
664 // parents go anticlockwise
665 // we need to know the direction we should use to fill the border
666 const bool clockwise = !is_parent;
667
668 std::pair<vector_1d, vector_1d> result;
669 if (clockwise) {
670 while (xy1_border != xy2_border) {
671 switch (xy1_border) {
672 case WEST:
673 // append NW
674 result.first.emplace_back(x_min);
675 result.second.emplace_back(y_max);
676 xy1_border = NORTH;
677 break;
678 case NORTH:
679 // append NE
680 result.first.emplace_back(x_max);
681 result.second.emplace_back(y_max);
682 xy1_border = EAST;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected