Debian Codegraph @

src/uk/me/parabola/imgfmt/app/trergn/Zoom.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2006 Steve Ratcliffe
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: 07-Dec-2006
16 */
17 package uk.me.parabola.imgfmt.app.trergn;
18
19 import uk.me.parabola.imgfmt.app.ImgFileWriter;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
24
25 /**
26 * A zoom level (or map level) determines the amount of detail that
27 * is shown as you zoom in and out.
28 * Level 0 is the the most detailed level.
29 *
30 * A zoom level has a number of bits per co-ordinate and the number of
31 * subdivisions at that level.
32 *
33 * The highest level must have one subdivision and have no elements I believe.
34 *
35 * @author Steve Ratcliffe
36 */
37 public class Zoom {
38 private final int level;
39 private boolean inherited;
40
41 private final int resolution;
42
43 private final List<Subdivision> subdivs = new ArrayList<>();
44
45 /**
46 * Create a new zoom level.
47 *
48 * @param zoom The level between 0 and 15.
49 * @param resolution The number of bits per coordinate, up to 24.
50 */
51 Zoom(int zoom, int resolution) {
52 this.level = zoom;
53 this.resolution = resolution;
54 }
55
56
57 public Iterator<Subdivision> subdivIterator() {
58 return subdivs.iterator();
59 }
60
61 public void setInherited(boolean inherited) {
62 this.inherited = inherited;
63 }
64
65
66 public int getLevel() {
67 return level;
68 }
69
70 public int getResolution() {
71 return resolution;
72 }
73
74 public int getShiftValue() {
75 return 24 - resolution;
76 }
77
78 public void write(ImgFileWriter file) {
79 file.put1u((level & 0xf) | (inherited ? 0x80 : 0));
80 file.put1u(resolution);
81 file.put2u(subdivs.size());
82 }
83
84 public String toString() {
85 return "L " + level + ':' + resolution;
86 }
87
88 void addSubdivision(Subdivision div) {
89 subdivs.add(div);
90 }
91 }