function [pts] = g(x, domain)

%%%%%
% Helper function g to make sure 
% the configuration is inside the
% acceptable search space.
%
% x : DE parameters (obtained applying f)
% domain : 1 for square, 2 for disk, 3 for interval
%
%%%%%

	dim = length(x)/2;

	switch domain
	
	case 1
	pts = [cos(x(1:dim,1)) cos(x(dim+1:end,1))];

	case 2
	polar_pts = [abs(cos(x(1:dim,1))) x(dim+1:end,1)];
	[x,y] = to_cartesian(polar_pts(:,1),polar_pts(:,2));
	pts = [x y];

	case 3
	pts = [cos(x)];

	otherwise
	pts = x;

	end

end

function [x,y] = to_cartesian(r,theta)

if nargin < 2
	return
end

if length(r) != length(theta)
	return
end

x = r.*cos(theta);
y = r.*sin(theta);

end
