function [G,x] = planerot(x)
%MATLAB Code Generation Library Function

%   Copyright 1984-2014 The MathWorks, Inc.
%#codegen

eml_invariant(nargin == 1, ...
    'MATLAB:minrhs');
eml_invariant(isa(x,'float'), ...
    'Coder:toolbox:unsupportedClass','planerot',class(x));
eml_invariant(eml_is_const(size(x)), ...
    'Coder:toolbox:InputMustBeFixedSize', 'x', ...    
    'IfNotConst','Fail');
eml_invariant(numel(x) == 2 && size(x,1) == 2 && size(x,2) == 1, ...
    'Coder:toolbox:planerot_4', ...
    'IfNotConst','Fail');
if x(2) ~= 0
    r = norm(x);
    G = coder.internal.div([x';-x(2),x(1)],r);
    x = [r; 0];
else
    G = eye(2,class(x));
end
