-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor polycube_reps and rotations #34
base: main
Are you sure you want to change the base?
refactor polycube_reps and rotations #34
Conversation
Im not sure whats normal within rust but things like |
I agree :P Depending on the goal of the mod pcube;
pub use pcube::{Compression, PCubeFile, ...}
mod point_list;
pub use point_list::Dim; instead to encapsulate it a bit. |
Copying from #31 for reference: // From and Into bounds are optional, but probably useful but not necessary
pub trait Polycube: From<RawPCube> + Into<RawPCube> {
// An associated type describing the iterator used for expansions.
// Add lifetime so that `expansions` may borrow `self`.
// Ideally, this would be `-> impl Iterator<Item = Self> + '_` on
// `fn expansions()`, but we can't do that on stable yet
// (see: https://github.com/rust-lang/rust/issues/91611)
type ExpansionIterator<'a>: Iterator<Item = Self> + 'a
where
Self: 'a;
fn expansions<'a>(&'a self) -> Self::ExpansionIterator<'a>;
// Handy to have
fn canonical_form(&self) -> Self;
// Maybe, for good measure?
fn size(&self) -> usize;
fn dims(&self) -> Dims
} |
I have (now updated based on yours)
in my local branch at the moment and would be open to any feed back. I changed a lot of things like dimensions to u8 because its basically impossible to go past 255, i8 may be better for allowing reps that have a concept of a negative coordinate. |
I think we should carefully consider the final goal of this trait, that's what will tell us if we're over- or underdoing it. 1: In the "brute force" approach (i.e. finding all unique expansions, by brute-forcing solutions and disregarding the fact that we can do things in a specific order), the goal is "we want to take an iterator over input cubes of size Ideally, all you'd need is something simple like: pub trait Polycube {
type ExpansionIterator<'a>: Iterator<Item = Self> + 'a
where
Self: 'a;
/// Produce an iterator that yields all unique n + 1 expansions of
/// `input`.
fn unique_expansions<'a>(input: impl Iterator<Item = Self>) -> Self::ExpansionIterator<'a>;
} 2: For the "smart" approach (i.e. Something like: pub trait Polycube {
/// Count all unique expansions of size `target` for all polycubes in `input`
fn unique_expansions<'a>(input: impl Iterator<Item = Self>, target: usize) -> usize;
} It feels like all of the other Additionally, all of the other trait bounds ( pub struct PolycubeEnumerator<T>
where T: Polycube + Eq + Ord + Hash
{}
// Do stuff that requires Eq, Ord, Hash in an impl block What is, to you, the goal with the trait you're writing? IMO the main goal is "just" to do enumerations, and the other things can either be implementation details or put into sub-traits that are Edit: also, #31 was squashed (on my request), so you'll have to drop all of my commits that are on your branch and rebase. (I think resetting to Edit2: ah, and some sort of |
Thats a good point. for the "smart" DFS approach it then also needs some sort of I'll fix the history in the branch in a bit my local checkout is a bit of a mess rn |
Yeah, absolutely! I think we'll want to land somewhere in between what I wrote (which, on further consideration, is definitly too sparse to be useful) and your idea a few comments up. In the end I think something that we can get all expansions (perhaps with a constraint on the ordering to facilitate the DFS search?), the size, and a method of transforming into the canonical representation should allow us to semi-easily write implementations of the brute-force and smart (= DFS) algorithms that is generic over the type of polycube provided. While writing this I think that sounds like a decent goal. Any opinions? |
Smart is a bit more involved than just what you put above and I think would be justified needing its own traits. In my opinion this means, either we want that algorithm to be part of the cube as I cant tell if its a detail of the algorithm, it could be derived maybe from the components or optionally given a seperate implementation for a polycube, |
8947dcc
to
185cb80
Compare
I see! Yes, that does sound much more difficult to make generic in an easy way. A trait that can do the brute-force, is probably enough for a start, then :) |
I have made a PR NailLegProcessorDivide#1 for your branch, to add some extra improvements to this branch (that hopefully make our lives a bit easier) |
98e6cae
to
a5f6120
Compare
Cleanup on aisle 5
based on #31 moves polycube representations into own submodules