% Input:
% L: Matrix (directions row-wise)
% Ijump: vector (containing the ids of the sets to calculate the
%                intersection with)
% omegas: ~ DEPRECATED cell array of function handles (flowpipe)
% options: cell array
% results: matrix (containing the evaluation results in directions from L)
% transition: struct
% additional_dimension_constraints: vector (values specifying the fixed
%                                   constraints in the additional dimension)

% Output:
% intersectedresults: matrix

% Description:
% intersects the flowpipe with guard and invariants relevant for the
% "transition". Can only be used with the matrix representation and
% implements the same procedure as intersectFlowpipe with fast_intersection
% parameter (but more efficient)

function [intersectedresults] = intersectFlowpipeFast(L,Ijump,~,options,results,transition,additional_dimension_constraints)
intersectedresults = results(:,Ijump);

accesssize = 1:size(intersectedresults,1);

intersectedresults = [intersectedresults;repmat(additional_dimension_constraints,1,size(intersectedresults,2))];
if ~isempty(additional_dimension_constraints)
    extendedL = [L; [zeros(2,size(L,2)-1) [1;-1] ]];
else
    extendedL = L;
end;

for i=1:1:size(intersectedresults,2)

   intersectedresults(accesssize,i) = min(transition.sortedValues,intersectedresults(accesssize,i));
    
    omega = calcPolytopeSP(extendedL,intersectedresults(:,i),options{2},options{3},zeros(size(L,2),1),[],[]);
    intersectedresults(accesssize,i) = sptotemplatepolyhedra(omega,L);                
end;
intersectedresults = intersectedresults(accesssize,:);