001/* *********************************************************************** *
002 * project: org.matsim.*
003 *                                                                         *
004 * *********************************************************************** *
005 *                                                                         *
006 * copyright       : (C) 2012 by the members listed in the COPYING,        *
007 *                   LICENSE and WARRANTY file.                            *
008 * email           : info at matsim dot org                                *
009 *                                                                         *
010 * *********************************************************************** *
011 *                                                                         *
012 *   This program is free software; you can redistribute it and/or modify  *
013 *   it under the terms of the GNU General Public License as published by  *
014 *   the Free Software Foundation; either version 2 of the License, or     *
015 *   (at your option) any later version.                                   *
016 *   See also COPYING, LICENSE and WARRANTY file                           *
017 *                                                                         *
018 * *********************************************************************** */
019package org.matsim.contrib.parking.parkingchoice.lib.obj.network;
020
021import java.util.Collection;
022
023import org.matsim.api.core.v01.network.Link;
024import org.matsim.api.core.v01.network.Network;
025import org.matsim.core.utils.collections.QuadTree;
026
027/**
028 * 
029 * @author rashid_waraich
030 *
031 * @param <T>
032 */
033public class QuadTreeInitializer<T> {
034
035        public QuadTree<T> getLinkQuadTree(Network network) {
036                double minX = Double.MAX_VALUE;
037                double minY = Double.MAX_VALUE;
038                double maxX = Double.MIN_VALUE;
039                double maxY = Double.MIN_VALUE;
040
041                for (Link link : network.getLinks().values()) {
042                        if (link.getCoord().getX() < minX) {
043                                minX = link.getCoord().getX();
044                        }
045
046                        if (link.getCoord().getY() < minY) {
047                                minY = link.getCoord().getY();
048                        }
049
050                        if (link.getCoord().getX() > maxX) {
051                                maxX = link.getCoord().getX();
052                        }
053
054                        if (link.getCoord().getY() > maxY) {
055                                maxY = link.getCoord().getY();
056                        }
057                }
058
059                return new QuadTree<T>(minX, minY, maxX + 1.0, maxY + 1.0);
060        }
061        
062        public QuadTree<T> getQuadTree(EnclosingRectangle rectagle){
063                return new QuadTree<T>(rectagle.getMinX() -1.0, rectagle.getMinY() -1.0, rectagle.getMaxX() + 1.0, rectagle.getMaxY() + 1.0);
064        }
065
066}