<commit_before>/*
 * Copyright (C) 2016 <NAME>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef DESCENDU_HEX_H
#define DESCENDU_HEX_H

#include <cstdlib>

#include "d.hpp"

namespace descendu {

// Based upon http://www.redblobgames.com/grids/hexagons/
template <typename T, spec S>
class hex : d<T,2,S>
{
    typedef d<T,2,S> base_type;

    hex(const base_type& src) : base_type(src) {}

    const base_type& base() const { return *this; }
          base_type& base()       { return *this; }

public:

    constexpr hex(const T& q, const T& r) : base_type{q, r} {}

    T q() const { return this->operator[](0); }
    T r() const { return this->operator[](1); }
    T s() const { return - (q() + r()); }

    bool operator==(const hex& o) const { return base() == o.base(); }
    bool operator!=(const hex& o) const { return base() != o.base(); }

    template <typename U, spec R>
    friend class hex;

    template <typename U, spec R>
    auto operator+(const hex<U,R>& o) const {
        return hex(base() + o.base());
    }

    template <typename U, spec R>
    auto operator-(const hex<U,R>& o) const {
        return hex(base() - o.base());
    }

    template <typename U>
    auto distance(const hex<U,S>& o) const {
        // Does not use operator- on account of spec compatibility
        using namespace std;
        return (abs(q()-o.q()) + abs(r()-o.r()) + abs(s()-o.s())) / 2;
    }

    constexpr hex neighbor(int i) const {
        switch (i % 6) {                             // C++11 modulo semantics
        case +0: default: return hex(q()+1, r()  );  // East<commit_msg>More constexpr means more cowbell<commit_after>/*
 * Copyright (C) 2016 <NAME>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef DESCENDU_HEX_H
#define DESCENDU_HEX_H

#include <cstdlib>

#include "d.hpp"

namespace descendu {

// Based upon http://www.redblobgames.com/grids/hexagons/
template <typename T, spec S>
class hex : d<T,2,S>
{
    typedef d<T,2,S> base_type;

    hex(const base_type& src) : base_type(src) {}

    const base_type& base() const { return *this; }
          base_type& base()       { return *this; }

public:

    constexpr hex(const T& q, const T& r) : base_type{q, r} {}

    constexpr T q() const { return this->operator[](0); }
    constexpr T r() const { return this->operator[](1); }
    constexpr T s() const { return - (q() + r()); }

    constexpr bool operator==(const hex& o) const { return base() == o.base(); }
    constexpr bool operator!=(const hex& o) const { return base() != o.base(); }

    template <typename U, spec R>
    friend class hex;

    template <typename U, spec R>
    constexpr auto operator+(const hex<U,R>& o) const {
        return hex(base() + o.base());
    }

    template <typename U, spec R>
    constexpr auto operator-(const hex<U,R>& o) const {
        return hex(base() - o.base());
    }

    template <typename U>
    constexpr auto distance(const hex<U,S>& o) const {
        // Does not use operator- on account of spec compatibility
        using namespace std;
        return (abs(q()-o.q()) + abs(r()-o.r()) + abs(s()-o.s())) / 2;
    }

    constexpr hex neighbor(int i) const {
        switch (i % 6) {                             // C++11 modulo semantics
        case +0: default: return hex(q()+1, r()  );  // East
{'fraction_non_alphanumeric': 0.15308370044052863, 'fraction_numerical': 0.009911894273127754, 'mean_word_length': 2.593471810089021, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7343384', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1203, 'n_words': 403}