Giter Club home page Giter Club logo

hexy's Introduction

Build Status

Hexy, A library for dealing with hexagonal coordinate systems.

A library that makes working with a hexagonal lattice easier. Some of the inspiration for this library comes from http://www.redblobgames.com/grids/hexagons/.

Alt text

Getting Started

Installing via pip

pip install hexy

Running the example

We'll use the HexyExamples repo to demonstrate hexy.

git clone https://github.com/redft/hexyexamples
cd hexyexamples
pip install -r requirements.txt # If you're not using a virtual environment, you might need to use sudo.
python2 example.py

The example app just shows off some features of the library. To play around you can:

- right click to change the hex selection type. 
- scroll up and down to change the radius of selection when selection type is ring or disk.
- left click to change the starting point of the line when selection type is a line.

For developers

If you're working on setup.py and want to check it's configured properly, you can run:

pip install -e .

Developing Tests

If you're working on the tests and want to install the test dependencies:

pip install -e .[tests]

If you're using zsh you'll have to use quotes in your command:

pip install -e ".[tests]"

Testing

From the project's root directory, run:

python -m pytest

License

This project is licensed under the MIT License - see the LICENSE.md file for details

hexy's People

Contributors

bicobus avatar ctrl-z-9000-times avatar redft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hexy's Issues

Numpy's sqrt should be used on arrays, not single numbers

numpy's design is to work with arrays and carries that much overhead, that is numpy needs to detect whether the argument is an array or an integer.

A quick benchmark shows that, for single numbers, math.sqrt is faster, but numpy.sqrt is a lot faster when dealing with arrays. If I'm not too tired, I see a factor of 10. Sadly many places within https://github.com/RedFT/Hexy/blob/1057e5df5962627c52c5bf92742ebc94204a6b9d/hexy/hexy.py uses numpy's function on simple integers, including my recent contributions which were based on existing code.

In [1]: import math

In [2]: import numpy as np

In [3]: %%timeit N = 10000
   ...: for i in range(N):
   ...:     z = math.sqrt(i)
   ...: 
1.45 ms ± 25.1 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

In [4]: %%timeit N = 10000
   ...: for i in range(N):
   ...:     z = np.sqrt(i)
   ...: 
16.8 ms ± 103 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [5]: %%timeit R = [i for i in range(10000)]
   ...: np.sqrt(R)
870 µs ± 981 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)

Consider splitting dependencies to required, extras

The install with pip works perfectly 👌 , one issue we're running into is the number of dependencies.

We develop a library, and use hexy as well as a library for its work with coordinates, hex cells.
Not being the end-user, we don't need any of the graphical stuff.

I figured there's an option in setup.py to split dependencies to "required" and several named "extras"
https://stackoverflow.com/questions/41678951/ignoring-some-requirements-when-installing-pip-requirements

  • core:
    for hexy.py, we found only numpy suffices (maybe some more for the tests?)

  • visualizations:
    pull the large game and maybe some more.

Would you consider splitting your setup to the

  • base library pip install hexy
  • and providing extras? for example:
    • tests: pip install hexy[tests]
    • visualizations: pip install hexy[visual]
    • and altogether: pip install hexy[full]
      ?

Thank you,
Mark

Consider distributing your library on PyPI (pip)

Hi,
first of all, this is a very nice software, thank you! 👍
We are going to use your lib in our oss library too,
it would be great if you could package your lib in PyPI so it can be easily installed with
pip install hexy

Cheers,

Inheritance from dict is unreliable and creates subtle issues

it is a known and documented problem that the dict object possess in-line optimizations that will make any subclass behave in a weird way. For example, calling HexMap.pop(k) will not go through your customized __delitem__, and would result in buggy behavior down the line. If the pop or update methods aren't welcomed in your API, consider wrapping an actual dict in your HexMap object instead.

Example:

class HexMap:
    def __init__(self):
        self._map = {}
    def __setitem__(self, k, v):
        self._map[k] = v
    def __delitem__(self, k):
        del self._map[k]

It it, from my understanding, recommended to use the abstract objects from collections.abc to obtain a dict-like behavior

More over, in the linked code bellow, it is seemingly impossible to both initialize and populate a HexMap at the same time.

Hexy/hexy/hex_map.py

Lines 42 to 44 in b856644

class HexMap(dict):
def __init__(self):
super(HexMap, self).__init__()

1.4.4 release?

It looks like there have been new features added in the last few years, but the latest version on PyPI is from 2019.

Thanks for the nice library!

PyPI version v1.41

Just a heads up, with the latest release, you've jumped from 1.3, 1.4, to 1.41.
Likely you've meant 1.4.1.
This will cause issues with updating, as 1.5 < 1.41, can you fix/remove the wrong release number from pip?

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.