Mercurial > hg > octave-max
comparison src/graphics.cc @ 14429:eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
* data.cc, defaults.cc, dirfns.cc, file-io.cc, graphics.cc, mappers.cc,
oct-map.cc, octave.cc, ov-base.cc, ov-bool-mat.cc, ov-cell.cc,
ov-fcn-handle.cc, ov-fcn-inline.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc,
ov-int64.cc, ov-int8.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-range.cc,
ov-re-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-uint16.cc, ov-uint32.cc,
ov-uint64.cc, ov-uint8.cc, ov.cc, pr-output.cc, pt-binop.cc, pt-eval.cc,
pt-idx.cc, pt-mat.cc, sighandlers.cc, strfns.cc, symtab.cc, syscalls.cc,
sysdep.cc, toplev.cc, utils.cc, variables.cc: Update %!tests in src/ directory
with Octave coding conventions.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 04 Mar 2012 12:21:10 -0800 |
parents | 4f160344236a |
children | 008a29999c3d |
comparison
equal
deleted
inserted
replaced
14428:099bd779466c | 14429:eff4a5933e28 |
---|---|
1965 else | 1965 else |
1966 error ("set: invalid number of arguments"); | 1966 error ("set: invalid number of arguments"); |
1967 } | 1967 } |
1968 | 1968 |
1969 /* | 1969 /* |
1970 %!# test set with name, value pairs | 1970 ## test set with name, value pairs |
1971 %!test | 1971 %!test |
1972 %! set(gcf, "visible", "off"); | 1972 %! set (gcf, "visible", "off"); |
1973 %! h = plot (1:10, 10:-1:1); | 1973 %! h = plot (1:10, 10:-1:1); |
1974 %! set (h, "linewidth", 10, "marker", "x"); | 1974 %! set (h, "linewidth", 10, "marker", "x"); |
1975 %! assert (get (h, "linewidth"), 10); | 1975 %! assert (get (h, "linewidth"), 10); |
1976 %! assert (get (h, "marker"), "x"); | 1976 %! assert (get (h, "marker"), "x"); |
1977 */ | 1977 */ |
1978 | 1978 |
1979 // Set properties given in two cell arrays containing names and values. | 1979 // Set properties given in two cell arrays containing names and values. |
1980 void | 1980 void |
1981 graphics_object::set (const Array<std::string>& names, | 1981 graphics_object::set (const Array<std::string>& names, |
2000 break; | 2000 break; |
2001 } | 2001 } |
2002 } | 2002 } |
2003 | 2003 |
2004 /* | 2004 /* |
2005 %!# test set with cell array arguments | 2005 ## test set with cell array arguments |
2006 %!test | 2006 %!test |
2007 %! set (gcf, "visible", "off"); | 2007 %! set (gcf, "visible", "off"); |
2008 %! h = plot (1:10, 10:-1:1); | 2008 %! h = plot (1:10, 10:-1:1); |
2009 %! set (h, {"linewidth", "marker"}, {10, "x"}); | 2009 %! set (h, {"linewidth", "marker"}, {10, "x"}); |
2010 %! assert (get(h, "linewidth"), 10); | 2010 %! assert (get (h, "linewidth"), 10); |
2011 %! assert (get(h, "marker"), "x"); | 2011 %! assert (get (h, "marker"), "x"); |
2012 | 2012 |
2013 %!# test set with multiple handles and cell array arguments | 2013 ## test set with multiple handles and cell array arguments |
2014 %!test | 2014 %!test |
2015 %! set (gcf, "visible", "off"); | 2015 %! set (gcf, "visible", "off"); |
2016 %! h = plot (1:10, 10:-1:1, 1:10, 1:10); | 2016 %! h = plot (1:10, 10:-1:1, 1:10, 1:10); |
2017 %! set (h, {"linewidth", "marker"}, {10, "x"; 5, "o"}); | 2017 %! set (h, {"linewidth", "marker"}, {10, "x"; 5, "o"}); |
2018 %! assert (get (h, "linewidth"), {10; 5}); | 2018 %! assert (get (h, "linewidth"), {10; 5}); |
2019 %! assert (get (h, "marker"), {"x"; "o"}); | 2019 %! assert (get (h, "marker"), {"x"; "o"}); |
2020 %! set (h, {"linewidth", "marker"}, {10, "x"}); | 2020 %! set (h, {"linewidth", "marker"}, {10, "x"}); |
2021 %! assert (get (h, "linewidth"), {10; 10}); | 2021 %! assert (get (h, "linewidth"), {10; 10}); |
2022 %! assert (get (h, "marker"), {"x"; "x"}); | 2022 %! assert (get (h, "marker"), {"x"; "x"}); |
2023 | 2023 |
2024 %!error <set: number of graphics handles must match number of value rows> | 2024 %!error <set: number of graphics handles must match number of value rows> |
2025 %! set (gcf, "visible", "off"); | 2025 %! set (gcf, "visible", "off"); |
2026 %! h = plot (1:10, 10:-1:1, 1:10, 1:10); | 2026 %! h = plot (1:10, 10:-1:1, 1:10, 1:10); |
2027 %! set (h, {"linewidth", "marker"}, {10, "x"; 5, "o"; 7, "."}); | 2027 %! set (h, {"linewidth", "marker"}, {10, "x"; 5, "o"; 7, "."}); |
2028 | 2028 |
2029 %!error <set: number of names must match number of value columns> | 2029 %!error <set: number of names must match number of value columns> |
2030 %! set (gcf, "visible", "off"); | 2030 %! set (gcf, "visible", "off"); |
2031 %! h = plot (1:10, 10:-1:1, 1:10, 1:10); | 2031 %! h = plot (1:10, 10:-1:1, 1:10, 1:10); |
2032 %! set (h, {"linewidth"}, {10, "x"; 5, "o"}); | 2032 %! set (h, {"linewidth"}, {10, "x"; 5, "o"}); |
2033 */ | 2033 */ |
2034 | 2034 |
2035 // Set properties given in a struct array | 2035 // Set properties given in a struct array |
2036 void | 2036 void |
2037 graphics_object::set (const octave_map& m) | 2037 graphics_object::set (const octave_map& m) |
2049 break; | 2049 break; |
2050 } | 2050 } |
2051 } | 2051 } |
2052 | 2052 |
2053 /* | 2053 /* |
2054 %!# test set with struct arguments | 2054 ## test set with struct arguments |
2055 %!test | 2055 %!test |
2056 %! set (gcf, "visible", "off"); | 2056 %! set (gcf, "visible", "off"); |
2057 %! h = plot (1:10, 10:-1:1); | 2057 %! h = plot (1:10, 10:-1:1); |
2058 %! set (h, struct ("linewidth", 10, "marker", "x")); | 2058 %! set (h, struct ("linewidth", 10, "marker", "x")); |
2059 %! assert (get (h, "linewidth"), 10); | 2059 %! assert (get (h, "linewidth"), 10); |
2060 %! assert (get (h, "marker"), "x"); | 2060 %! assert (get (h, "marker"), "x"); |
2061 %! h = plot (1:10, 10:-1:1, 1:10, 1:10); | 2061 %! h = plot (1:10, 10:-1:1, 1:10, 1:10); |
2062 %! set (h, struct ("linewidth", {5, 10})); | 2062 %! set (h, struct ("linewidth", {5, 10})); |
2063 %! assert (get(h, "linewidth"), {10; 10}); | 2063 %! assert (get (h, "linewidth"), {10; 10}); |
2064 */ | 2064 */ |
2065 | 2065 |
2066 // Set a property to a value or to its (factory) default value. | 2066 // Set a property to a value or to its (factory) default value. |
2067 | 2067 |
2068 void | 2068 void |
2099 else | 2099 else |
2100 rep->set (name, val); | 2100 rep->set (name, val); |
2101 } | 2101 } |
2102 | 2102 |
2103 /* | 2103 /* |
2104 %!# test setting of default values | 2104 ## test setting of default values |
2105 %!test | 2105 %!test |
2106 %! set (gcf, "visible", "off"); | 2106 %! set (gcf, "visible", "off"); |
2107 %! h = plot (1:10, 10:-1:1); | 2107 %! h = plot (1:10, 10:-1:1); |
2108 %! set (0, "defaultlinelinewidth", 20); | 2108 %! set (0, "defaultlinelinewidth", 20); |
2109 %! set (h, "linewidth", "default"); | 2109 %! set (h, "linewidth", "default"); |
2110 %! assert (get (h, "linewidth"), 20); | 2110 %! assert (get (h, "linewidth"), 20); |
2111 %! set (h, "linewidth", "factory"); | 2111 %! set (h, "linewidth", "factory"); |
2112 %! assert (get (h, "linewidth"), 0.5); | 2112 %! assert (get (h, "linewidth"), 0.5); |
2113 */ | 2113 */ |
2114 | 2114 |
2115 static double | 2115 static double |
2116 make_handle_fraction (void) | 2116 make_handle_fraction (void) |
2117 { | 2117 { |
3053 return pos; | 3053 return pos; |
3054 } | 3054 } |
3055 | 3055 |
3056 /* | 3056 /* |
3057 %!test | 3057 %!test |
3058 %! set (0, "units", "pixels") | 3058 %! set (0, "units", "pixels"); |
3059 %! sz = get (0, "screensize") - [1, 1, 0, 0]; | 3059 %! sz = get (0, "screensize") - [1, 1, 0, 0]; |
3060 %! dpi = get (0, "screenpixelsperinch"); | 3060 %! dpi = get (0, "screenpixelsperinch"); |
3061 %! set (0, "units", "inches") | 3061 %! set (0, "units", "inches"); |
3062 %! assert (get (0, "screensize"), sz / dpi, 0.5 / dpi) | 3062 %! assert (get (0, "screensize"), sz / dpi, 0.5 / dpi); |
3063 %! set (0, "units", "centimeters") | 3063 %! set (0, "units", "centimeters"); |
3064 %! assert (get (0, "screensize"), sz / dpi * 2.54, 0.5 / dpi * 2.54) | 3064 %! assert (get (0, "screensize"), sz / dpi * 2.54, 0.5 / dpi * 2.54); |
3065 %! set (0, "units", "points") | 3065 %! set (0, "units", "points"); |
3066 %! assert (get (0, "screensize"), sz / dpi * 72, 0.5 / dpi * 72) | 3066 %! assert (get (0, "screensize"), sz / dpi * 72, 0.5 / dpi * 72); |
3067 %! set (0, "units", "normalized") | 3067 %! set (0, "units", "normalized"); |
3068 %! assert (get (0, "screensize"), [0.0, 0.0, 1.0, 1.0]) | 3068 %! assert (get (0, "screensize"), [0.0, 0.0, 1.0, 1.0]); |
3069 %! set (0, "units", "pixels") | 3069 %! set (0, "units", "pixels"); |
3070 %! assert (get (0, "screensize"), sz + [1, 1, 0, 0]) | 3070 %! assert (get (0, "screensize"), sz + [1, 1, 0, 0]); |
3071 */ | 3071 */ |
3072 | 3072 |
3073 void | 3073 void |
3074 root_figure::properties::remove_child (const graphics_handle& gh) | 3074 root_figure::properties::remove_child (const graphics_handle& gh) |
3075 { | 3075 { |
3679 | 3679 |
3680 /* | 3680 /* |
3681 %!test | 3681 %!test |
3682 %! figure (1, "visible", false); | 3682 %! figure (1, "visible", false); |
3683 %! tol = 100 * eps (); | 3683 %! tol = 100 * eps (); |
3684 %! set (gcf (), "paperorientation", "PORTRAIT") | 3684 %! ## UPPER case and MiXed case is part of test and should not be changed. |
3685 %! set (gcf (), "paperunits", "inches") | 3685 %! set (gcf (), "paperorientation", "PORTRAIT"); |
3686 %! set (gcf (), "papertype", "USletter") | 3686 %! set (gcf (), "paperunits", "inches"); |
3687 %! assert (get (gcf (), "papersize"), [8.5, 11.0], tol) | 3687 %! set (gcf (), "papertype", "USletter"); |
3688 %! set (gcf (), "paperorientation", "Landscape") | 3688 %! assert (get (gcf (), "papersize"), [8.5, 11.0], tol); |
3689 %! assert (get (gcf (), "papersize"), [11.0, 8.5], tol) | 3689 %! set (gcf (), "paperorientation", "Landscape"); |
3690 %! set (gcf (), "paperunits", "centimeters") | 3690 %! assert (get (gcf (), "papersize"), [11.0, 8.5], tol); |
3691 %! assert (get (gcf (), "papersize"), [11.0, 8.5] * 2.54, tol) | 3691 %! set (gcf (), "paperunits", "centimeters"); |
3692 %! assert (get (gcf (), "papersize"), [11.0, 8.5] * 2.54, tol); | |
3692 %! set (gcf (), "papertype", "a4"); | 3693 %! set (gcf (), "papertype", "a4"); |
3693 %! assert (get (gcf (), "papersize"), [29.7, 21.0], tol) | 3694 %! assert (get (gcf (), "papersize"), [29.7, 21.0], tol); |
3694 %! set (gcf (), "paperunits", "inches", "papersize", [8.5, 11.0]) | 3695 %! set (gcf (), "paperunits", "inches", "papersize", [8.5, 11.0]); |
3695 %! assert (get (gcf (), "papertype"), "usletter") | 3696 %! assert (get (gcf (), "papertype"), "usletter"); |
3696 %! assert (get (gcf (), "paperorientation"), "portrait") | 3697 %! assert (get (gcf (), "paperorientation"), "portrait"); |
3697 %! set (gcf (), "papersize", [11.0, 8.5]) | 3698 %! set (gcf (), "papersize", [11.0, 8.5]); |
3698 %! assert (get (gcf (), "papertype"), "usletter") | 3699 %! assert (get (gcf (), "papertype"), "usletter"); |
3699 %! assert (get (gcf (), "paperorientation"), "landscape") | 3700 %! assert (get (gcf (), "paperorientation"), "landscape"); |
3700 */ | 3701 */ |
3701 | 3702 |
3702 void | 3703 void |
3703 figure::properties::set_units (const octave_value& v) | 3704 figure::properties::set_units (const octave_value& v) |
3704 { | 3705 { |
3720 get_units (), screen_size_pixels ()), false); | 3721 get_units (), screen_size_pixels ()), false); |
3721 } | 3722 } |
3722 | 3723 |
3723 /* | 3724 /* |
3724 %!test | 3725 %!test |
3725 %! figure (1, "visible", false) | 3726 %! figure (1, "visible", false); |
3726 %! set (0, "units", "pixels") | 3727 %! set (0, "units", "pixels"); |
3727 %! rsz = get (0, "screensize"); | 3728 %! rsz = get (0, "screensize"); |
3728 %! set (gcf (), "units", "pixels") | 3729 %! set (gcf (), "units", "pixels"); |
3729 %! fsz = get (gcf (), "position"); | 3730 %! fsz = get (gcf (), "position"); |
3730 %! set (gcf (), "units", "normalized") | 3731 %! set (gcf (), "units", "normalized"); |
3731 %! assert (get (gcf (), "position"), (fsz - [1, 1, 0, 0]) ./ rsz([3, 4, 3, 4])) | 3732 %! assert (get (gcf (), "position"), (fsz - [1, 1, 0, 0]) ./ rsz([3, 4, 3, 4])); |
3732 */ | 3733 */ |
3733 | 3734 |
3734 std::string | 3735 std::string |
3735 figure::properties::get_title (void) const | 3736 figure::properties::get_title (void) const |
3736 { | 3737 { |
4966 update_zlabel_position (); | 4967 update_zlabel_position (); |
4967 update_title_position (); | 4968 update_title_position (); |
4968 } | 4969 } |
4969 | 4970 |
4970 /* | 4971 /* |
4972 ## FIXME: A demo can't be called in a C++ file. This should be made a test | |
4973 ## or moved to a .m file where it can be called. | |
4971 %!demo | 4974 %!demo |
4972 %! clf | 4975 %! clf; |
4973 %! subplot (2, 1, 1) | 4976 %! subplot (2,1,1); |
4974 %! plot (rand (3)) | 4977 %! plot (rand (3)); |
4975 %! xlabel xlabel | 4978 %! xlabel xlabel; |
4976 %! ylabel ylabel | 4979 %! ylabel ylabel; |
4977 %! title title | 4980 %! title title; |
4978 %! subplot (2, 1, 2) | 4981 %! subplot (2,1,2); |
4979 %! plot (rand (3)) | 4982 %! plot (rand (3)); |
4980 %! set (gca, "ticklength", get (gca, "ticklength") * 2, "tickdir", "out") | 4983 %! set (gca, "ticklength", get (gca, "ticklength") * 2, "tickdir", "out"); |
4981 %! xlabel xlabel | 4984 %! xlabel xlabel; |
4982 %! ylabel ylabel | 4985 %! ylabel ylabel; |
4983 %! title title | 4986 %! title title; |
4984 */ | 4987 */ |
4985 | 4988 |
4986 static bool updating_xlabel_position = false; | 4989 static bool updating_xlabel_position = false; |
4987 | 4990 |
4988 void | 4991 void |
8606 | 8609 |
8607 return retval; | 8610 return retval; |
8608 } | 8611 } |
8609 | 8612 |
8610 /* | 8613 /* |
8611 %!assert (get (findobj (0, 'Tag', 'nonexistenttag'), 'nonexistentproperty'), []) | 8614 %!assert (get (findobj (0, "Tag", "nonexistenttag"), "nonexistentproperty"), []) |
8612 */ | 8615 */ |
8613 | 8616 |
8614 // Return all properties from the graphics handle @var{h}. | 8617 // Return all properties from the graphics handle @var{h}. |
8615 // If @var{h} is a vector, return a cell array including the | 8618 // If @var{h} is a vector, return a cell array including the |
8616 // property values or lists respectively. | 8619 // property values or lists respectively. |