lundi 25 juin 2018

How can I split "Segment" to two "Segments"? c++

given the following classes:

#include <vector>

using std::vector;

enum TypeSeg {
    OPEN, CLOSE, CLOSE_LEFT, CLOSE_RIGHT
};

template<class T>
class Segment {
    T left;
    T right;
    TypeSeg typeS;
public:
    Segment(T left, T right, TypeSeg typeS) :
            left(left), right(right), typeS(typeS) {
    }
    //.....
};

template<class T>
class SegCollection {
    vector<Segment<T>> segments;
public:
//.....
};

So that Segment describes segment ?left, right? while:
if typeS==OPEN so : (left,right).
if typeS==CLOSE so : [left,right].
if typeS==CLOSE_LEFT so : [left,right).
if typeS==CLOSE_RIGHTso : (left,right].

and SegCollection describes collection of segments so that:
The SegCollection no contains two same segments , and no contains two segments with intersect (it will contain the union of them instead) and even no contains two segments like that: [1,4) and [4,5) (for example) , but, it will contain [1,5).

How can I implement operator-() for SegCollection that delete segment from SegCollection so that: this segment not must be in SegCollection, but, all the points (from all the segments in SegCollection) that exists in SegCollection and in the deleted segment will be removed from the segments that exists in SegCollection.

For example: given: [1,7] , [9,12] , if we will remove (2,5) , so we will get: [1,2] , [5,7] , [9,12].

I don't know (I thought about it some hours..) how can I treat in the case that I need to split segment following remove of segment (like [1,7] in the example , that changed to [1,2] , [5,7])?

Note: Segment is a template-class because that it's can be from (int, int) , (float,float) e.g.

Aucun commentaire:

Enregistrer un commentaire