classdef Particle < handle
    properties(Constant)
        NEUTRON = 1;
        URANIUM = 2;
        STABLE = 3;
    end
    
    properties
        position % x y z column vector for position
        direction % precondition: unit vector for direction
        speed 
        type % use constants for neutron or tritium
    end
    
    methods
        function draw(obj)
            if obj.type == Particle.NEUTRON
                color = [.4 .4 .4];
                size = 10;
            elseif obj.type == Particle.TRITIUM
                color = [.8 .3 .3];
                size = 30;
            else
                error('Unknown particle type');
            end
            
%             '.', 'MarkerSize', size, ...
            scatter3(obj.position(1), ...
            obj.position(2), ...
            obj.position(3), ...
            'MarkerEdgeColor', 'k',...
            'MarkerFaceColor', color)
            % TODO draw so it has black outline and 
            % size is based on distance away from viewpoint
        end
        
        function update(obj)
            global MIN_X MAX_X MIN_Y MAX_Y MIN_Z MAX_Z;
            p2 = obj.position + obj.speed * obj.direction;
            
            % Loop x bounds
            if p2(1) > MAX_X
                p2(1) = MIN_X + mod(p2(1), MAX_X);
            elseif p2(1) < MIN_X
                p2(1) = MAX_X + mod(p2(1), MIN_X); 
            end
            
            % Loop y bounds
            if p2(2) > MAX_Y
                p2(2) = MIN_Y + mod(p2(2), MAX_Y-MIN_Y);
            elseif p2(2) < MIN_Y
                p2(2) = MAX_Y + mod(p2(2), MIN_Y);
            end
            
            % Loop z bounds
            if p2(3) > MAX_Z
                p2(3) = MIN_Z + mod(p2(3), MAX_Z-MIN_Z);
            elseif p2(3) < MIN_Z
                p2(3) = MAX_Z + mod(p2(3), MIN_Z);
            end
            
            obj.position = p2;
        end
        
    end
end