Mercurial > hg > octave-nkf
changeset 7446:4bfbec4b0e24
[project @ 2008-02-04 21:17:18 by jwe]
author | jwe |
---|---|
date | Mon, 04 Feb 2008 21:17:18 +0000 |
parents | af92b34f3a3a |
children | 25018e35b4cb |
files | src/ChangeLog src/Makefile.in src/graphics.cc src/graphics.h.in |
diffstat | 4 files changed, 138 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2008-02-04 Shai Ayal <shaiay@users.sourceforge.net> + + * graphics.h.in (axes::properties::update_xlim, + axes::properties::update_ylim, axes::properties::update_zlim): + New update methods. + + * graphics.cc (axes::properties::calc_ticks): New function. + (axes::properties::magform): New function. + (axes::update_axis_limits): Call update_{x,y,z}lims if + appropriate. + 2008-02-04 Michael Goffioul <michael.goffioul@gmail.com> * graphics.h.in (base_graphics_backend::get_screen_size,
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -328,10 +328,10 @@ rm -f $@ $(SH_LD) $(SH_LDFLAGS) $(SONAME_FLAGS) -o $@ $^ $(OCTINTERP_LINK_DEPS) -stamp-prereq: defaults.h graphics.h oct-conf.h oct-gperf.h parse.cc lex.cc $(OPT_HANDLERS) +stamp-prereq: defaults.h oct-conf.h touch stamp-prereq -octave$(EXEEXT): stamp-prereq $(LIBRARIES) main.o $(DLD_STATIC_OBJ) +octave$(EXEEXT): $(LIBRARIES) main.o $(DLD_STATIC_OBJ) $(LD_CXX) $(CPPFLAGS) $(ALL_CXXFLAGS) $(RDYNAMIC_FLAG) \ $(ALL_LDFLAGS) -o $@ \ main.o $(DLD_STATIC_OBJ) \ @@ -364,21 +364,21 @@ @echo DEF_FILES = $(DEF_FILES) @echo $(DEF_FILES) > def-files @$(srcdir)/mkbuiltins def-files > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ graphics.h: graphics.h.in genprops.awk @echo making $@ @$(AWK) -f $(srcdir)/genprops.awk $< > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ PKG_ADD: $(DLD_DEF_FILES) $(srcdir)/mk-pkg-add $(DLD_DEF_FILES) > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ DOCSTRINGS: gendoc$(BUILD_EXEEXT) @echo making $@ @./gendoc > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ doc-files: $(DOC_FILES) @echo making $@ @@ -389,7 +389,7 @@ gendoc.cc: doc-files mkgendoc @echo making $@ @$(srcdir)/mkgendoc doc-files > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ gendoc$(BUILD_EXEEXT): gendoc.cc $(BUILD_CXX) $(BUILD_CXXFLAGS) -o $@ $^ $(BUILD_LDFLAGS) @@ -397,15 +397,15 @@ ops.cc: $(OP_SRC) mkops @echo making $@ from $(OP_SRC) @$(srcdir)/mkops $(OP_SRC) > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ stamp-liboctave-prereq: $(MAKE) -C ../liboctave stamp-prereq touch stamp-liboctave-prereq -$(DEF_FILES): stamp-prereq stamp-liboctave-prereq mkdefs defun-int.h defun-dld.h defun.h defaults.h oct-conf.h +$(DEF_FILES): stamp-prereq stamp-liboctave-prereq mkdefs -$(MAKEDEPS): stamp-prereq stamp-liboctave-prereq defaults.h oct-gperf.h oct-conf.h +$(MAKEDEPS): stamp-prereq stamp-liboctave-prereq graphics.h oct-gperf.h oct-gperf.h parse.cc lex.cc $(OPT_HANDLERS) check: all .PHONY: check @@ -560,7 +560,7 @@ $(OPT_HANDLERS) : %.cc : $(top_srcdir)/liboctave/%.in $(top_srcdir)/mk-opts.pl @echo making $@ from $< @$(PERL) $(top_srcdir)/mk-opts.pl --opt-handler-fcns $< > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ parse.cc : parse.y @echo "expect 14 shift/reduce conflicts" @@ -575,7 +575,7 @@ lex.cc : lex.l $(LEX) $(LFLAGS) $< > $(@F)-t - @$(builddir-move-if-change-rule) + @mv $(@F)-t $@ ## We want to force an update of defaults.h and oct-conf.h every ## time make is run because some values may come from the command @@ -601,14 +601,14 @@ else \ $(SED) '/@SYSDEP_ERRNO_LIST@/D' $< > $@-t; \ fi - @$(simple-move-if-change-rule) + @mv $@-t $@ oct-gperf.h: octave.gperf @echo "making $@ from $<" @$(GPERF) -t -C -D -G -L C++ -Z octave_kw_hash $< | \ $(SED) 's,lookup\[,gperf_lookup[,' > $@-t \ || (rm -f $@-t; exit 1) - @$(simple-move-if-change-rule) + @mv $@-t $@ # How to make a .oct file from a .o file:
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -2232,6 +2232,88 @@ return retval; } +// magform(x) Returns (a, b), where x = a * 10^b, a >= 1., and b is +// integral. Used by calc_ticks + +void +axes::properties::magform (double x, double& a, int &b) +{ + if (x == 0) + { + a = 0; + b = 0; + } + else + { + double l = std::log10 (std::abs (x)); + double r = std::fmod (l, 1.); + a = std::pow (10.0, r); + b = static_cast<int> (l-r); + if (a < 1) + { + a *= 10; + b -= 1; + } + + if (x < 0) + a = -a; + } +} + +// A translation from Tom Holoryd's python code at +// http://kurage.nimh.nih.gov/tomh/tics.py +// FIXME -- add log ticks +void +axes::properties::calc_ticks (const array_property& lims, array_property& ticks) +{ + + int ticint = 5; + + if (lims.get ().is_empty ()) + return; + + double lo = (lims.get ().matrix_value ()) (0); + double hi = (lims.get ().matrix_value ()) (1); + + // Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and + // SCALE3 for Determination of Scales on Computer Generated + // Plots", Communications of the ACM, 10 (1973), 639-640. + // Also cited as ACM Algorithm 463. + + double a; + int b, x; + magform ( (hi-lo)/ticint, a, b); + if (a < 1.41) // sqrt(2) + x = 1; + else if (a < 3.16) // sqrt(10) + x = 2; + else if (a < 7.07) // sqrt(50) + x = 5; + else + x = 10; + + + double sep = x * std::pow (10., b); + + // FIXME x can now be used to set minor ticks + if (x == 10) + x = 1; + + + // The following guarantees that if zero is in the range, it will be + // included as a tic. + + int i1 = static_cast<int> (std::floor (lo / sep)); + int i2 = static_cast<int> (std::ceil (hi / sep)); + + Matrix limits (1, i2-i1+1); + for (int i=0; i<i2-i1+1; i++) + limits (i) = sep*(i+i1); + + ticks = limits; + +} + static bool updating_axis_limits = false; void @@ -2380,16 +2462,19 @@ case 'x': xproperties.set_xlim (limits); xproperties.set_xlimmode ("auto"); + xproperties.update_xlim (); break; case 'y': xproperties.set_ylim (limits); xproperties.set_ylimmode ("auto"); + xproperties.update_ylim (); break; case 'z': xproperties.set_zlim (limits); xproperties.set_zlimmode ("auto"); + xproperties.update_zlim (); break; case 'c':
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -2327,9 +2327,9 @@ array_property dataaspectratio m , Matrix (1, 3, 1.0) radio_property dataaspectratiomode , "{auto}|manual" radio_property layer , "{bottom}|top" - array_property xlim m , default_lim () - array_property ylim m , default_lim () - array_property zlim m , default_lim () + array_property xlim mu , default_lim () + array_property ylim mu , default_lim () + array_property zlim mu , default_lim () array_property clim m , default_lim () array_property alim m , default_lim () radio_property xlimmode al , "{auto}|manual" @@ -2463,6 +2463,31 @@ void update_xdir (void) { update_camera (); } void update_ydir (void) { update_camera (); } void update_zdir (void) { update_camera (); } + + void magform (double x, double& a, int &b); + + void calc_ticks (const array_property& lims, array_property& ticks); + + public: + void update_xlim (void) + { + if (xtickmode.is ("auto")) + calc_ticks (xlim, xtick); + } + + void update_ylim (void) + { + if (ytickmode.is ("auto")) + calc_ticks (ylim, ytick); + } + + void update_zlim (void) + { + if (ztickmode.is ("auto")) + calc_ticks (zlim, ztick); + } + + }; private: