[gnumeric] ValueArea: fix problems with inverted ranges.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] ValueArea: fix problems with inverted ranges.
- Date: Sun, 24 Apr 2016 20:09:11 +0000 (UTC)
commit e8b6151c027e35d1497172e07e39e63875989899
Author: Morten Welinder <terra gnome org>
Date: Sun Apr 24 16:07:07 2016 -0400
ValueArea: fix problems with inverted ranges.
Notably fix problems with ranges that are inverted because a relative
range went off the edge of the sheet.
ChangeLog | 8 ++++++-
NEWS | 1 +
src/value-sheet.c | 58 +++++++++++-----------------------------------------
3 files changed, 21 insertions(+), 46 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a5370fa..da55b01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
+2016-04-24 Morten Welinder <terra gnome org>
+
+ * src/value-sheet.c (value_area_get_x_y): Use
+ gnm_rangeref_normalize. Do full wrap-around.
+
2016-04-24 Jean Brefort <jean brefort normalesup org>
- * src/graph.c (gnm_go_data_matrix_load_values): fix array reading. [#765483]
+ * src/graph.c (gnm_go_data_matrix_load_values): fix array
+ reading. [#765483]
2016-04-17 Jean Brefort <jean brefort normalesup org>
diff --git a/NEWS b/NEWS
index b448636..f907194 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Morten:
* Documentation fixes for complex numbers.
* Fix rare RANDBETWEEN problem.
* Test suite improvements.
+ * Fix value-area problem. [#765438]
--------------------------------------------------------------------------
Gnumeric 1.12.28
diff --git a/src/value-sheet.c b/src/value-sheet.c
index dc179f0..474f2ad 100644
--- a/src/value-sheet.c
+++ b/src/value-sheet.c
@@ -164,58 +164,26 @@ value_area_get_x_y (GnmValue const *v, int x, int y, GnmEvalPos const *ep)
NULL);
return v->v_array.vals [x][y];
} else if (VALUE_IS_CELLRANGE (v)) {
- GnmCellRef const * const a = &v->v_range.cell.a;
- GnmCellRef const * const b = &v->v_range.cell.b;
- int a_col = a->col;
- int a_row = a->row;
- int b_col = b->col;
- int b_row = b->row;
+ GnmRange r;
+ Sheet *start_sheet, *end_sheet;
GnmCell *cell;
- Sheet *sheet;
-
- /* Handle relative references */
- if (a->col_relative)
- a_col += ep->eval.col;
- if (a->row_relative)
- a_row += ep->eval.row;
- if (b->col_relative)
- b_col += ep->eval.col;
- if (b->row_relative)
- b_row += ep->eval.row;
-
- /* Handle inverted references */
- if (a_row > b_row) {
- int tmp = a_row;
- a_row = b_row;
- b_row = tmp;
- }
- if (a_col > b_col) {
- int tmp = a_col;
- a_col = b_col;
- b_col = tmp;
- }
-
- a_col += x;
- a_row += y;
-
- /*
- * FIXME FIXME FIXME
- * This should return NA but some of the math functions may
- * rely on this for now.
- */
- g_return_val_if_fail (a_row<=b_row, NULL);
- g_return_val_if_fail (a_col<=b_col, NULL);
- sheet = eval_sheet (a->sheet, ep->sheet);
+ gnm_rangeref_normalize (&v->v_range.cell, ep,
+ &start_sheet, &end_sheet,
+ &r);
+ if (start_sheet != end_sheet)
+ return NULL;
- g_return_val_if_fail (IS_SHEET (sheet), NULL);
+ // Full wrap-around
+ x = (r.start.col + x) % gnm_sheet_get_max_cols (start_sheet);
+ y = (r.start.row + y) % gnm_sheet_get_max_rows (start_sheet);
/* Speedup */
- if (sheet->cols.max_used < a_col ||
- sheet->rows.max_used < a_row)
+ if (start_sheet->cols.max_used < x ||
+ start_sheet->rows.max_used < y)
return value_new_empty ();
- cell = sheet_cell_get (sheet, a_col, a_row);
+ cell = sheet_cell_get (start_sheet, x, y);
if (cell != NULL) {
gnm_cell_eval (cell);
return cell->value;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]