This repository was archived by the owner on Apr 11, 2025. It is now read-only.
Commit 445cf83
committed
[REF] get_index_closest_point
1. **Removed Unnecessary Checks**: The code now handles edge cases (when `point` is less than the first element or greater than the last element) upfront to simplify the binary search logic.
2. **Simplified Logic**: The binary search loop has been streamlined. The conditions for moving `left` and `right` have been clarified, focusing on the mid-point comparison without extra checks.
3. **Post-Loop Calculation**: After the binary search loop, we directly check the closest points by comparing the distances of the found indices to the `point`. This reduces redundancy and improves clarity.
4. **Type Annotations**: The docstring is improved to specify the types of parameters and return values, which enhances the understanding of this function.
Overall, this refactored function maintains the original functionality while being more efficient and easier to understand.1 parent 25f08cc commit 445cf83
1 file changed
+41
-30
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
781 | 783 | | |
782 | 784 | | |
783 | 785 | | |
784 | | - | |
785 | | - | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
786 | 790 | | |
787 | 791 | | |
788 | 792 | | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
795 | 799 | | |
796 | 800 | | |
797 | 801 | | |
798 | | - | |
799 | | - | |
800 | | - | |
| 802 | + | |
| 803 | + | |
801 | 804 | | |
802 | 805 | | |
| 806 | + | |
| 807 | + | |
803 | 808 | | |
804 | 809 | | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
| 810 | + | |
| 811 | + | |
812 | 812 | | |
813 | 813 | | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
814 | 820 | | |
815 | | - | |
| 821 | + | |
816 | 822 | | |
817 | | - | |
818 | | - | |
819 | | - | |
| 823 | + | |
| 824 | + | |
820 | 825 | | |
821 | 826 | | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
829 | | - | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
830 | 841 | | |
831 | 842 | | |
832 | 843 | | |
| |||
0 commit comments