Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure CheckIsLine(A: TArr; var IsCorrect: Boolean; var Error: String);
- var
- Counter, I: Integer;
- begin
- I := 0;
- Counter := 0;
- while (IsCorrect) and (Counter < 3) and (I < High(A)) do
- begin
- if A[I] = A[I + 1] then
- Inc(Counter)
- else
- Dec(Counter);
- if (Counter = 3) then
- begin
- IsCorrect := false;
- Error := 'Данная фигура не является многоугольником. ';
- end;
- Inc(I);
- end;
- end;
- procedure CheckIsPolygon(X, Y: TArr; Size: Integer; var IsCorrect: Boolean; var Error: String);
- var
- I, J, K: Integer;
- TempX, TempY: TArr;
- Res1, Res2: Double;
- begin
- //чересчур мудрённый
- SetLength(TempX, Size + 2);
- SetLength(TempY, Size + 2);
- for I := 0 to High(X) do
- begin
- TempX[I] := X[I];
- TempY[I] := Y[I];
- end;
- TempX[Size] := X[0];
- TempX[Size + 1] := X[1];
- TempY[Size] := Y[0];
- TempY[Size + 1] := Y[1];
- CheckIsLine(TempX, IsCorrect, Error);
- CheckIsLine(TempY, IsCorrect, Error);
- I := 0;
- while (IsCorrect) and (I < Size) do
- begin
- if (TempX[I + 1] = TempX[I]) then
- begin
- if (TempY[I + 1] = TempY[I]) then
- begin
- IsCorrect := false;
- Error := 'Введены две одинаковые координаты подряд. ';
- end
- else
- begin
- Res1 := TempX[I + 2] - TempX[I];
- Res2 := (TempY[I + 2] - TempY[I]) / (TempY[I + 1] - TempY[I]);
- end;
- end
- else
- begin
- if (TempY[I + 1] = TempY[I]) then
- begin
- Res1 := TempX[I + 2] - TempX[I] / (TempX[I + 1] - TempX[I]);
- Res2 := (TempY[I + 2] - TempY[I]);
- end
- else
- begin
- Res1 := TempX[I + 2] - TempX[I] / (TempX[I + 1] - TempX[I]);
- Res2 := (TempY[I + 2] - TempY[I]) / (TempY[I + 1] - TempY[I]);
- end;
- end;
- if (IsCorrect) and (res1 = res2) then
- begin
- IsCorrect := false;
- Error := Error + 'Данная совокупность точек не является многоугольником. ';
- end;
- Inc(I);
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement