A Question about struct

Sorry, I’m new to Julia and I have a little conflict with the structures, for example if I have 2 structures corresponding to a polygon and a segment.

tstruct segment
    first_vertex::Array
    second_vertex::Array
    long::Real
end
struct poligon
    vertex::Union{Array, Array, Array}
    segment::Union{Array, Array, Array}
    perimetrer::Real
    area::Real
end

And I would like to make a couple of functions that take as arguments for Segment, the initial vertex and the final vertex of a segment, and for the Polygon function, that take as arguments an array of vertices.
How i do that?

It’s not clear whether you want to create constructors or functions that operate on the struct data. For the latter, write your function to accept the struct type as an argument, and the function would access the fields of the argument. Also, Union{Array, Array, Array} makes no sense. Union means that a variable of the union type may reference a value of any of the parameter types, but these are all the same.

2 Likes