// Path: android-maps-extensions/src/main/java/com/androidmapsextensions/utils/SphericalMercator.java
// public final class SphericalMercator {
// 
//     private static final double MIN_LATITUDE = -85.0511287798;
//     private static final double MAX_LATITUDE = 85.0511287798;
// 
//     private SphericalMercator() {
//     }
// 
//     public static double fromLatitude(double latitude) {
//         double radians = Math.toRadians(latitude + 90) / 2;
//         return Math.toDegrees(Math.log(Math.tan(radians)));
//     }
// 
//     public static double toLatitude(double mercator) {
//         double radians = Math.atan(Math.exp(Math.toRadians(mercator)));
//         return Math.toDegrees(2 * radians) - 90;
//     }
// 
//     /**
//      * @param latitude to be scaled
//      * @return value in the range [0, 360)
//      */
//     public static double scaleLatitude(double latitude) {
//         if (latitude < MIN_LATITUDE) {
//             latitude = MIN_LATITUDE;
//         } else if (latitude > MAX_LATITUDE) {
//             latitude = MAX_LATITUDE;
//         }
//         return fromLatitude(latitude) + 180.0;
//     }
// 
//     /**
//      * @param longitude to be scaled
//      * @return value in the range [0, 360)
//      */
//     public static double scaleLongitude(double longitude) {
//         return longitude + 180.0;
//     }
// }


import com.androidmapsextensions.utils.SphericalMercator;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import java.util.ArrayList;
import java.util.List;
/*
 * Copyright (C) 2013 Maciej Górski
 *
 * 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.
 */
package com.androidmapsextensions.impl;



class DebugHelper {

    private List<Polyline> gridLines = new ArrayList<Polyline>();

    void drawDebugGrid(IGoogleMap map, double clusterSize) {
        cleanup();
        IProjection projection = map.getProjection();
        LatLngBounds bounds = projection.getVisibleRegion().latLngBounds;
// Path: android-maps-extensions/src/main/java/com/androidmapsextensions/utils/SphericalMercator.java
// public final class SphericalMercator {
// 
//     private static final double MIN_LATITUDE = -85.0511287798;
//     private static final double MAX_LATITUDE = 85.0511287798;
// 
//     private SphericalMercator() {
//     }
// 
//     public static double fromLatitude(double latitude) {
//         double radians = Math.toRadians(latitude + 90) / 2;
//         return Math.toDegrees(Math.log(Math.tan(radians)));
//     }
// 
//     public static double toLatitude(double mercator) {
//         double radians = Math.atan(Math.exp(Math.toRadians(mercator)));
//         return Math.toDegrees(2 * radians) - 90;
//     }
// 
//     /**
//      * @param latitude to be scaled
//      * @return value in the range [0, 360)
//      */
//     public static double scaleLatitude(double latitude) {
//         if (latitude < MIN_LATITUDE) {
//             latitude = MIN_LATITUDE;
//         } else if (latitude > MAX_LATITUDE) {
//             latitude = MAX_LATITUDE;
//         }
//         return fromLatitude(latitude) + 180.0;
//     }
// 
//     /**
//      * @param longitude to be scaled
//      * @return value in the range [0, 360)
//      */
//     public static double scaleLongitude(double longitude) {
//         return longitude + 180.0;
//     }
// }


// Path: android-maps-extensions/src/main/java/com/androidmapsextensions/impl/DebugHelper.java
import com.androidmapsextensions.utils.SphericalMercator;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import java.util.ArrayList;
import java.util.List;

/*
 * Copyright (C) 2013 Maciej Górski
 *
 * 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.
 */
package com.androidmapsextensions.impl;



class DebugHelper {

    private List<Polyline> gridLines = new ArrayList<Polyline>();

    void drawDebugGrid(IGoogleMap map, double clusterSize) {
        cleanup();
        IProjection projection = map.getProjection();
        LatLngBounds bounds = projection.getVisibleRegion().latLngBounds;
        double minY = -180 + clusterSize * (int) (SphericalMercator.scaleLatitude(bounds.southwest.latitude) / clusterSize);