| 808 | } |
| 809 | |
| 810 | std::optional<Point> Layer::convertPointToLayer(Point point, const Valdi::Ref<Layer>& childLayer) const { |
| 811 | thread_local std::vector<Ref<Layer>> kDescendants; |
| 812 | |
| 813 | auto& descendants = kDescendants; |
| 814 | auto current = childLayer; |
| 815 | |
| 816 | for (;;) { |
| 817 | if (current.get() == this) { |
| 818 | break; |
| 819 | } |
| 820 | |
| 821 | if (current == nullptr) { |
| 822 | return std::nullopt; |
| 823 | } |
| 824 | |
| 825 | descendants.emplace_back(current); |
| 826 | current = Valdi::castOrNull<Layer>(current->getParent()); |
| 827 | } |
| 828 | |
| 829 | for (size_t i = descendants.size(); i > 0;) { |
| 830 | i--; |
| 831 | point = descendants[i]->convertPointFromParent(point); |
| 832 | } |
| 833 | |
| 834 | descendants.clear(); |
| 835 | |
| 836 | return point; |
| 837 | } |
| 838 | |
| 839 | Point Layer::convertPointFromParent(const Point& point) { |
| 840 | // TODO(simon): Take in account rotation |