Skip to content

Package: MapViewPoint

MapViewPoint

nameinstructionbranchcomplexitylinemethod
of(Cartesian)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
of(MouseEvent)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString()
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
translated(double, double)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * MapView: a JavaFX map renderer for tile-based servers
5: * http://tidalwave.it/projects/mapview
6: *
7: * Copyright (C) 2024 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/mapview-src
22: * git clone https://github.com/tidalwave-it/mapview-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.mapviewer;
27:
28: import jakarta.annotation.Nonnull;
29: import javafx.scene.input.MouseEvent;
30: import lombok.EqualsAndHashCode;
31: import lombok.Getter;
32: import lombok.RequiredArgsConstructor;
33: import lombok.experimental.Accessors;
34:
35: /***************************************************************************************************************************************************************
36: *
37: * This class represents a point on the map. (0, 0) corresponds to the center of the map view.
38: *
39: * @see MapCoordinates
40: * @see MapViewPoint
41: * @author Fabrizio Giudici
42: *
43: **************************************************************************************************************************************************************/
44: @RequiredArgsConstructor(staticName = "of") @Accessors(fluent = true) @Getter @EqualsAndHashCode
45: public final class MapViewPoint implements Cartesian
46: {
47: private final double x;
48:
49: private final double y;
50:
51: /***********************************************************************************************************************************************************
52: * {@return a new point given a (x,y) source}.
53: * @param point the source
54: **********************************************************************************************************************************************************/
55: @Nonnull
56: public static MapViewPoint of (@Nonnull final Cartesian point)
57: {
58: return of(point.x(), point.y());
59: }
60:
61: /***********************************************************************************************************************************************************
62: * {@return a new point copying from a {@link MouseEvent}}.
63: * @param event the event
64: **********************************************************************************************************************************************************/
65: @Nonnull
66: public static MapViewPoint of (@Nonnull final MouseEvent event)
67: {
68: return of(event.getX(), event.getY());
69: }
70:
71: /***********************************************************************************************************************************************************
72: * {@return a point translated of the specified amount}.
73: * @param dx the horizontal translation
74: * @param dy the vertical translation
75: **********************************************************************************************************************************************************/
76: @Nonnull
77: public MapPoint translated (final double dx, final double dy)
78: {
79: return MapPoint.of(x + dx, x + dy);
80: }
81:
82: /***********************************************************************************************************************************************************
83: * {@inheritDoc}
84: **********************************************************************************************************************************************************/
85: @Override @Nonnull
86: public String toString()
87: {
88: return String.format("MapViewPoint(%f, %f)", x, y);
89: }
90: }