<commit_before>package de.lmu.ifi.dbs.elki.data.spatial;

/*
 This file is part of ELKI:
 Environment for Developing KDD-Applications Supported by Index-Structures

 Copyright (C) 2011
 Ludwig-Maximilians-Universität München
 Lehr- und Forschungseinheit für Datenbanksysteme
 ELKI Development Team

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import de.lmu.ifi.dbs.elki.data.HyperBoundingBox;
import de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox;
import de.lmu.ifi.dbs.elki.logging.LoggingConfiguration;
import de.lmu.ifi.dbs.elki.utilities.datastructures.ArrayAdapter;

/**
 * Utility class with spatial functions.
 * 
 * @author <NAME>
 * 
 * @apiviz.landmark
 * 
 * @apiviz.uses SpatialComparable oneway - - «compares»
 * @apiviz.has HyperBoundingBox oneway - - «creates»
 */
// IMPORTANT NOTE: when editing this class, bear in mind that the dimension
// numbers start at 1 or 0 depending on the context!
public final class SpatialUtil {
  /**
   * Copy the MBR of an instance.
   * 
   * @param obj Object to copy
   * @param adapter Adapter
   * @return (Modifiable) bounding box
   */
  public static <E> ModifiableHyperBoundingBox copyMBR(E obj, SpatialAdapter<? super E> adapter) {
    final int dim = adapter.getDimensionality(obj);
    double[] min = new double[dim];
    double[] max = new double[dim];
    for(int i = 0; i < dim; i++) {
      min[i] = adapter.getMin(obj, i);
      max[i] = adapter.getMax(obj, i);
    }
    return new ModifiableHyperBoundingBox(min, max);
  }

  /**
   * Compute the volume (area) of the union of two MBRs
   * 
   * @param r1 First object
   * @param a1 Adapter for first object
   * @param r2 Second object
   * @param a2 Adapter for second object
   * @return
   */
  public static <E1, E2> double volumeUnion(E1 r1, SpatialAdapter<? super E1> a1, E2 r2, SpatialAdapter<? super E2> a2) {
    final int dim1 = a1.getDimensionality(r1);
    final int dim2 = a2.getDimensionality(r2);
    assert (!LoggingConfiguration.DEBUG || dim1 == dim2);
    double volume = 1.0;
    for(int i = 0; i < dim1; i++) {
      final double min = Math.min(a1.getMin(r1, i), a2.getMin(r2, i));
      final double max = Math.max(a1.getMax(r1, i), a2.getMax(r2, i));
      volume *= (max - min);
    }
    return volume;
  }

  /**
   * Returns a clone of the minimum hyper point.
   * 
   * @return the minimum hyper point
   */
  public static double[] getMin(SpatialComparable box) {
    final int dim = box.getDimensionality();
    double[] min = new double[dim];
    for(int i = 0; i < dim; i++) {
      min[i] = box.getMin(i + 1);
    }<commit_msg>Refactoring, cleanups.<commit_after>package de.lmu.ifi.dbs.elki.data.spatial;

/*
 This file is part of ELKI:
 Environment for Developing KDD-Applications Supported by Index-Structures

 Copyright (C) 2011
 Ludwig-Maximilians-Universität München
 Lehr- und Forschungseinheit für Datenbanksysteme
 ELKI Development Team

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import de.lmu.ifi.dbs.elki.data.HyperBoundingBox;
import de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox;
import de.lmu.ifi.dbs.elki.logging.LoggingConfiguration;
import de.lmu.ifi.dbs.elki.utilities.datastructures.ArrayAdapter;

/**
 * Utility class with spatial functions.
 * 
 * @author <NAME>
 * 
 * @apiviz.landmark
 * 
 * @apiviz.uses SpatialComparable oneway - - «compares»
 * @apiviz.has HyperBoundingBox oneway - - «creates»
 */
// IMPORTANT NOTE: when editing this class, bear in mind that the dimension
// numbers start at 1 or 0 depending on the context!
public final class SpatialUtil {
  /**
   * Copy the MBR of an instance.
   * 
   * @param obj Object to copy
   * @param adapter Adapter
   * @return (Modifiable) bounding box
   */
  public static <E> ModifiableHyperBoundingBox copyMBR(E obj, SpatialAdapter<? super E> adapter) {
    final int dim = adapter.getDimensionality(obj);
    double[] min = new double[dim];
    double[] max = new double[dim];
    for(int i = 0; i < dim; i++) {
      min[i] = adapter.getMin(obj, i);
      max[i] = adapter.getMax(obj, i);
    }
    return new ModifiableHyperBoundingBox(min, max);
  }

  /**
   * Compute the volume (area) of the union of two MBRs
   * 
   * @param r1 First object
   * @param a1 Adapter for first object
   * @param r2 Second object
   * @param a2 Adapter for second object
   * @return
   */
  public static <E1, E2> double volumeUnion(E1 r1, SpatialAdapter<? super E1> a1, E2 r2, SpatialAdapter<? super E2> a2) {
    final int dim1 = a1.getDimensionality(r1);
    final int dim2 = a2.getDimensionality(r2);
    assert (!LoggingConfiguration.DEBUG || dim1 == dim2) : "Computing union with different dimensionality: " + dim1 + " vs. " + dim2;
    double volume = 1.0;
    for(int i = 0; i < dim1; i++) {
      final double min = Math.min(a1.getMin(r1, i), a2.getMin(r2, i));
      final double max = Math.max(a1.getMax(r1, i), a2.getMax(r2, i));
      volume *= (max - min);
    }
    return volume;
  }

  /**
   * Returns a clone of the minimum hyper point.
   * 
   * @return the minimum hyper point
   */
  public static double[] getMin(SpatialComparable box) {
    final int dim = box.getDimensionality();
    double[] min = new double[dim];
    for(int i = 0; i < dim; i++) {
      min[i] = box.getMin(i + 1);
    }
{'fraction_non_alphanumeric': 0.1045630317092034, 'fraction_numerical': 0.013921113689095127, 'mean_word_length': 3.325083612040134, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6075821', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2063, 'n_words': 735}