<commit_before>/* Copyright (c) 2015-2016 Boundless and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Distribution License v1.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/edl-v10.html
 *
 * Contributors:
 * <NAME> (Boundless) - initial implementation
 */
package org.locationtech.geogig.model.internal;

import com.vividsolutions.jts.geom.Envelope;

public enum Quadrant {
    SW(0, 0), NW(0, 1), NE(1, 1), SE(1, 0);

    private final int offsetX;

    private final int offsetY;

    Quadrant(int offsetX, int offsetY) {
        this.offsetX = offsetX;
        this.offsetY = offsetY;
    }

    public int getBucketNumber() {
        int i = 0;
        for (Quadrant q : Quadrant.values()) {
            if (q.equals(this))
                return i;
            i++;
        }
        return -1;
    }

    public Envelope slice(Envelope parent) {

        double w = parent.getWidth() / 2.0;
        double h = parent.getHeight() / 2.0;

        double x1 = parent.getMinX() + offsetX * w;
        double x2 = x1 + w;
        double y1 = parent.getMinY() + offsetY * h;
        double y2 = y1 + h;

        return new Envelope(x1, x2, y1, y2);

    }
}<commit_msg>change implementation of getBucketNumber() so its faster<commit_after>/* Copyright (c) 2015-2016 Boundless and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Distribution License v1.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/edl-v10.html
 *
 * Contributors:
 * <NAME> (Boundless) - initial implementation
 */
package org.locationtech.geogig.model.internal;

import com.vividsolutions.jts.geom.Envelope;

public enum Quadrant {
    SW(0, 0), NW(0, 1), NE(1, 1), SE(1, 0);

    private final int offsetX;

    private final int offsetY;

    Quadrant(int offsetX, int offsetY) {
        this.offsetX = offsetX;
        this.offsetY = offsetY;
    }

    public int getBucketNumber() {
       return this.ordinal();
    }

    public Envelope slice(Envelope parent) {

        double w = parent.getWidth() / 2.0;
        double h = parent.getHeight() / 2.0;

        double x1 = parent.getMinX() + offsetX * w;
        double x2 = x1 + w;
        double y1 = parent.getMinY() + offsetY * h;
        double y2 = y1 + h;

        return new Envelope(x1, x2, y1, y2);

    }
}
{'fraction_non_alphanumeric': 0.11067036890122967, 'fraction_numerical': 0.027766759222530742, 'mean_word_length': 2.5027777777777778, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '4266635', 'n_tokens_mistral': 847, 'n_tokens_neox': 786, 'n_words': 246}