struct co_ordinate {
double x;
double y;
};
// -----> DESIGN 1
class Land {
public:
Land(std::vector<co_ordinate> co) shape_before_plotting(co) {}
// actions
// creates stage 2
// populates shape_after_plotting_outside_boundary
void do_plotting_of_boundary(size_t off_set){
// logic here
// this off_set is used to know where to add new co_ordinates
// in the boundary
// (the beginning and end of boundary is untouched)
}
// creates stage 3
// populates shape_after_plotting_land
void do_internal_plotting(){
// logic here
// adds new co-ordinate where line intersected inside the land after
// stage 2.
}
// getters
std::vector<co_ordinate> get_shape_before_plotting{
return shape_before_plotting;
}
std::vector<co_ordinate> get_shape_after_plotting_outside_boundary {
return shape_after_plotting_outside_boundary;
}
std::vector<co_ordinate> get_shape_after_plotting_land {
return shape_after_plotting_land;
}
private:
std::vector<co_ordinate> shape_before_plotting;
std::vector<co_ordinate> shape_after_plotting_outside_boundary;
std::vector<co_ordinate> shape_after_plotting_land;
};
int main(){
Land my_land(vec);
// stage 2 populates shape_after_plotting_outside_boundary
my_land.do_plotting_of_boundary();
// stage 3 populates shape_after_plotting_land
my_land.do_internal_plotting();
// get co ordinate here
}
// -----> DESIGN 2
class Land {
public:
Land(std::vector<co_ordinate> co) plotting(co) {}
Land operator=(const Land& other) {// logic for assignment operator}
// actions
// creates stage 2
// populates shape_after_plotting_outside_boundary
void do_plotting_of_boundary(size_t off_set){
// logic here
// this off_set is use know where to add new co_ordinates
// in the boundary
// the beginning and end of boundary is untouched
}
// creates stage 3
// populates shape_after_plotting_land
void do_internal_plotting(){
// logic here
// adds new co-ordinate where line intersected inside the land.
}
// getters
std::vector<co_ordinate> get_shape_co_oridinate(){
return plotting;
}
private:
std::vector<co_ordinate> plotting;
};
int main(){
Land stage_1(vec);
Land stage_2(stage_1);
// plotting is replaced by
// new co-ordinates to store stage 2 co-ordinates
stage_2.do_plotting_of_boundary();
// use assignment operator
//
Land stage_3(stag_2);
// plotting is replaced by
// new co-ordinates to store stage 3 co-ordinates
stage_3.do_internal_plotting();
// get co ordinate here
// Now to get different co-ordinate of stage 1
//
std::vector<co_ordinate> hold_stage_1_co_ordinate = stage_1.get_shape_co_oridinate();
// Now to get different co-ordinate of stage 2
//
std::vector<co_ordinate> hold_stage_2_co_ordinate = stage_2.get_shape_co_oridinate();
// Now to get different co-ordinate of stage 3
//
std::vector<co_ordinate> hold_stage_3_co_ordinate = stage_3.get_shape_co_oridinate();
}
I am working on project where we get land and we plot them. We represent land in x, y co-ordinate system.
stage 1 (Coarsed representation) :
For sake of simplicity lets say land we get have four boundaries.
curve boundaries : The boundaries can be curved so to represent curved boundaries we require more co-ordinate.
straight boundaries : To represent straight boundaries only two co_ordinate is sufficient.
stage 2 (Fine representation) :
Once we get the land we then divide the boundary (line segment) at certain interval. Let say at lenght of 5 meter. This will process increse the number of co_ordinate the land used to reprsent.
stage 3 (Fine and Internal co-ordinate representation) :
In this representation we draw lines between co-ordinate on the boundary from Fine representation and add new co-ordinate that intersected inside the land.
I need to save all the co_ordinate that reprsents the land.
My question is :
Do you think the way I am storing the co_ordinate in Design 1 is good design? I am doubting my self because the API design seems too verbose and probably inconsistant.
That is why I made Desing 2 whose API is simple
std::vector<co_ordinate> get_shape_co_ordinate();
But in this design I have to mange multiple object. What do you think is the correct design ? Is there better design then this?
do_plotting_of_boundary()
anddo_internal_plotting()
methods returnvoid
, why are you assigning them to variables? What are you trying to accomplish?private:
when you didn't usepublic:
before, as the default visibility for class members is private.