<commit_before><?php
/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

/**
 * RESTo Geometry utilities functions
 */
class RestoGeometryUtil {

    /**
     * Check if input object is a valid GeoJSON object
     * 
     * Valid GeoJSON Feature 
     * 
     *      array(
     *          'type' => 'Feature',
     *          'geometry' => array(...),
     *          'properties' => array(...)
     *      )
     *       
     * @param Array $object : json object
     */
    public static function isValidGeoJSONFeature($object) {
        if (!$object || !is_array($object)) {
            return false;
        }
        if (!isset($object['type']) || $object['type'] !== 'Feature') {
            return false;
        }
        if (!isset($object['geometry']) || !is_array($object['geometry'])) {
            return false;
        }
        if (!isset($object['properties']) || !is_array($object['properties'])) {
            return false;
        }
        return true;
    }
    
    /**
     * Return WKT from geometry
     * @param array $geometry - GeoJSON geometry
     */
    public static function geoJSONGeometryToWKT($geometry) {
        $type = strtoupper($geometry['type']);
        switch($type) {
            case 'POINT':
                return $type . RestoGeometryUtil::toPoint($geometry['coordinates']);
            case 'MULTIPOINT':
                return $type . RestoGeometryUtil::toMultiPoint($geometry['coordinates']);
            case 'LINESTRING':
                return $type . RestoGeometryUtil::toLineString($geometry['coordinates']);
            case 'MULTILINESTRING':
                return $type . RestoGeometryUtil::toMultiLineString($geometry['coordinates']);
            case 'POLYGON':
                return $type . RestoGeometryUtil::toPolygon($geometry['coordinates']);
            case 'MULTIPOLYGON':
                return $type . RestoGeometryUtil::toMultiPolygon($geometry['coordinates']);
            default:
                return null;
        }
    }
    
    /**
     * Return BBOX from WKT
     * 
     * @param array $polygon - WKT Polygon
     */
    public static function getExtent($polygon) {
        $extent = [360, 180, -360, -180];
        $stringPairs = explode(',', str_replace('POLYGON((', '', str_replace('))', '', $polygon)));
        for ($i = 0, $ii = count($stringPairs); $i < $ii; $i++) {
            $coordinates = explode(' ', trim($stringPairs[$i]));
            if (floatval($coordinates[0]) > $extent[2]) {
                $extent[2] = $coordinates[0];
            }<commit_msg>Fix bug in RestoGeometryUtil::getExtent<commit_after><?php
/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

/**
 * RESTo Geometry utilities functions
 */
class RestoGeometryUtil {

    /**
     * Check if input object is a valid GeoJSON object
     * 
     * Valid GeoJSON Feature 
     * 
     *      array(
     *          'type' => 'Feature',
     *          'geometry' => array(...),
     *          'properties' => array(...)
     *      )
     *       
     * @param Array $object : json object
     */
    public static function isValidGeoJSONFeature($object) {
        if (!$object || !is_array($object)) {
            return false;
        }
        if (!isset($object['type']) || $object['type'] !== 'Feature') {
            return false;
        }
        if (!isset($object['geometry']) || !is_array($object['geometry'])) {
            return false;
        }
        if (!isset($object['properties']) || !is_array($object['properties'])) {
            return false;
        }
        return true;
    }
    
    /**
     * Return WKT from geometry
     * @param array $geometry - GeoJSON geometry
     */
    public static function geoJSONGeometryToWKT($geometry) {
        $type = strtoupper($geometry['type']);
        switch($type) {
            case 'POINT':
                return $type . RestoGeometryUtil::toPoint($geometry['coordinates']);
            case 'MULTIPOINT':
                return $type . RestoGeometryUtil::toMultiPoint($geometry['coordinates']);
            case 'LINESTRING':
                return $type . RestoGeometryUtil::toLineString($geometry['coordinates']);
            case 'MULTILINESTRING':
                return $type . RestoGeometryUtil::toMultiLineString($geometry['coordinates']);
            case 'POLYGON':
                return $type . RestoGeometryUtil::toPolygon($geometry['coordinates']);
            case 'MULTIPOLYGON':
                return $type . RestoGeometryUtil::toMultiPolygon($geometry['coordinates']);
            default:
                return null;
        }
    }
    
    /**
     * Return BBOX from WKT
     * 
     * @param array $polygon - WKT Polygon
     */
    public static function getExtent($polygon) {
        $extent = array(360, 180, -360, -180);
        $stringPairs = explode(',', str_replace('POLYGON((', '', str_replace('))', '', $polygon)));
        for ($i = 0, $ii = count($stringPairs); $i < $ii; $i++) {
            $coordinates = explode(' ', trim($stringPairs[$i]));
            if (floatval($coordinates[0]) > $extent[2]) {
                $extent[2] = $coordinates[0];
            }
{'fraction_non_alphanumeric': 0.13667792249557806, 'fraction_numerical': 0.008039877793857533, 'mean_word_length': 2.1864754098360657, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3004643', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1664, 'n_words': 457}