fix some rules
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 6 Apr 2025 00:49:37 +0000 (17:49 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 6 Apr 2025 00:49:37 +0000 (17:49 -0700)
rust/pspp/src/output/pivot/mod.rs
rust/pspp/src/output/pivot/output.rs
rust/pspp/src/output/pivot/test.rs
rust/pspp/src/output/text.rs

index 3061c85448a3d4d4adac33ed7a6e2fd92368def0..4ae6f1b00cff13e9ff85462bad8a5e1a03aa5fa2 100644 (file)
@@ -170,7 +170,7 @@ pub enum Border {
 }
 
 impl Border {
-    fn default_stroke(self) -> Stroke {
+    pub fn default_stroke(self) -> Stroke {
         match self {
             Self::InnerFrame(_) | Self::DataLeft | Self::DataTop => Stroke::Thick,
             Self::Dimensions(side) if side != RowColBorder::RowVert => Stroke::Solid,
@@ -178,7 +178,7 @@ impl Border {
             _ => Stroke::None,
         }
     }
-    fn default_border_style(self) -> BorderStyle {
+    pub fn default_border_style(self) -> BorderStyle {
         BorderStyle {
             stroke: self.default_stroke(),
             color: Color::BLACK,
@@ -267,6 +267,7 @@ pub struct Axis {
 pub struct AxisIterator<'a> {
     axis: &'a Axis,
     indexes: SmallVec<[usize; 4]>,
+    done: bool,
 }
 
 impl<'a> Iterator for AxisIterator<'a> {
@@ -274,16 +275,19 @@ impl<'a> Iterator for AxisIterator<'a> {
 
     fn next(&mut self) -> Option<Self::Item> {
         if self.indexes.is_empty() {
-            if self
-                .axis
-                .dimensions
-                .iter()
-                .any(|dimension| dimension.is_empty())
+            if self.done
+                || self
+                    .axis
+                    .dimensions
+                    .iter()
+                    .any(|dimension| dimension.is_empty())
             {
-                return None;
+                None
+            } else {
+                self.done = true;
+                self.indexes = smallvec![0; self.axis.dimensions.len()];
+                Some(self.indexes.clone())
             }
-            self.indexes = smallvec![0; self.axis.dimensions.len()];
-            Some(self.indexes.clone())
         } else {
             for (index, dimension) in self.indexes.iter_mut().zip(self.axis.dimensions.iter()) {
                 *index += 1;
@@ -302,6 +306,7 @@ impl Axis {
         AxisIterator {
             axis: self,
             indexes: SmallVec::new(),
+            done: false,
         }
     }
 }
@@ -1120,9 +1125,9 @@ pub struct Color {
 }
 
 impl Color {
-    const BLACK: Color = Color::new(0, 0, 0);
-    const WHITE: Color = Color::new(255, 255, 255);
-    const TRANSPARENT: Color = Color::new(0, 0, 0).with_alpha(0);
+    pub const BLACK: Color = Color::new(0, 0, 0);
+    pub const WHITE: Color = Color::new(255, 255, 255);
+    pub const TRANSPARENT: Color = Color::new(0, 0, 0).with_alpha(0);
 
     const fn new(r: u8, g: u8, b: u8) -> Self {
         Self {
index d9726ba80699b33918f99bc5d46e894a4ad9c3ae..2341aadb6a653b39b7ef56b5583bddcef3ece91f 100644 (file)
@@ -71,9 +71,9 @@ impl PivotTable {
         fixed_indexes: &[usize],
         fixed_axis: Axis3,
     ) -> bool {
+        dbg!();
         let vary_axis = fixed_axis.transpose().unwrap();
-        let mut cursor2 = self.axes[vary_axis].iter();
-        while let Some(vary_indexes) = cursor2.next() {
+        for vary_indexes in self.axes[vary_axis].iter() {
             let mut presentation_indexes = enum_map! {
                 Axis3::Z => layer_indexes,
                 _ => fixed_indexes,
@@ -81,9 +81,11 @@ impl PivotTable {
             presentation_indexes[vary_axis] = &vary_indexes;
             let data_indexes = self.convert_indexes_ptod(presentation_indexes);
             if self.get(&data_indexes).is_some() {
+                dbg!();
                 return false;
             }
         }
+        dbg!();
         true
     }
     fn enumerate_axis(
@@ -244,10 +246,8 @@ impl PivotTable {
                 0..body.n.y(),
             );
 
-            if stub.x() > 0 {
-                body.h_line(Border::DataTop, 0..body.n.x(), stub.y());
-                body.v_line(Border::DataLeft, stub.x(), 0..body.n.y());
-            }
+            body.h_line(Border::DataTop, 0..body.n.x(), stub.y());
+            body.v_line(Border::DataLeft, stub.x(), 0..body.n.y());
         }
         body
     }
@@ -539,11 +539,7 @@ fn compose_headings(
                     // +-----+-----+-----+-----+-----+-----+-----+-----+-----+
                     // ```
                     if c.parent().is_some_and(|parent| parent.show_label.is_some()) {
-                        table.draw_line(
-                            Border::Categories(col_horz),
-                            (h, top_row),
-                            h_ofs..table.n[h],
-                        );
+                        table.draw_line(Border::Categories(col_horz), (h, y1), h_ofs..table.n[h]);
                     }
                 }
             }
index 2fbd33e51695acba9df8193f79abb54da5db77a6..7534430bd5e03b2674e7a397b34add3e11d14741 100644 (file)
@@ -30,7 +30,7 @@ fn pivot_table_1d() {
     }
     let dimension = DimensionBuilder::new(Axis3::X, bigger_group);
     let mut pt = PivotTableBuilder::new(Value::new_text("Columns"), &[dimension]);
-    for i in 0..6 {
+    for i in 0..5 {
         pt.insert(&[i], Value::new_number(Some(i as f64)));
     }
     let mut driver = TextDriver::new(File::create("/dev/stdout").unwrap());
index b61559731f88fc3f24d31e792d8715523bd0cf19..d78e91d32b0514baa2e30cd7fd3b116f52b5b8a1 100644 (file)
@@ -269,8 +269,8 @@ impl TextDriver {
 
                 let h = pager.draw_next(self, usize::MAX);
 
-                for (ln, line) in self.lines[..h].iter_mut().enumerate() {
-                    println!("{ln}: {}", line);
+                for line in self.lines[..h].iter_mut() {
+                    println!("{line}");
                     line.clear();
                 }
             }