Skip to content

Package: MapViewPoint

MapViewPoint

nameinstructionbranchcomplexitylinemethod
of(Cartesian)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
of(MouseEvent)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toPoint2D()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
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.mapview;
27:
28: import jakarta.annotation.Nonnull;
29: import javafx.geometry.Point2D;
30: import javafx.scene.input.MouseEvent;
31: import org.apiguardian.api.API;
32: import lombok.EqualsAndHashCode;
33: import lombok.Getter;
34: import lombok.RequiredArgsConstructor;
35: import lombok.experimental.Accessors;
36: import static org.apiguardian.api.API.Status.STABLE;
37:
38: /***************************************************************************************************************************************************************
39: *
40: * This class represents a point on the map. (0, 0) corresponds to the center of the map view.
41: *
42: * @see MapCoordinates
43: * @see MapViewPoint
44: * @author Fabrizio Giudici
45: *
46: **************************************************************************************************************************************************************/
47: @API(status = STABLE)
48: @RequiredArgsConstructor(staticName = "of") @Accessors(fluent = true) @Getter @EqualsAndHashCode
49: public final class MapViewPoint implements Cartesian
50: {
51: private final double x;
52:
53: private final double y;
54:
55: /***********************************************************************************************************************************************************
56: * {@return a new point given a (x,y) source}.
57: * @param point the source
58: **********************************************************************************************************************************************************/
59: @Nonnull
60: public static MapViewPoint of (@Nonnull final Cartesian point)
61: {
62: return of(point.x(), point.y());
63: }
64:
65: /***********************************************************************************************************************************************************
66: * {@return a new point copying from a {@link MouseEvent}}.
67: * @param event the event
68: **********************************************************************************************************************************************************/
69: @Nonnull
70: public static MapViewPoint of (@Nonnull final MouseEvent event)
71: {
72: return of(event.getX(), event.getY());
73: }
74:
75: /***********************************************************************************************************************************************************
76: * {@return a point translated of the specified amount}.
77: * @param dx the horizontal translation
78: * @param dy the vertical translation
79: **********************************************************************************************************************************************************/
80: @Nonnull
81: public MapPoint translated (final double dx, final double dy)
82: {
83: return MapPoint.of(x + dx, x + dy);
84: }
85:
86: /***********************************************************************************************************************************************************
87: * {@return a {@link Point2D} equivalent}.
88: * @since 1.0-ALPHA-3
89: **********************************************************************************************************************************************************/
90: @Nonnull
91: public Point2D toPoint2D()
92: {
93: return new Point2D(x, y);
94: }
95:
96: /***********************************************************************************************************************************************************
97: * {@inheritDoc}
98: **********************************************************************************************************************************************************/
99: @Override @Nonnull
100: public String toString()
101: {
102: return String.format("MapViewPoint(%f, %f)", x, y);
103: }
104: }