One of the main advantages of using a triangle class is that keeps information hidden and also helps by doing things like calculating the length of the sides for you.

Don't expect this to be used by anyone, just looked at.

Triangle

var

Vertex/vertex1

Vertex/vertex2

Vertex/vertex3

Side/side1

Side/side2

Side/side3

New(Vertex/VERTEX1,Vertex/VERTEX2,Vertex/VERTEX3)

..()

if(args.len != 3) return

vertex1 = VERTEX1

vertex2 = VERTEX2

vertex3 = VERTEX3

side1 = new/Side(vertex1,vertex2)

side2 = new/Side(vertex2,vertex3)

side3 = new/Side(vertex3,vertex1)

proc

perimeter()

return side1.length + side2.length + side3.length

toText()

var/text = "Triangle ID:[ID] {\n"

text += "\tvertex1 = [vertex1.toText()]\n"

text += "\tvertex2 = [vertex2.toText()]\n"

text += "\tvertex3 = [vertex3.toText()]\n\n"

text += "\tside1 = [side1.toText()]\n"

text += "\tside2 = [side2.toText()]\n"

text += "\tside3 = [side3.toText()]\n"

text += "}"

return text

Side

var

Vertex/vertex1

Vertex/vertex2

length = 0

New(VERTEX1, VERTEX2)

..()

if(args.len != 2) return

vertex1 = VERTEX1

vertex2 = VERTEX2

calcLength()

proc

calcLength()

var/sideA = vertex1.x - vertex2.x

var/sideB = vertex1.y - vertex2.y

length = sqrt(sideA ** 2 + sideB ** 2)

toText()

return "Side ID:[ID] { [vertex1.toText()] >> [vertex2.toText()] = [length] }"

Vertex

var

x = 0

y = 0

New(X,Y)

..()

x = X

y = Y

proc

toText()

return "Vertex ID:[ID] { ([x],[y]) }"

var/currentID = 0

datum

var/ID = 0

New()

ID = currentID

currentID ++

Example Output:

Triangle ID:4 {

vertex1 = Vertex ID:1 { (2,2) }

vertex2 = Vertex ID:2 { (4,4) }

vertex3 = Vertex ID:3 { (5,0) }

side1 = Side ID:5 { Vertex ID:1 { (2,2) } >> Vertex ID:2 { (4,4) } = 2.82843 }

side2 = Side ID:6 { Vertex ID:2 { (4,4) } >> Vertex ID:3 { (5,0) } = 4.12311 }

side3 = Side ID:7 { Vertex ID:3 { (5,0) } >> Vertex ID:1 { (2,2) } = 3.60555 }

}

calcLength()is unnecessary. Squaring a real number always results in a positive number.