# All files / src/WebGL/shapes Sphere.ts

86.66% Statements 13/15
50% Branches 2/4
71.42% Functions 5/7
86.66% Lines 13/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47

    29x
    29x

    1x
    1x
    1x

    1x
    1x
    1x

    1x
    1x
    1x

    1x
    1x

     import { Matrix4 } from '../math';
    import { Vector3 } from '../math';
    //Intersection sphere and box shapes.

    //Intersection sphere for sphere, stick render
    export class Sphere {
      center: Vector3
      radius: number

      constructor(center = new Vector3(), radius = 0) {
        this.center = center;
        this.radius = radius;
      }

      set(center: Vector3, radius: number): Sphere {
        this.center.copy(center);
        this.radius = radius;
        return this;
      }

      copy(sphere: Sphere): Sphere {
        this.center.copy(sphere.center);
        this.radius = sphere.radius;
        return this;
      }

      applyMatrix4(matrix: Matrix4): Sphere {
        this.center.applyMatrix4(matrix);
        this.radius = this.radius * matrix.getMaxScaleOnAxis();
        return this;
      }

      translate(offset: Vector3): Sphere {
        this.center.add(offset);
        return this;
      }

      equals(sphere: Sphere): boolean {
        // @ts-ignore
        return sphere.center.equals(this.center) && sphere.radius === this.radius;
      }

      clone(): Sphere {
        return new Sphere().copy(this);
      }
    }