LibreOffice Module android (master) 1
TileIdentifier.java
Go to the documentation of this file.
1/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9package org.libreoffice;
10
11import android.graphics.Rect;
12import android.graphics.RectF;
13
15
19public class TileIdentifier {
20 public final int x;
21 public final int y;
22 public final float zoom;
23 public final IntSize size;
24
25 public TileIdentifier(int x, int y, float zoom, IntSize size) {
26 this.x = x;
27 this.y = y;
28 this.zoom = zoom;
29 this.size = size;
30 }
31
35 public RectF getRectF() {
36 return new RectF(x, y, x + size.width, y + size.height);
37 }
38
42 public RectF getCSSRectF() {
43 float cssX = x / zoom;
44 float cssY = y / zoom;
45 float cssSizeW = size.width / zoom;
46 float cssSizeH = size.height / zoom;
47 return new RectF(cssX, cssY, cssX + cssSizeW, cssY + cssSizeH);
48 }
49
53 public Rect getCSSRect() {
54 float cssX = x / zoom;
55 float cssY = y / zoom;
56 float sizeW = size.width / zoom;
57 float sizeH = size.height / zoom;
58 return new Rect(
59 (int) cssX, (int) cssY,
60 (int) (cssX + sizeW),
61 (int) (cssY + sizeH) );
62 }
63
64 @Override
65 public boolean equals(Object o) {
66 if (this == o) return true;
67 if (o == null || getClass() != o.getClass()) return false;
68
70
71 if (x != that.x) return false;
72 if (y != that.y) return false;
73 if (Float.compare(that.zoom, zoom) != 0) return false;
74
75 return true;
76 }
77
78 @Override
79 public int hashCode() {
80 int result = x;
81 result = 31 * result + y;
82 result = 31 * result + (zoom != +0.0f ? Float.floatToIntBits(zoom) : 0);
83 return result;
84 }
85
86 @Override
87 public String toString() {
88 return String.format("TileIdentifier (%d, %d) z=%f s=(%d, %d)", x, y, zoom, size.width, size.height);
89 }
90}
91
92/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Identifies the tile by its position (x and y coordinate on the document), zoom and tile size (current...
RectF getRectF()
Returns a rectangle of the tiles position in scaled coordinates.
RectF getCSSRectF()
Returns a rectangle of the tiles position in non-scaled coordinates (coordinates as the zoom would be...
Rect getCSSRect()
Returns an integer rectangle of the tiles position in non-scaled and rounded coordinates (coordinates...
TileIdentifier(int x, int y, float zoom, IntSize size)
PyRef getClass(const OUString &name, const Runtime &runtime)
Any result