Library for Rubik's cube applications.

Overview

Rubik Master

Crates.io documentation CI Tokei

cube-demo3.mov

Do you like to solve Rubik's cube? I do.

As a cuber and programmer, I want to build a toolset to build applications like

  • Solver
  • Virtual Cube (As WebGL component)
  • Cube net printer
  • Tool to find more ergonomic OLL/PLL
  • (Semi-)Automatic scrambler

In this library, the state of the cube is expressed as 54x54 permutation matrix which consumes only 54 bytes in memory and the multiplication costs only O(54) since the matrix is sparse.

Features

This library includes the following modules

  • Core: The matrix representation of cube state and rotation.
  • Parser: Parser for rotation notes like RUR'U'.
  • Cube Component: Yew component to visualize a cube. Animation supported.

I am open to any suggestions.

Author

Akira Hayakawa (@akiradeveloper)

Comments
  • Emphasize piece borders

    Emphasize piece borders

    スクリーンショット 2021-10-07 2 53 06

    The borders between pieces are not clear now but the real cube has clear borders.

    • Classical cube has explicit thick black borders.
    • Sticker-less cube (like picture below. It is GAN 356M) doesn't have black border but the border is clear.

    How to implement this?

    PXL_20211007_153331807

    help wanted 
    opened by akiradeveloper 3
  • Use SIMD in matrix multiplication

    Use SIMD in matrix multiplication

    I think portable-simd will improve multiplication because it is gather operation.

       fn apply(self, to: Self) -> Self {
            let out = gather(&self.inv_perm, &to.inv_perm);
            Self { inv_perm: out }
        }
    

    and portable_simd has one.

        pub fn gather_or_default(slice: &[T], idxs: Simd<usize, LANES>) -> Self
        where
            T: Default,
        {
            Self::gather_or(slice, idxs, Self::splat(T::default()))
        }
    

    It looks quite an early stage but let's trust it.

    enhancement 
    opened by akiradeveloper 3
  • Implement Cube component

    Implement Cube component

    I don't know how I can design it because I am not familiar with WebApp tech. Please help me.

    But some requirements in my mind:

    1. It should be embedded in rust-wasm application easily. (Implementing as a Yew component is my recommendation. See https://github.com/yewstack/yew/pull/908/files)
    2. It should support camera moves by mouse move and reset when certain key (e.g. space or esc) is pressed. If it supports flicking in mobile browser It will be preferred.
    3. It should accept sequence of command (like RU2R') and it performs rotations.
    4. Rotations should be animated. The speed should be able to configure.
    5. Camera move by key input should be considered. When key like UP is pressed it should rotate the cube by x or x'.

    スクリーンショット 2021-09-22 16 04 37

    What you will do:

    • You will create cube-component crate (or other name you like). You can use PermutationMatrix and operations to calculate cube state after rotation but this is not required.
    • You will create cube-app that can launch webapp easily on localhost. This will help testing and debugging.
    help wanted 
    opened by akiradeveloper 3
  • component: Use light gray as the background

    component: Use light gray as the background

    I got an advice in forum https://users.rust-lang.org/t/rubiks-cube-library-rubikmaster/65185/4?u=akiradeveloper

    I guess it would look better if the cube wasn’t the same color as the blackground. Black cube sound fine if you want that, but then perhaps make the background dark grey or so. Right now your demo looks a bit like the cube’s stickers are free-floating in space.

    opened by akiradeveloper 2
  • Implement Parser

    Implement Parser

    In Rubik's cube, rotation is a sequence of characters.

    The parser should parse a text like you see in here

    Here are some examples:

    • R2 D (R' U2 R) D' (R' U2 R')
    • (R U') (R U)2 (R U') R' U' R2
    • (R2' U)(RUR')(U'R'U')(R' U R')

    But the space between the characters should not be assumed.

    As an extension, it is convenient to allow to add prime to group (RLR')' and this will eventually be interpreted as RL'R' which is counter effective of the original one.

    Implement this function using nom (>= 0.7) or anything you like as long as maintainable (combine is another choice I know)

    pub enum Elem {
        One(Command),
        Group(Vec<Command>, i8),
    }
    pub fn parse(s: &str) -> Vec<Elem> {
        todo!()
    }
    

    What you will do:

    1. Implement parser
    2. Add some tests (basic tests are ok but you may use proptest)
    good first issue 
    opened by akiradeveloper 2
  • [App] Implement F2L trainer

    [App] Implement F2L trainer

    F2L has 41 patterns. Each situation should be reproduced by

    M = (F2L)' * (random OLL)' * (random PLL)' * Id

    So we can make 41 * 57 * 21 (= 49k) problems.

    good first issue 
    opened by akiradeveloper 1
  • Optimize rendering

    Optimize rendering

    The cube component is super sub-optimal. It recomputes everything in every frame.

    To optimize, let's consider when data should be changed.

    • The vertex and index list can be reused in all frames. This can use VAO.
    • The color (each vertex) should be changed between moves. This can also use VAO.
    • The rotation matrix should be updated in every frame because the rotation angle is changing.
    help wanted 
    opened by akiradeveloper 1
  • Implement reduce function with rayon

    Implement reduce function with rayon

    Rotation is matrix multiply of O(54). It may be optimized to gather operation but may be not. It isn't a cheap computation anyway.

    Multiplying N matrices can be parallel by Rayon. It would be nice to have a matrix::reduce function whose type is like this

    fn reduce(Vec<PermutationMatrix>) -> PermutationMatrix
    

    What you will do:

    1. Implement reduce function
    2. Add bench. What we want to know is what N should we choose to switch between serial and parallel. I will be great if it is small like 10 or so.
    good first issue 
    opened by akiradeveloper 1
  • Introduce PieceCoordinate

    Introduce PieceCoordinate

    The-2-3-Rubiks-cube-and-a-numbering

    According to the rotation rule (x,y,z), cube is considered to have a x,y,z coordinate as the direction in this figure.

    How I number the piece surfaces? The rule is

    • When you see a surface, you can see two axis in two dimension
    • Now place axis to direct 0 o'clock and 3 o'clock. That's the default position.
    • The left-top is (0,0) and the right-top is (0,2)

    For example, If you see the cube from R surface. Place z on 0 o'clock and y on 3 o'clock.

    This rule is symmetric.

    But this rule is too hard to calculate in brain unless you are a genius.

    For ease of use, it would be better to have PieceCoordinate so the piece with 1,5,9 has (1,1,1) and 6,9,13 has (-1,1,1).

    Then we can define a calculation (PieceCoordinate, Surface) -> Surface Index

    What you will do:

    1. Define coordinate module
    2. Put this definitions there

    This will help to draw Cube in 3d world.

    good first issue 
    opened by akiradeveloper 1
  • Use PHF table for lookup

    Use PHF table for lookup

    https://github.com/rust-phf/rust-phf

    We could use this library to speed up this table

    fn create_plane_group() -> HashMap<RotationPlane, [Piece; 9]> {
    
    opened by akiradeveloper 0
  • Support Smart Cube

    Support Smart Cube

    Develop a crate that transforms events from smart cube to a command stream.

    There are referential implementations so it will be easy because the spec is known.

    https://github.com/playfultechnology/esp32-smartcube

    If you can move the cube in an app by moving the cube in your hand, that will be a path to smart cube apps!

    help wanted 
    opened by akiradeveloper 4
  • Transparent pieces

    Transparent pieces

    The component has blacklist which is a set of surfaces which will be painted in black.

    Instead of this, I want to specify set of pieces to be transparent.

    Transparent piece isn't possible with real cube so will be a great value.

    To make a piece transparent, we can use so-called alpha brending. But since other pieces aren't transparent. We need to do some graphic technique to see solid piece behind a transparent piece because depth buffer enabled normally eliminated the solid piece when they are drawn front to back.

    My idea is firstly draw all solid pieces and then transparent ones.

    help wanted 
    opened by akiradeveloper 0
  • [App] Implement Cube App

    [App] Implement Cube App

    This cube app has two input fields. One for the initial scrambler and for a solve sequence.

    This app helps cubers reproduce a cube state and try a new solve sequence. Especially good for learners.

    good first issue 
    opened by akiradeveloper 0
Owner
Akira Hayakawa
I am just a very good Rust programmer.
Akira Hayakawa
An SVG rendering library.

resvg resvg is an SVG rendering library. Purpose resvg can be used as a Rust library, a C library and as a CLI application to render SVG files based o

Evgeniy Reizner 1.8k Jan 7, 2023
Graph data structure library for Rust.

petgraph Graph data structure library. Supports Rust 1.41 and later. Please read the API documentation here Crate feature flags: graphmap (default) en

null 2k Jan 9, 2023
A graph library for Rust.

Gamma A graph library for Rust. Gamma provides primitives and traversals for working with graphs. It is based on ideas presented in A Minimal Graph AP

Metamolecular, LLC 122 Dec 29, 2022
Simple but powerful graph library for Rust

Graphlib Graphlib is a simple and powerful Rust graph library. This library attempts to provide a generic api for building, mutating and iterating ove

Purple Protocol 177 Nov 22, 2022
The library provides basic functions to work with Graphviz dot lang from rust code.

Description The library provides the basic access to the graphs in graphviz format with ability to import into or export from it. Base examples: Parse

Boris 28 Dec 16, 2022
Rust library for of graph ensembles

Rust library for random graph ensembles Minimal Rust version: 1.55.0 Implements simple sampling and monte carlo (or rather markov-) steps, that can be

Yannick Feld 2 Dec 14, 2022
Generic framebuffer implementation in Rust for use with embedded-graphics library

Fraramebuffer implementation for Rust's Embedded-graphics Framebuffer approach helps to deal with display flickering when you update multiple parts of

Bernard Kobos 9 Nov 29, 2022
Small, lightweight and fast library for rendering text with wgpu.

wgpu-text wgpu-text is a wrapper over glyph-brush for fast and easy text rendering in wgpu. This project was inspired by and is similar to wgpu_glyph,

Leon 20 Nov 30, 2022
Python library for embedding large graphs in 2D space, using force-directed layouts.

Graph Force A python/rust library for embedding graphs in 2D space, using force-directed layouts. Installation pip install graph_force Usage The first

Niko Abeler 159 Dec 29, 2022
A 2D vector graphics library optimized for GUIs, written in Rust and wgpu

RootVG A 2D vector graphics library optimized for GUIs, written in Rust and wgpu How it Works Unlike other 2D vector graphics libraries which have a s

Meadowlark 14 Jul 10, 2024
Pathfinding library for calculating all node pairs' shortest paths in an unweighted undirected graph.

bit_gossip bit_gossip, named after its implementation technique, is a simple pathfinding library for calculating all node pairs' shortest paths in an

Jack Lee 49 Sep 4, 2024
Library for Rubik's cube applications.

Rubik Master cube-demo3.mov Do you like to solve Rubik's cube? I do. As a cuber and programmer, I want to build a toolset to build applications like S

Akira Hayakawa 12 Nov 3, 2022
Rubik's Cube simulator in Rust.

cubedesu Rubik's Cube simulator written in Rust. Play it at https://stanleydesu.github.io/cubedesu/ ! Features Visual simulation of a 3x3 cube, allowi

Stanley Su 16 Jul 15, 2022
📊 Cube.js — Open-Source Analytics API for Building Data Apps

?? Cube.js — Open-Source Analytics API for Building Data Apps

Cube.js 14.4k Jan 8, 2023
Rubik's cube made with bevy engine.

English Rubik's Cube 魔方 3阶魔方 随机打乱魔方 重置魔方 鼠标拖拽魔方旋转 游戏UI 相机视角控制(缩放、移动) WASM支持 在线游玩:点这里(电脑版Chrome/Firefox/Edge打开) 运行 本地运行 cargo run WASM运行 rustup target

Night's Watch Games 4 Dec 31, 2022
Blazingly Fast 3D ASCII Rubik's Cube

rs-cube Blazingly Fast 3D ASCII Rubik's Cube Screenshot Installation Homebrew brew tap doprz/rs-cube brew install rs-cube Cargo cargo install rs-cube

null 8 Apr 2, 2023
Perspective projection of a spinning cube, using just ASCII characters.

Spinning Cube Perspective projection of a spinning cube, using just ASCII characters. spinning_cube.mp4 Instalation cargo install spinning_cube Basic

Guilherme Pagano 5 Aug 31, 2023
⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).

config-rs Layered configuration system for Rust applications (with strong support for 12-factor applications). Set defaults Set explicit values (to pr

Ryan Leckey 1.8k Jan 9, 2023
Decentralized Autonomous Applications (DAAs). Building the Future with Self-Managing Applications.

Decentralized Autonomous Applications (DAAs) Building the Future with Self-Managing Applications. ?? Straw Man Code Outline ?? Reddit Group ?? Twitter

rUv 100 Apr 15, 2023
cfg-rs: A Configuration Library for Rust Applications

cfg-rs: A Configuration Library for Rust Applications Major Features One method to get all config objects, see get. Automatic derive config object, se

Daniel YU 20 Dec 16, 2022