Skip to content

Commit ca1f6f4

Browse files
authored
Merge pull request #371 from godardma/codac2_dev
[graphics] set_axes with a bounding box
2 parents e876589 + 720d8fe commit ca1f6f4

8 files changed

Lines changed: 59 additions & 17 deletions

File tree

doc/manual/development/changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
Changelog
44
=========
55

6+
Pull Request from godardma (17/04/26)
7+
-------------------------------------
8+
69

710
Commit 52b81c8 ([cmake] warning for Doxygen version)
811
----------------------------------------------------
912

13+
set_axes change for Figure2D
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
16+
Since this PR, a bounding box can be passed to the set_axes method to specify the ranges of the x and y axes.
17+
The old method with ``axis(id,Interval)`` still works
18+
1019
Python binding build requirement
1120
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1221

doc/manual/manual/visualization/figures.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,17 @@ Once created, the properties of a Figure2D object can be modified using the foll
106106
.. code-tab:: py
107107

108108
fig.set_window_properties([50,50],[500,500]) # set the window position and size
109-
fig.set_axes(axis(0,[-10,10]), axis(1,[-10,10])) # set the x-axis index to 0 and its range to [-10,10], same for y with index 1
109+
fig.set_axes([[-15,5],[-10,10]]) # set the x-axis range to [-15,5] and y-axis range to [-10,10]
110110

111111
.. code-tab:: c++
112112

113113
fig.set_window_properties({50,50},{500,500}); // set the window position and size
114-
fig.set_axes(axis(0,{-10,10}), axis(1,{-10,10})); // set the x-axis index to 0 and its range to [-10,10], same for y with index 1
114+
fig.set_axes({{-15,5},{-10,10}}); // set the x-axis range to [-15,5] and y-axis range to [-10,10]
115115

116116
.. code-tab:: matlab
117117

118-
fig.set_window_properties(Vector({50,50}),Vector({500,500})); % position, window size
119-
fig.set_axes(axis(1,Interval(-10,10)), axis(2,Interval(-10,10))); % (axis_id,[range_of_values_on_this_axis])
118+
fig.set_window_properties(Vector({50,50}),Vector({500,500})); % set the window position and size
119+
fig.set_axes(IntervalVector({{-15,5},{-10,10}})); % set the x-axis range to [-15,5] and y-axis range to [-10,10]
120120

121121
The same methods can be applied on the DefaultFigure object.
122122

@@ -125,17 +125,17 @@ The same methods can be applied on the DefaultFigure object.
125125
.. code-tab:: py
126126

127127
DefaultFigure.set_window_properties([50,50],[500,500]) # set the window position and size
128-
DefaultFigure.set_axes(axis(0,[-10,10]), axis(1,[-10,10])) # set the x-axis index to 0 and its range to [-10,10], same for y with index 1
128+
DefaultFigure.set_axes([[-15,5],[-10,10]]) # set the x-axis range to [-15,5] and y-axis range to [-10,10]
129129

130130
.. code-tab:: c++
131131

132132
DefaultFigure::set_window_properties({50,50},{500,500}); // set the window position and size
133-
DefaultFigure::set_axes(axis(0,{-10,10}), axis(1,{-10,10})); // set the x-axis index to 0 and its range to [-10,10], same for y with index 1
133+
DefaultFigure::set_axes({{-15,5},{-10,10}}); // set the x-axis range to [-15,5] and y-axis range to [-10,10]
134134

135135
.. code-tab:: matlab
136136

137137
DefaultFigure().set_window_properties(Vector({50,50}),Vector({500,500})); % set the window position and size
138-
DefaultFigure().set_axes(axis(1,Interval(-10,10)), axis(2,Interval(-10,10))); % set the x-axis index to 0 and its range to [-10,10], same for y with index 1
138+
DefaultFigure().set_axes(IntervalVector({{-15,5},{-10,10}})); % set the x-axis range to [-15,5] and y-axis range to [-10,10]
139139

140140

141141
Many properties have an associated getter :

examples/00_graphics/graphic_examples.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ int main(){
3030
// For IPE, it generates a file named "My figure 1.xml" that can be edited with IPE, and converted to PDF
3131

3232
fig1->set_window_properties({50,50},{500,500}); // position, window size
33-
fig1->set_axes(axis(0,{-10,10}), axis(1,{-10,10})); // (axis_id,{range_of_values_on_this_axis})
33+
fig1->set_axes(IntervalVector::constant(2,{-10,10})); // bounding box
3434
fig1->draw_box({{-1,1},{-1,1}},{Color::green(),Color::red(0.2)}); // drawing a green box with red opacity values inside
3535
fig1->draw_circle({1,1},0.5,Color({255,155,5})); // drawing a circle at (1,1) of radius 0.5 with a custom RGB color
3636
fig1->draw_ring({1,1},{4,6},Color::red()); // drawing a ring at (1,1) of radius {4,6} with a predefined red color
3737

3838
std::shared_ptr<codac2::Figure2D> fig2 = std::make_shared<Figure2D>("My Figure 2",GraphicOutput::VIBES|GraphicOutput::IPE);
39-
fig2->set_axes(axis(0,{-1,5}), axis(1,{-1,5}));
39+
fig2->set_axes(axis(0,{-1,5}), axis(1,{-1,5})); // (axis_id,{range_of_values_on_this_axis})
4040
fig2->set_window_properties({250,250},{500,500});
4141

4242
// The previously declared figure "fig2" can now be used as a DefaultFigure

examples/00_graphics/graphic_examples.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
% For IPE, it generates a file named "My figure 1.xml" that can be edited with IPE, and converted to PDF
2424

2525
fig1.set_window_properties(Vector({50,50}),Vector({500,500})); % position, window size
26-
fig1.set_axes(axis(1,Interval(-10,10)), axis(2,Interval(-10,10))); % (axis_id,[range_of_values_on_this_axis])
26+
fig1.set_axes(IntervalVector().constant(2,Interval(-10,10))); % bounding box
2727
fig1.draw_box(IntervalVector({{-1,1},{-1,1}}),StyleProperties({Color().green(),Color().red(0.2)})); % drawing a green box with red opacity values inside
2828
fig1.draw_circle(Vector({1,1}),0.5,Color({255,155,5})); % drawing a circle at (1,1) of radius 0.5 with a custom RGB color
2929
fig1.draw_ring(Vector({1,1}),Interval(4,6),Color().red()); % drawing a ring at (1,1) of radius [4,6] with a predefined red color
3030

3131
fig2 = Figure2D("My figure 2", GraphicOutput().VIBES.union(GraphicOutput().IPE));
32-
fig2.set_axes(axis(1,Interval(-1,5)), axis(2,Interval(-1,5)));
32+
fig2.set_axes(axis(1,Interval(-1,5)), axis(2,Interval(-1,5))); % (axis_id,[range_of_values_on_this_axis])
3333
fig2.set_window_properties(Vector({250,250}),Vector({500,500}));
3434

3535
% The previously declared figure "fig2" can now be used as a DefaultFigure

examples/00_graphics/graphic_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
# For IPE, it generates a file named "My figure 1.xml" that can be edited with IPE, and converted to PDF
2424

2525
fig1.set_window_properties([50,50],[500,500]) # position, window size
26-
fig1.set_axes(axis(0,[-10,10]), axis(1,[-10,10])) # (axis_id,[range_of_values_on_this_axis])
26+
fig1.set_axes(IntervalVector.constant(2,[-10,10])) # bounding box
2727
fig1.draw_box([[-1,1],[-1,1]],[Color.green(),Color.red(0.2)]) # drawing a green box with red opacity values inside
2828
fig1.draw_circle([1,1],0.5,Color([255,155,5])) # drawing a circle at (1,1) of radius 0.5 with a custom RGB color
2929
fig1.draw_ring([1,1],[4,6],Color.red()) # drawing a ring at (1,1) of radius [4,6] with a predefined red color
3030

3131
fig2 = Figure2D("My figure 2", GraphicOutput.VIBES | GraphicOutput.IPE)
32-
fig2.set_axes(axis(0,[-1,5]), axis(1,[-1,5]))
32+
fig2.set_axes(axis(0,[-1,5]), axis(1,[-1,5])) # (axis_id,[range_of_values_on_this_axis])
3333
fig2.set_window_properties([250,250],[500,500])
3434

3535
# The previously declared figure "fig2" can now be used as a DefaultFigure

python/src/graphics/figures/codac2_py_Figure2D.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ void export_Figure2D(py::module& m)
7878

7979
.def("axes", &Figure2D::axes,
8080
CONST_VECTOR_FIGUREAXIS_REF_FIGURE2D_AXES_CONST)
81-
82-
.def("set_axes", &Figure2D::set_axes,
81+
82+
.def("set_axes", (Figure2D& (Figure2D::*)(const FigureAxis&, const FigureAxis&)) &Figure2D::set_axes,
8383
FIGURE2D_REF_FIGURE2D_SET_AXES_CONST_FIGUREAXIS_REF_CONST_FIGUREAXIS_REF,
8484
"axis1"_a, "axis2"_a)
85+
86+
.def("set_axes", (Figure2D& (Figure2D::*)(const IntervalVector&)) &Figure2D::set_axes,
87+
FIGURE2D_REF_FIGURE2D_SET_AXES_CONST_INTERVALVECTOR_REF,
88+
"bbox"_a)
8589

8690
.def("i", &Figure2D::i,
8791
CONST_INDEX_REF_FIGURE2D_I_CONST)
@@ -321,10 +325,15 @@ void export_Figure2D(py::module& m)
321325

322326
.def_static("set", &DefaultFigure::set,
323327
STATIC_VOID_DEFAULTFIGURE_SET_SHARED_PTR_FIGURE2D)
324-
325-
.def_static("set_axes", &DefaultFigure::set_axes, py::return_value_policy::reference,
328+
329+
.def_static("set_axes", (Figure2D& (*)(const FigureAxis&, const FigureAxis&)) &DefaultFigure::set_axes, py::return_value_policy::reference,
326330
STATIC_FIGURE2D_REF_DEFAULTFIGURE_SET_AXES_CONST_FIGUREAXIS_REF_CONST_FIGUREAXIS_REF,
327331
"axis1"_a, "axis2"_a)
332+
333+
.def_static("set_axes", (Figure2D& (*)(const IntervalVector&)) &DefaultFigure::set_axes, py::return_value_policy::reference,
334+
STATIC_FIGURE2D_REF_DEFAULTFIGURE_SET_AXES_CONST_INTERVALVECTOR_REF,
335+
"bbox"_a)
336+
328337

329338
.def_static("set_window_properties", &DefaultFigure::set_window_properties,
330339
STATIC_VOID_DEFAULTFIGURE_SET_WINDOW_PROPERTIES_CONST_VECTOR_REF_CONST_VECTOR_REF)

src/graphics/figures/codac2_Figure2D.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ Figure2D& Figure2D::set_axes(const FigureAxis& axis1, const FigureAxis& axis2)
6060
return *this;
6161
}
6262

63+
Figure2D& Figure2D::set_axes(const IntervalVector& bbox)
64+
{
65+
assert_release(bbox.size()==2);
66+
return set_axes(axis(0,bbox[0]),axis(1,bbox[1]));
67+
}
68+
6369
const Index& Figure2D::i() const
6470
{
6571
return axes()[0].dim_id;

src/graphics/figures/codac2_Figure2D.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ namespace codac2
126126
*/
127127
Figure2D& set_axes(const FigureAxis& axis1, const FigureAxis& axis2);
128128

129+
/**
130+
* \brief Setter for the axes of the figure
131+
*
132+
* \param bbox Bounding box
133+
*/
134+
Figure2D& set_axes(const IntervalVector& bbox);
135+
129136
/**
130137
* \brief Getter for the index of the horizontal axis
131138
*
@@ -666,6 +673,17 @@ namespace codac2
666673
auto_init();
667674
return selected_fig()->set_axes(axis1,axis2);
668675
}
676+
677+
/**
678+
* \brief Setter for the axes of the figure
679+
*
680+
* \param bbox Bounding box
681+
*/
682+
static Figure2D& set_axes(const IntervalVector& bbox)
683+
{
684+
auto_init();
685+
return selected_fig()->set_axes(bbox);
686+
}
669687

670688
/**
671689
* \brief Setter for the position and size of the window

0 commit comments

Comments
 (0)