-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuTriangle.pas
51 lines (41 loc) · 1.26 KB
/
uTriangle.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
unit uTriangle;
interface
type
Shapes = (Equilateral, Isosceles, Scalene);
Triangle = class
class function Sides(AShapeName : Shapes; ASide1, ASide2, ASide3 : single) : boolean; static;
end;
implementation
uses
System.Generics.Collections;
class function Triangle.Sides(AShapeName : Shapes; ASide1, ASide2, ASide3 : single) : boolean;
var
SidesList : TArray<single>;
begin
// Default value for Result
Result := FALSE;
SidesList := [ASide1, ASide2, ASide3];
System.Generics.Collections.TArray.Sort<single>(SidesList);
// Not a "real" triangle case
if (0 >= ASide1) or (0 >= ASide2) or (0 >= ASide3) then
exit;
// "Opened" triangle case
if (SidesList[0] + SidesList[1]) < SidesList[2] then
exit;
case (AShapeName) of
Equilateral :
if (ASide1 = ASide2) and (ASide2 = ASide3) then
Result := TRUE;
Isosceles :
begin
if (ASide1 = ASide2) or (ASide2 = ASide3) or (ASide1 = ASide3) then
Result := TRUE;
end;
Scalene :
begin
if (ASide1 <> ASide2) and (ASide2 <> ASide3) and (ASide1 <> ASide3) then
Result := TRUE;
end;
end;
end;
end.