def auto_locate_connectors(shapes, shape_hash)
      # Valid connector shapes.
      connector_shapes = {
        :straightConnector => 1,
        :Connector         => 1,
        :bentConnector     => 1,
        :curvedConnector   => 1,
        :line              => 1
      }

      shape_base = @type.chop.to_sym # Remove the number of segments from end of type.
      @connect = connector_shapes[shape_base] ? 1 : 0
      return if @connect == 0

      # Both ends have to be connected to size it.
      return if @start == 0 && @end == 0

      # Both ends need to provide info about where to connect.
      return if @start_side == 0 && @end_side == 0

      sid = @start
      eid = @end

      slink_id = shape_hash[sid] || 0
      sls      = shapes.fetch(slink_id, Shape.new)
      elink_id = shape_hash[eid] || 0
      els      = shapes.fetch(elink_id, Shape.new)

      # Assume shape connections are to the middle of an object, and
      # not a corner (for now).
      connect_type = @start_side + @end_side
      smidx        = sls.x_offset + sls.width / 2
      emidx        = els.x_offset + els.width / 2
      smidy        = sls.y_offset + sls.height / 2
      emidy        = els.y_offset + els.height / 2
      netx         = (smidx - emidx).abs
      nety         = (smidy - emidy).abs

      if connect_type == 'bt'
        sy = sls.y_offset + sls.height
        ey = els.y_offset

        @width = (emidx - smidx).to_i.abs
        @x_offset = [smidx, emidx].min.to_i
        @height =
          (els.y_offset - (sls.y_offset + sls.height)).to_i.abs
        @y_offset =
          [sls.y_offset + sls.height, els.y_offset].min.to_i
        @flip_h = smidx < emidx ? 1 : 0
        @rotation = 90

        if sy > ey
          @flip_v = 1

          # Create 3 adjustments for an end shape vertically above a
          # start @ Adjustments count from the upper left object.
          if @adjustments.empty?
            @adjustments = [-10, 50, 110]
          end
          @type = 'bentConnector5'
        end
      elsif connect_type == 'rl'
        @width =
          (els.x_offset - (sls.x_offset + sls.width)).to_i.abs
        @height = (emidy - smidy).to_i.abs
        @x_offset =
          [sls.x_offset + sls.width, els.x_offset].min
        @y_offset = [smidy, emidy].min

        @flip_h = 1 if smidx < emidx && smidy > emidy
        @flip_h = 1 if smidx > emidx && smidy < emidy

        if smidx > emidx
          # Create 3 adjustments for an end shape to the left of a
          # start @
          if @adjustments.empty?
            @adjustments = [-10, 50, 110]
          end
          @type = 'bentConnector5'
        end
      end
    end
def auto_locate_connectors(shapes, shape_hash)
      # Valid connector shapes.
      connector_shapes = {
        :straightConnector => 1,
        :Connector         => 1,
        :bentConnector     => 1,
        :curvedConnector   => 1,
        :line              => 1
      }

      shape_base = @type.chop.to_sym # Remove the number of segments from end of type.
      @connect = connector_shapes[shape_base] ? 1 : 0
      return if @connect == 0

      # Both ends have to be connected to size it.
      return if @start == 0 && @end == 0

      # Both ends need to provide info about where to connect.
      return if @start_side == 0 && @end_side == 0

      sid = @start
      eid = @end

      slink_id = shape_hash[sid] || 0
      sls      = shapes.fetch(slink_id, Shape.new)
      elink_id = shape_hash[eid] || 0
      els      = shapes.fetch(elink_id, Shape.new)

      # Assume shape connections are to the middle of an object, and
      # not a corner (for now).
      connect_type = @start_side + @end_side
      smidx        = sls.x_offset + sls.width / 2
      emidx        = els.x_offset + els.width / 2
      smidy        = sls.y_offset + sls.height / 2
      emidy        = els.y_offset + els.height / 2
      netx         = (smidx - emidx).abs
      nety         = (smidy - emidy).abs

      if connect_type == 'bt'
        sy = sls.y_offset + sls.height
        ey = els.y_offset

        @width = (emidx - smidx).to_i.abs
        @x_offset = [smidx, emidx].min.to_i
        @height =
          (els.y_offset - (sls.y_offset + sls.height)).to_i.abs
        @y_offset =
          [sls.y_offset + sls.height, els.y_offset].min.to_i
        @flip_h = smidx < emidx ? 1 : 0
        @rotation = 90

        if sy > ey
          @flip_v = 1

          # Create 3 adjustments for an end shape vertically above a
          # start @ Adjustments count from the upper left object.
          if @adjustments.empty?
            @adjustments = [-10, 50, 110]
          end
          @type = 'bentConnector5'
        end
      elsif connect_type == 'rl'
        @width =
          (els.x_offset - (sls.x_offset + sls.width)).to_i.abs
        @height = (emidy - smidy).to_i.abs
        @x_offset =
          [sls.x_offset + sls.width, els.x_offset].min
        @y_offset = [smidy, emidy].min

        @flip_h = 1 if smidx < emidx && smidy > emidy
        @flip_h = 1 if smidx > emidx && smidy < emidy

        if smidx > emidx
          # Create 3 adjustments for an end shape to the left of a
          # start @
          if @adjustments.empty?
            @adjustments = [-10, 50, 110]
          end
          @type = 'bentConnector5'
        end
      end
    end
Re-size connector shapes if they are connected to other shapes.