Reference: https://web.archive.org/web/20170808221957/https://sharif.edu/~zarrabi/papers/cccg-06/meb.pdf
| 55 | // Reference: |
| 56 | // https://web.archive.org/web/20170808221957/https://sharif.edu/~zarrabi/papers/cccg-06/meb.pdf |
| 57 | void add_points(Sphere &s, u32 num, u32 stride, const void *points) |
| 58 | { |
| 59 | const char *pts = (char *)points; |
| 60 | |
| 61 | if (CE_UNLIKELY(num == 0)) |
| 62 | return; |
| 63 | |
| 64 | s.c = *(Vector3 *)pts; |
| 65 | s.r = 0.0f; |
| 66 | pts += stride; |
| 67 | |
| 68 | for (u32 i = 1; i < num; ++i, pts += stride) { |
| 69 | const Vector3 &p = *(Vector3 *)pts; |
| 70 | |
| 71 | if (!sphere::contains_point(s, p)) { |
| 72 | const f32 dist = distance(p, s.c); |
| 73 | const f32 delta = 0.5f * (dist - s.r); |
| 74 | const f32 alpha = delta / dist; |
| 75 | |
| 76 | s.c += alpha * (p - s.c); |
| 77 | s.r += delta + FLOAT_EPSILON * 10.0f; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | } // namespace sphere |
| 83 |