function results = msmt_split(T,points)
% MSMT_SPLIT determines whether a point is an element of set A or set B.
%
%	results = msmt_split(T,points)
%
%	T: matrix representing the decision matrix T, detemined by MSM-T
%		algorithm
%	points: if classifying one point, points is a vector representing
%		that point.
%		if classifying more than one point, points if a matrix where
%		each row is an individual point
%	results: for each point i that is to be classified:
%		 results(i) = 0 if point i is an element of set A.
%		 results(i) = 1 if point i is an element of set B.
%
%	NOTE: assume A is such that Aw <= theta
%	      	     B is such that Bw >  theta

% if point is in a leaf that is a left child, it is in A
% if point is in a leaf that is a right child, it is in B
global n;

for i = 1:size(points,1)
	position = 1;	% start with root node in T
	done = 0;	% done = false

	while (~done)	% while not done
	
		w = T(1:n,position);		% get the weight vector w
		theta = T(n+1,position);	% get the threshold, theta

		if (points(i,:)*w == theta)	% if this point is on line

			results(i) = 0;		% it is a point of A.
			done = 1;		% and we're done with it.

		end

		if (points(i,:)*w < theta)	% if this point is 'below' line
			if (T(n+2,position) ~= -1)	% if lchild not leaf

				position = T(n+2,position); % goto lchild

			else				% else lchild is leaf
				results(i) = 0;		% it is a point of A
				done = 1;		% and we're done

			end

		else				% if this point is 'above' line
			if (T(n+3,position) ~= -1)	% if rchild not leaf

				position = T(n+3,position); % goto rchild

			else				% else rchild is leaf
				results(i) = 1;		% it is a point of B
				done = 1;		% and we're done

			end
		end
	end % while
end % for


