# Strange code in Fast Keypoint detector: (i - 3) % 3

**URL:** <https://forum.opencv.org/t/strange-code-in-fast-keypoint-detector-i-3-3/19682>\
**Category:** C++\
**Tags:** features2d\
**Created:** [January 5, 2025, 4:38am UTC](https://forum.opencv.org/t/strange-code-in-fast-keypoint-detector-i-3-3/19682 "2025-01-05T04:38:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vahagnIV](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/vahagniv/32/903_2.png) [@vahagnIV](https://forum.opencv.org/u/vahagnIV)\
**Post date:** [January 5, 2025, 4:38am UTC](https://forum.opencv.org/t/strange-code-in-fast-keypoint-detector-i-3-3/19682/1 "2025-01-05T04:38:14Z")

</div>

I see this code here:

> <https://github.com/opencv/opencv/blob/ff18c9cc7904e878b10273265196e0238490e692/modules/features2d/src/fast.cpp#L102C16-L102C20>

Am I missing something or is it an artifact that remained there after debugging?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [January 5, 2025, 5:46am UTC](https://forum.opencv.org/t/strange-code-in-fast-keypoint-detector-i-3-3/19682/2 "2025-01-05T05:46:46Z")

</div>

`curr` is being used two lines down, so no, that’s not dead code.

it is some funky math but seems intentional.

remember, the `%` operator in C and C++ has weird semantics. `(-1) % 3 == -1`

---

<div class="post-metadata">

**Author:** ![vahagnIV](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/vahagniv/32/903_2.png) [@vahagnIV](https://forum.opencv.org/u/vahagnIV)\
**Post date:** [January 5, 2025, 6:08am UTC](https://forum.opencv.org/t/strange-code-in-fast-keypoint-detector-i-3-3/19682/3 "2025-01-05T06:08:31Z")

</div>

We have `i >=3` always

> <https://github.com/opencv/opencv/blob/ff18c9cc7904e878b10273265196e0238490e692/modules/features2d/src/fast.cpp#L99>

I am not saying it’s dead. I am saying that we could simply write `i % 3` instead.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [January 5, 2025, 8:31am UTC](https://forum.opencv.org/t/strange-code-in-fast-keypoint-detector-i-3-3/19682/4 "2025-01-05T08:31:02Z")

</div>

oh right, I’m not quite awake yet. so… it’s index shifting. and the shift shows up in that place, as it should, but it’s all magic constants, which is bad.

such code deserves a few more comments.

anyway, any reasonable compiler will optimize that, so nothing to worry about.
