Velfi / i-ching

A library for i-ching apps written in Rust, and a companion CLI app for divination
Other
24 stars 9 forks source link

Changing line numbers are inverted and 1 less than accurate #4

Closed krry closed 5 years ago

krry commented 5 years ago

After submitting the PR today about the line order for self-cast readings, I realized that there might be other unsolved mysteries related to line numbers.

Looking closely at the readouts for changing line numbers, I notice that the line number indexes must be off. They seem to be counted from the top, and are also shifted one less than they ought to be, as though the <Vec> assembled at src/hexagram.rs:89 is zero indexed.

I've tried to fix it by adding a call to .rev() after the iterator,

    pub fn get_changing_line_positions(&self) -> Vec<usize> {
        self.get_lines_as_vec()
            .iter()
            .rev()
            .enumerate()
            .filter_map(|enumerated_line| match enumerated_line {
                (index, Line::BrokenChanging) | (index, Line::UnbrokenChanging) => Some(index),
                _ => None,
            })
            .collect()
    }

and then incrementing the line number by one at src/bin/main.rs:170

        for line_meaning in hexagram_info.get_line_meanings(&changing_line_positions) {
            print!(
                "\nLine {} changes:\n{}",
                line_meaning.position+1, line_meaning.meaning
            );
        }

but it's not quite there. I'm missing something.

Edit: typo

Velfi commented 5 years ago

Hey! Thanks for finding this. For some reason I never got notified of your issues/prs and I'm only just seeing this. I'll try to make some time this weekend to address all your points / merge updates.

krry commented 5 years ago

Oh hai :) I've been using this library daily for about a month now. Really great, thanks again.

You should know that I'm super green when it comes to Rust. Did my best not to break things. And I'm not certain about how the lines are being ordered, but I've been testing the results against my paper method for a few weeks now, and with these pull requests it yields the same results consistently.