cid#1607171 Data race condition
[LibreOffice.git] / android / source / src / java / org / libreoffice / TileIdentifier.java
blob9f6fc5605af9cebc18c6ad12aefee9623353fc38
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
9 package org.libreoffice;
11 import android.graphics.Rect;
12 import android.graphics.RectF;
14 import org.mozilla.gecko.gfx.IntSize;
16 /**
17 * Identifies the tile by its position (x and y coordinate on the document), zoom and tile size (currently static)
19 public class TileIdentifier {
20 public final int x;
21 public final int y;
22 public final float zoom;
23 public final IntSize size;
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;
32 /**
33 * Returns a rectangle of the tiles position in scaled coordinates.
35 public RectF getRectF() {
36 return new RectF(x, y, x + size.width, y + size.height);
39 /**
40 * Returns a rectangle of the tiles position in non-scaled coordinates (coordinates as the zoom would be 1).
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);
50 /**
51 * Returns an integer rectangle of the tiles position in non-scaled and rounded coordinates (coordinates as the zoom would be 1).
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) );
64 @Override
65 public boolean equals(Object o) {
66 if (this == o) return true;
67 if (o == null || getClass() != o.getClass()) return false;
69 TileIdentifier that = (TileIdentifier) o;
71 if (x != that.x) return false;
72 if (y != that.y) return false;
73 if (Float.compare(that.zoom, zoom) != 0) return false;
75 return true;
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;
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);
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */