user1487551
user1487551

Reputation: 411

data structure for line segment splitting and merging

I am writing a Qt application to enable generation of signal files using a GUI. The GUI has a canvas that allows a user to draw a new signal. Id like a signal to be defined as a set of contiguous line segments where each segment can be shifted up or down to shift the signal up or down.

I am trying to figure out the best data structure to represent the signal that will allow dynamic change in number of line segments while keeping total signal length the same, i.e. a user can choose the granularity at which she can change the signal. This would mean there needs to be a dynamic data structure that can add/remove and more importantly split and merge line segments.

Need some pointers at what type of data structure might be best.

thanks

Upvotes: 0

Views: 649

Answers (1)

Will
Will

Reputation: 75665

You typically don't need a complex recursive data-structure to store a path. Just use a normal dynamic array of points.

Rendering costs will completely dominate; the cost of walking an array to determine its length, and to validate if an insertion or deletion is legal etc is trivial in comparison.

Upvotes: 1

Related Questions