Code Monkey home page Code Monkey logo

Comments (2)

alice-i-cecile avatar alice-i-cecile commented on June 2, 2024
/// Returns the angle associated with the provided hex [`Direction`].
///
/// Measured in radians counterclockwise from the +x axis.
pub fn angle(direction: Direction) -> f32 {
    use Direction::*;
    // See https://dr282zn36sxxg.cloudfront.net/datastreams/f-d%3Adff233ddd1e7e4c34a6545a8dfc1d63bbaf7eefbb40215febc633a30%2BIMAGE_TINY%2BIMAGE_TINY.1
    PI / 6.
        * match direction {
            BottomRight => 11.,
            TopRight => 1.,
            Top => 3.,
            TopLeft => 5.,
            BottomLeft => 7.,
            Bottom => 9.,
        }
}

from hexx.

ManevilleF avatar ManevilleF commented on June 2, 2024

That would make a great addition !
As context there is a similar functionality in hex_layout computing the corners of hexagons, and I note that in your example the start_rotationis missing (flat/pointy hexagons)

I think that the angle method should be in HexLayout or HexOrientation to take the start_rotation in account. Would that work for you ? Something like:

let layout = HexLayout::default();
let angle = layout.direction_angle(Direction::BottomRight);

and/ or

let orientation = HexOrientation::pointy();
let angle = orientation.direction_angle(Direction::BottomRight);

and / or

let orientation = HexOrientation::pointy();
let angle = Direction::BottomRight.angle(&orientation);

from hexx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.