function removeEdge(this,iElement)
% Method to delete edge from constraint object

%   Author: A. Stothert 
%   Copyright 1986-2004 The MathWorks, Inc.
%   $Revision: 1.1.6.1 $ $Date: 2004/12/10 19:32:18 $

%Only edge if have valid constraint
if ~this.isValid
   return
end

%If no edge specified use selected edge
if nargin < 2, iElement = this.SelectedEdge; end

nConstr = size(this.xCoords,1);

%Temporarilty turn off any listeners 
set(this.Listeners,'Enable','off')

%Remove the the selected edge from the x, y, and linked lists
this.xCoords = [...
   this.xCoords(1:iElement-1,:); ...
   this.xCoords(iElement+1:end,:)];
this.yCoords = [...
   this.yCoords(1:iElement-1,:); ...
   this.yCoords(iElement+1:end,:)];

%Update the Linked Elements
if iElement < nConstr
   this.Linked = [...
      this.Linked(1:iElement-1,:); ...
      this.Linked(iElement+1:end,:)];
else
   this.Linked = this.Linked(1:iElement-2,:);
end

%Update the weight vector
this.Weight = [...
   this.Weight(1:iElement-1); ...
   this.Weight(iElement+1:end)];

%Update the remaining edges to cover the removed edge
iElement = max(1,iElement-1);
switch this.Orientation
   case 'horizontal'
      if iElement < nConstr-1
         this.xCoords(iElement,2) = this.xCoords(iElement+1,1);
      end
   case 'vertical'
      if iElement < nConstr-1
         this.yCoords(iElement,2) = this.yCoords(iElement+1,1);
      end
   case 'both'
      if iElement < nConstr-1
         this.xCoords(iElement,2) = this.xCoords(iElement+1,1);
         this.yCoords(iElement,2) = this.yCoords(iElement+1,1);
      end
end

%Update the selected edge
this.SelectedEdge = max(iElement(1)-1,1);

%Turn any listeners back on
set(this.Listeners,'Enable','on')

%Call superclass update method to re-render
this.update;
