Skip to main content
added 5 characters in body
Source Link
Cris Luengo
  • 6.2k
  • 1
  • 13
  • 36
  1. You’re ensuring, inside the loop, that you’re not outside the image on the right and bottom, but not on the left or top (x or y can be negative in that loop. Also, it would be a lot more efficient if you changed the loop limits instead of adding that test to the loop: for (std::size_t y = std::max(point_y - radius, 0); y <= std::min(point_y + radius, height - 1); ++y) etc.

  2. You’re making the loop unconditionally parallel. But the default case of radius == 2 leads to a tiny loop that will only slow down if parallelized (because creating threads is expensive).

  3. Your condition distance^2| distance^2 - radius^2 <| < 2 radius is unclear to me. The thickness of the drawn circle is related to the square root of the radius? Where does this come from? Why does that not match what I see in your example output?

  4. There’s a much simpler and efficient algorithm for drawing a circle. Your algorithm iterates over all pixels in a square around the circle, and does a test for each. Instead, you can just loop over the pixels that form the circle: https://en.m.wikipedia.org/wiki/Midpoint_circle_algorithm

  1. You’re ensuring, inside the loop, that you’re not outside the image on the right and bottom, but not on the left or top (x or y can be negative in that loop. Also, it would be a lot more efficient if you changed the loop limits instead of adding that test to the loop: for (std::size_t y = std::max(point_y - radius, 0); y <= std::min(point_y + radius, height - 1); ++y) etc.

  2. You’re making the loop unconditionally parallel. But the default case of radius == 2 leads to a tiny loop that will only slow down if parallelized (because creating threads is expensive).

  3. Your condition distance^2 - radius^2 < 2 radius is unclear to me. The thickness of the drawn circle is related to the square root of the radius? Where does this come from? Why does that not match what I see in your example output?

  4. There’s a much simpler and efficient algorithm for drawing a circle. Your algorithm iterates over all pixels in a square around the circle, and does a test for each. Instead, you can just loop over the pixels that form the circle: https://en.m.wikipedia.org/wiki/Midpoint_circle_algorithm

  1. You’re ensuring, inside the loop, that you’re not outside the image on the right and bottom, but not on the left or top (x or y can be negative in that loop. Also, it would be a lot more efficient if you changed the loop limits instead of adding that test to the loop: for (std::size_t y = std::max(point_y - radius, 0); y <= std::min(point_y + radius, height - 1); ++y) etc.

  2. You’re making the loop unconditionally parallel. But the default case of radius == 2 leads to a tiny loop that will only slow down if parallelized (because creating threads is expensive).

  3. Your condition | distance^2 - radius^2 | < 2 radius is unclear to me. The thickness of the drawn circle is related to the square root of the radius? Where does this come from? Why does that not match what I see in your example output?

  4. There’s a much simpler and efficient algorithm for drawing a circle. Your algorithm iterates over all pixels in a square around the circle, and does a test for each. Instead, you can just loop over the pixels that form the circle: https://en.m.wikipedia.org/wiki/Midpoint_circle_algorithm

Source Link
Cris Luengo
  • 6.2k
  • 1
  • 13
  • 36

  1. You’re ensuring, inside the loop, that you’re not outside the image on the right and bottom, but not on the left or top (x or y can be negative in that loop. Also, it would be a lot more efficient if you changed the loop limits instead of adding that test to the loop: for (std::size_t y = std::max(point_y - radius, 0); y <= std::min(point_y + radius, height - 1); ++y) etc.

  2. You’re making the loop unconditionally parallel. But the default case of radius == 2 leads to a tiny loop that will only slow down if parallelized (because creating threads is expensive).

  3. Your condition distance^2 - radius^2 < 2 radius is unclear to me. The thickness of the drawn circle is related to the square root of the radius? Where does this come from? Why does that not match what I see in your example output?

  4. There’s a much simpler and efficient algorithm for drawing a circle. Your algorithm iterates over all pixels in a square around the circle, and does a test for each. Instead, you can just loop over the pixels that form the circle: https://en.m.wikipedia.org/wiki/Midpoint_circle_algorithm