// Last edited on 2000-09-05 02:55:35 by stolfi import Trecho; import Bairro; import Ponto; import Retangulo; import java.util.Vector; public class LogradouroImpl extends Logradouro { int _id; // Identificacao unica para o logradouro String _nome; // Nome do logradouro Ponto _centro = null; // Centro aproximado do logrdouro Trecho[] _trechos = null; // ** MÉTODOS PARA CONSTRUÇÃO ** public LogradouroImpl(int id) { this._id = id; } public void inicializa(String nome, Vector listaTrechos) { this._nome = nome; this._trechos = pegaTrechos(listaTrechos); } // ** MÉTODOS PÚBLICOS GERAIS DE ELEMENTOS ** public int id() { return this._id; } public String nome() { return this._nome; } public String toString() { return "lg" + id(); } public Bairro bairro() { return null; } public Ponto centro() { return null; } public void insere(Retangulo r) { Trecho[] tr = trechos(); for (int i = 0; i < tr.length; i++) { tr[i].insere(r); } } public boolean intercepta(Retangulo r) { Trecho[] tr = trechos(); for (int i = 0; i < tr.length; i++) { if (tr[i].intercepta(r)) { return true; } } return false; } public double distancia(Ponto p) { Trecho[] tr = trechos(); double distMin = Double.MAX_VALUE; for (int i = 0; i < tr.length; i++) { double dist = tr[i].distancia(p); if (dist < distMin) { distMin = dist; } } return distMin; } // ** MÉTODOS PÚBLICOS ESPECÍFICOS ** public Trecho[] trechos() { return this._trechos; } // ** MÉTODOS INTERNOS ** private Trecho[] pegaTrechos(Vector listaTrechos) { int n = listaTrechos.size(); Trecho[] tr = new Trecho[n]; for(int i = 0; i < n;i++) { tr[i] = (Trecho) listaTrechos.elementAt(i); } listaTrechos = null; return tr; } }