function Directions = scaleDirections(Directions,optimState)

% Scale search directions used in patternsearch.

%   Copyright 2022 The MathWorks, Inc.

if isempty(Directions)
    return;
end
coordinates = strcmp(optimState.NUPS.CurrentBasisType, 'coordinates');
noConstr = ~strcmp(optimState.linconstrtype,'linearconstraints');
if coordinates && noConstr
    % This case is straightforward because all the directions are coordinates
    Directions = optimState.DirGenerator.scale.*Directions;
    return;
end

% Coordinate directions (can be part of ortho, tangent set)
coordDirs = sum(abs(Directions) > eps) == 1;
Directions(:,coordDirs) = optimState.DirGenerator.scale.*Directions(:,coordDirs);

% Other directions are scaled by a scalar
Directions(:,~coordDirs) = optimState.DirGenerator.MeshScaleFactor*Directions(:,~coordDirs);

