work rust
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 2 Dec 2025 17:23:16 +0000 (09:23 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 2 Dec 2025 17:23:16 +0000 (09:23 -0800)
rust/pspp/src/output/drivers/csv.rs
rust/pspp/src/output/drivers/html.rs
rust/pspp/src/output/pivot/output.rs
rust/pspp/src/output/render.rs
rust/pspp/src/output/table.rs

index 498dd744630ed444eaf7d3bb6283ec61db743e12..d27a424ed2b75aade4e794dfe038097bae48ff43 100644 (file)
@@ -326,13 +326,13 @@ impl CsvDriver {
             return Ok(());
         };
 
-        for y in 0..table.n.1 {
-            for x in 0..table.n.0 {
+        for y in 0..table.n.y {
+            for x in 0..table.n.x {
                 if x > 0 {
                     write!(&mut self.file, "{}", self.options.delimiter)?;
                 }
 
-                let coord = CellPos(x, y);
+                let coord = CellPos { x, y };
                 let content = table.get(coord);
                 if content.is_top_left() {
                     let display = content.inner().value.display(pivot_table);
index 747156b718545e2a017527e1900f113da3d3ae6e..ad19aded6c89ac1ab30fb9fe47f9463f11d287f8 100644 (file)
@@ -86,7 +86,7 @@ where
             writeln!(&mut self.writer, ">")?;
 
             if let Some(title) = output.title {
-                let cell = title.get(CellPos(0, 0));
+                let cell = title.get(CellPos::new(0, 0));
                 self.put_cell(
                     DrawCell::new(cell.inner(), &title),
                     CellRect::new(0..1, 0..1),
@@ -111,10 +111,10 @@ where
             }
 
             writeln!(&mut self.writer, "<tbody>")?;
-            for y in 0..output.body.n.1 {
+            for y in 0..output.body.n.y {
                 writeln!(&mut self.writer, "<tr>")?;
                 for x in output.body.iter_x(y) {
-                    let cell = output.body.get(CellPos(x, y));
+                    let cell = output.body.get(CellPos { x, y });
                     if cell.is_top_left() {
                         let is_header = x < output.body.h[Axis2::X] || y < output.body.h[Axis2::Y];
                         let tag = if is_header { "th" } else { "td" };
@@ -135,7 +135,7 @@ where
                 writeln!(&mut self.writer, "<tr>")?;
                 if let Some(caption) = output.caption {
                     self.put_cell(
-                        DrawCell::new(caption.get(CellPos(0, 0)).inner(), &caption),
+                        DrawCell::new(caption.get(CellPos::new(0, 0)).inner(), &caption),
                         CellRect::new(0..output.body.n[Axis2::X], 0..1),
                         "td",
                         None,
@@ -235,14 +235,14 @@ where
             if rect.x.end == table.n[Axis2::X] {
                 Self::put_border(
                     &mut style,
-                    table.get_rule(Axis2::X, CellPos(rect.x.end, rect.y.start)),
+                    table.get_rule(Axis2::X, CellPos::new(rect.x.end, rect.y.start)),
                     "right",
                 );
             }
             if rect.y.end == table.n[Axis2::Y] {
                 Self::put_border(
                     &mut style,
-                    table.get_rule(Axis2::Y, CellPos(rect.x.start, rect.y.end)),
+                    table.get_rule(Axis2::Y, CellPos::new(rect.x.start, rect.y.end)),
                     "bottom",
                 );
             }
index 8610277d4a0542bd89b8b8203f5f44bb4f967a4e..dad7607e02bd2056a6a6c7bab489709b72820499 100644 (file)
@@ -139,14 +139,17 @@ impl PivotTable {
         I: Iterator<Item = Box<Value>> + ExactSizeIterator,
     {
         let mut table = Table::new(
-            CellPos(1, rows.len()),
-            CellPos(0, 0),
+            CellPos::new(1, rows.len()),
+            CellPos::new(0, 0),
             self.style.look.areas.clone(),
             self.borders(false),
             self.into_value_options(),
         );
         for (y, row) in rows.enumerate() {
-            table.put(CellRect::for_cell(CellPos(0, y)), CellInner::new(area, row));
+            table.put(
+                CellRect::for_cell(CellPos::new(0, y)),
+                CellInner::new(area, row),
+            );
         }
         table
     }
@@ -177,7 +180,7 @@ impl PivotTable {
 
         let data = CellPos::from_fn(|axis| headings[axis].width());
         let mut stub = CellPos::from_fn(|axis| headings[!axis].height());
-        if headings[Axis2::Y].row_label_position == LabelPosition::Corner && stub.1 == 0 {
+        if headings[Axis2::Y].row_label_position == LabelPosition::Corner && stub.y == 0 {
             stub[Axis2::Y] = 1;
         }
         let mut body = Table::new(
@@ -215,11 +218,11 @@ impl PivotTable {
         // are not in the corner.
         if self.metadata.corner_text.is_some()
             && self.style.look.row_label_position == LabelPosition::Nested
-            && stub.0 > 0
-            && stub.0 > 0
+            && stub.x > 0
+            && stub.y > 0
         {
             body.put(
-                CellRect::new(0..stub.0, 0..stub.1),
+                CellRect::new(0..stub.x, 0..stub.y),
                 CellInner::new(
                     Area::Corner,
                     self.metadata.corner_text.clone().unwrap_or_default(),
@@ -227,14 +230,14 @@ impl PivotTable {
             );
         }
 
-        if body.n.0 > 0 && body.n.1 > 0 {
-            body.h_line(Border::InnerFrame(BoxBorder::Top), 0..body.n.0, 0);
-            body.h_line(Border::InnerFrame(BoxBorder::Bottom), 0..body.n.0, body.n.1);
-            body.v_line(Border::InnerFrame(BoxBorder::Left), 0, 0..body.n.1);
-            body.v_line(Border::InnerFrame(BoxBorder::Right), body.n.0, 0..body.n.1);
+        if body.n.x > 0 && body.n.y > 0 {
+            body.h_line(Border::InnerFrame(BoxBorder::Top), 0..body.n.x, 0);
+            body.h_line(Border::InnerFrame(BoxBorder::Bottom), 0..body.n.x, body.n.y);
+            body.v_line(Border::InnerFrame(BoxBorder::Left), 0, 0..body.n.y);
+            body.v_line(Border::InnerFrame(BoxBorder::Right), body.n.x, 0..body.n.y);
 
-            body.h_line(Border::DataTop, 0..body.n.0, stub.1);
-            body.v_line(Border::DataLeft, stub.0, 0..body.n.1);
+            body.h_line(Border::DataTop, 0..body.n.x, stub.y);
+            body.v_line(Border::DataLeft, stub.x, 0..body.n.y);
         }
         body
     }
index 69bb0fa746cac4090a3bc431ec7dc232af1b70e7..2f3ff19cb60eaf11c9c4d018a20c406683cde07f 100644 (file)
@@ -391,7 +391,7 @@ impl Page {
 
         // Calculate minimum and maximum widths of cells that do not span
         // multiple columns.
-        let mut unspanned_columns = EnumMap::from_fn(|_| vec![0; n.0]);
+        let mut unspanned_columns = EnumMap::from_fn(|_| vec![0; n.x]);
         for cell in table.cells().filter(|cell| cell.col_span() == 1) {
             let mut w = device.measure_cell_width(&DrawCell::new(cell.inner(), &table));
             if device.params().px_size.is_some() {
@@ -448,7 +448,7 @@ impl Page {
         // In pathological cases, spans can cause the minimum width of a column
         // to exceed the maximum width.  This bollixes our interpolation
         // algorithm later, so fix it up.
-        for i in 0..n.0 {
+        for i in 0..n.x {
             if columns[Min][i] > columns[Max][i] {
                 columns[Max][i] = columns[Min][i];
             }
@@ -483,7 +483,7 @@ impl Page {
             let w = joined_width(&cp_x, rect.x.clone());
             let h = device.measure_cell_height(&DrawCell::new(cell.inner(), &table), w);
 
-            let row = &mut unspanned_rows[cell.pos.1];
+            let row = &mut unspanned_rows[cell.pos.y];
             if h > *row {
                 *row = h;
             }
@@ -848,7 +848,7 @@ impl Page {
             let mut x = cells.x.start;
             while x < cells.x.end {
                 if !is_rule(x) && !is_rule(y) {
-                    let cell = self.get_cell(CellPos(x / 2, y / 2));
+                    let cell = self.get_cell(CellPos::new(x / 2, y / 2));
                     self.draw_cell(device, ofs, &cell);
                     x = rule_ofs(cell.rect.x.end);
                 } else {
@@ -860,7 +860,7 @@ impl Page {
         for y in cells.y.clone() {
             for x in cells.x.clone() {
                 if is_rule(x) || is_rule(y) {
-                    self.draw_rule(device, ofs, CellPos(x, y));
+                    self.draw_rule(device, ofs, CellPos { x, y });
                 }
             }
         }
@@ -1281,14 +1281,10 @@ impl Break {
             if self.axis == Axis2::Y && device.params().can_adjust_break {
                 let mut x = 0;
                 while x < self.page.n[Axis2::X] {
-                    let cell = self.page.get_cell(CellPos(x, z));
+                    let cell = self.page.get_cell(CellPos::new(x, z));
                     let better_pixel = device.adjust_break(
                         cell.content,
-                        Coord2::new(
-                            self.page
-                                .joined_width(Axis2::X, cell.rect.x.clone()),
-                            pixel,
-                        ),
+                        Coord2::new(self.page.joined_width(Axis2::X, cell.rect.x.clone()), pixel),
                     );
                     x += cell.rect.x.len();
 
index 05ad8e9cac675d4f0103cdf6819466f5778a6055..3b21e63567fc206a49932f4f229c4ef9d7cb5775 100644 (file)
@@ -46,18 +46,21 @@ use super::pivot::{
 
 /// The `(x,y)` position of a cell in a [Table].
 #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
-pub struct CellPos(
+pub struct CellPos {
     /// X
-    pub usize,
+    pub x: usize,
     /// Y
-    pub usize,
-);
+    pub y: usize,
+}
 
 impl CellPos {
+    pub fn new(x: usize, y: usize) -> Self {
+        Self { x, y }
+    }
     pub fn for_axis((a, az): (Axis2, usize), bz: usize) -> Self {
         match a {
-            Axis2::X => Self(az, bz),
-            Axis2::Y => Self(bz, az),
+            Axis2::X => Self::new(az, bz),
+            Axis2::Y => Self::new(bz, az),
         }
     }
 
@@ -65,7 +68,7 @@ impl CellPos {
     where
         F: FnMut(Axis2) -> usize,
     {
-        Self(f(Axis2::X), f(Axis2::Y))
+        Self::new(f(Axis2::X), f(Axis2::Y))
     }
 }
 
@@ -74,8 +77,8 @@ impl Index<Axis2> for CellPos {
 
     fn index(&self, index: Axis2) -> &Self::Output {
         match index {
-            Axis2::X => &self.0,
-            Axis2::Y => &self.1,
+            Axis2::X => &self.x,
+            Axis2::Y => &self.y,
         }
     }
 }
@@ -83,8 +86,8 @@ impl Index<Axis2> for CellPos {
 impl IndexMut<Axis2> for CellPos {
     fn index_mut(&mut self, index: Axis2) -> &mut Self::Output {
         match index {
-            Axis2::X => &mut self.0,
-            Axis2::Y => &mut self.1,
+            Axis2::X => &mut self.x,
+            Axis2::Y => &mut self.y,
         }
     }
 }
@@ -92,7 +95,9 @@ impl IndexMut<Axis2> for CellPos {
 /// A rectangular group of cells in a [Table].
 #[derive(Clone, Debug, Default)]
 pub struct CellRect {
+    /// X range.
     pub x: Range<usize>,
+    /// Y range.
     pub y: Range<usize>,
 }
 
@@ -101,7 +106,7 @@ impl CellRect {
         Self { x, y }
     }
     pub fn for_cell(cell: CellPos) -> Self {
-        Self::new(cell.0..cell.0 + 1, cell.1..cell.1 + 1)
+        Self::new(cell.x..cell.x + 1, cell.y..cell.y + 1)
     }
     pub fn for_ranges((a_axis, a): (Axis2, Range<usize>), b: Range<usize>) -> Self {
         match a_axis {
@@ -110,7 +115,7 @@ impl CellRect {
         }
     }
     pub fn top_left(&self) -> CellPos {
-        CellPos(self.x.start, self.y.start)
+        CellPos::new(self.x.start, self.y.start)
     }
     pub fn is_empty(&self) -> bool {
         self.x.is_empty() || self.y.is_empty()
@@ -166,7 +171,7 @@ impl CellRef<'_> {
     }
 
     pub fn next_x(&self) -> usize {
-        self.content.next_x(self.pos.0)
+        self.content.next_x(self.pos.x)
     }
 
     pub fn is_top_left(&self) -> bool {
@@ -331,12 +336,12 @@ impl Table {
         Self {
             n,
             h: headers,
-            contents: Array::default((n.0, n.1)),
+            contents: Array::default((n.x, n.y)),
             areas,
             borders,
             rules: enum_map! {
-                Axis2::X => Array::default((n.0 + 1, n.1)),
-                Axis2::Y => Array::default((n.0, n.1 + 1)),
+                Axis2::X => Array::default((n.x + 1, n.y)),
+                Axis2::Y => Array::default((n.x, n.y + 1)),
             },
             value_options,
         }
@@ -345,12 +350,12 @@ impl Table {
     pub fn get(&self, coord: CellPos) -> CellRef<'_> {
         CellRef {
             pos: coord,
-            content: &self.contents[[coord.0, coord.1]],
+            content: &self.contents[[coord.x, coord.y]],
         }
     }
 
     pub fn get_rule(&self, axis: Axis2, pos: CellPos) -> BorderStyle {
-        self.rules[axis][[pos.0, pos.1]].map_or(BorderStyle::none(), |b| self.borders[b])
+        self.rules[axis][[pos.x, pos.y]].map_or(BorderStyle::none(), |b| self.borders[b])
     }
 
     pub fn put(&mut self, region: CellRect, inner: CellInner) {
@@ -400,9 +405,9 @@ impl Table {
 
     /// The heading region that `pos` is part of, if any.
     pub fn heading_region(&self, pos: CellPos) -> Option<HeadingRegion> {
-        if pos.0 < self.h.0 {
+        if pos.x < self.h.x {
             Some(HeadingRegion::Rows)
-        } else if pos.1 < self.h.1 {
+        } else if pos.y < self.h.y {
             Some(HeadingRegion::Columns)
         } else {
             None
@@ -434,8 +439,8 @@ impl Iterator for XIter<'_> {
     fn next(&mut self) -> Option<Self::Item> {
         let next_x = self
             .x
-            .map_or(0, |x| self.table.get(CellPos(x, self.y)).next_x());
-        if next_x >= self.table.n.0 {
+            .map_or(0, |x| self.table.get(CellPos::new(x, self.y)).next_x());
+        if next_x >= self.table.n.x {
             None
         } else {
             self.x = Some(next_x);
@@ -457,7 +462,7 @@ impl<'a> Cells<'a> {
             next: if table.is_empty() {
                 None
             } else {
-                Some(table.get(CellPos(0, 0)))
+                Some(table.get(CellPos::new(0, 0)))
             },
         }
     }
@@ -474,9 +479,9 @@ impl<'a> Iterator for Cells<'a> {
         self.next = loop {
             let next_x = next.next_x();
             let coord = if next_x < self.table.n[X] {
-                CellPos(next_x, next.pos.1)
-            } else if next.pos.1 + 1 < self.table.n[Y] {
-                CellPos(0, next.pos.1 + 1)
+                CellPos::new(next_x, next.pos.y)
+            } else if next.pos.y + 1 < self.table.n[Y] {
+                CellPos::new(0, next.pos.y + 1)
             } else {
                 break None;
             };