-如何避免这样的字符串,有没什么好的思路?[请问]

----------------如何处理这样的字符串,有没什么好的思路?-----------------[请教]
本帖最后由 cowbo2 于 2013-11-21 19:37:07 编辑
有一个数组记录着一堆座标,这些座标记录的是一个图上多个形状的像素点,
而这些路径有相连,也有断开的

我的代码已经能找出相邻的点,但问题是:在输出时无法将其分割开.

现在如何求出,将座标点输出到STringlist,使不同组的座标用空行分开?



就是要把这些字符串进行对比,相近的就放在一起,不相近的组空行分开,再放另一组?

有没什么好的思路?



测试数据:
1,2
1,3
2,4
2,5

需要输出:
1,2
1,3

2,4
2,5





unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
    TPixel =record    //定义点类型
          x,y:integer;
end;
        
type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  PL:array of TPoint;

implementation

{$R *.dfm}
//判断数据是否在于数组中
function PointInPoint(p1:TPoint;p2:array of TPoint):Boolean;
var
    x,y:Integer;
begin
    Result:=False;
    for x := 0 to Length(p2) - 1 do
    begin
        if p1.X=p2[x].X then
        if p1.y=p2[x].y then
        begin
            Result:=true;
            Break;
        end;
    end;       
    
end;
//去掉重复
Function RemoveDuplicates(const stringList : TStringList):TStringList;
 var
   cnt: Integer;
 begin
   stringList.Sort;
   Result := TStringList.Create;
   Result.Sorted := True;
   Result.Duplicates := dupIgnore;
   Result.BeginUpdate;
   for cnt := 0 to stringList.Count - 1 do
     Result.Add(stringList[cnt]) ;
   Result.EndUpdate;

 end;
 



{广泛搜索,将像索点的所有连接点检测出来}
function CutPoint(dl: array of TPoint): TStringList;
const
  direct :array [1..4,1..2] of shortint =((0,-1),(0,1),(-1,0),(1,0)); //方向增量
var
   //队列
  Star,Ende,i:Integer;  //Star为队首指针,Ende为队尾指针
  tmp,tmp2:TPoint;
begin
  Star:=0;  
  Ende:=Length(dl); 

  //FillChar(dl,sizeof(dl),0); //初始化队列
  
  result := TStringList.Create;
  while Star<>Ende do //当 Star<>Ende时执行以下代码
  begin     
    tmp:=dl[Star];  //将第一个写入tmp
    Inc(Star);  //不断加1向后循环
    for i:= 1 to 4 do  //遍历四个方向
    begin
        tmp2.X :=tmp.X+direct[i,1];
        tmp2.Y :=tmp.Y+direct[i,2];
        if (tmp2.X<0)or(tmp2.Y<0) then //如果越界则跳过
            continue; 
             
        if not PointInPoint(tmp2,dl) then  //如果不存在于数组中则去跳过
            continue;  
        

        Result.Add(IntToStr(tmp2.x)+','+IntToStr(tmp2.y));

    end; 
  end;
  Result.Sort;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
    i,k:Integer;
    s1:string;
begin

    SetLength(pl,memo1.Lines.Count);
    for I := 0 to memo1.Lines.Count - 1 do
    begin                               
        s1:=Trim(Memo1.Lines.Strings[i]);
        k:=Pos(',',s1);