1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.cts.verifier.sensors.sixdof.Utils.Path; 17 18 import com.android.cts.verifier.sensors.sixdof.Utils.Manager; 19 import com.android.cts.verifier.sensors.sixdof.Utils.MathsUtils; 20 import com.android.cts.verifier.sensors.sixdof.Utils.Exceptions.WaypointAreaCoveredException; 21 import com.android.cts.verifier.sensors.sixdof.Utils.Exceptions.WaypointDistanceException; 22 import com.android.cts.verifier.sensors.sixdof.Utils.Exceptions.WaypointRingNotEnteredException; 23 import com.android.cts.verifier.sensors.sixdof.Utils.Exceptions.WaypointStartPointException; 24 import com.android.cts.verifier.sensors.sixdof.Utils.Path.PathUtilityClasses.Waypoint; 25 26 import java.util.ArrayList; 27 28 /** 29 * Contains all the information of the current path. 30 */ 31 public abstract class Path { 32 protected ArrayList<Waypoint> mCurrentPath = new ArrayList<>(); 33 protected ArrayList<Waypoint> mPathMarkers = new ArrayList<>(); 34 35 /** 36 * Creates a waypoint and adds it to the path. 37 * 38 * @param coordinates the coordinates to use for the waypoint. 39 * @param userGenerated indicates whether the data was user created or system created. 40 * @param currentLap the lap the data was created in. 41 * @throws WaypointDistanceException if the location is too close to another. 42 * @throws WaypointAreaCoveredException if the area covered by the user is too little. 43 * @throws WaypointStartPointException if the location is not close enough to the start. 44 * @throws WaypointRingNotEnteredException if a ring is not entered. 45 */ createWaypointAndAddToPath( float[] coordinates, boolean userGenerated, Manager.Lap currentLap)46 public void createWaypointAndAddToPath( 47 float[] coordinates, boolean userGenerated, Manager.Lap currentLap) 48 throws WaypointStartPointException, WaypointDistanceException, 49 WaypointAreaCoveredException, WaypointRingNotEnteredException { 50 if (userGenerated) { 51 additionalChecks(coordinates); 52 } 53 Waypoint waypoint = new Waypoint(coordinates, userGenerated, currentLap); 54 mCurrentPath.add(waypoint); 55 if (waypoint.isUserGenerated()) { 56 mPathMarkers.add(waypoint); 57 } 58 } 59 getLengthOfCurrentPath()60 protected float getLengthOfCurrentPath() { 61 float length = 0.0f; 62 63 // Start at index 1. 64 for (int i = 1; i < mCurrentPath.size(); i++) { 65 float distance = MathsUtils.distanceCalculationOnXYPlane( 66 mCurrentPath.get(i).getCoordinates(), 67 mCurrentPath.get(i - 1).getCoordinates()); 68 length += Math.abs(distance); 69 } 70 71 return length; 72 } 73 74 /** 75 * Abstract method used by classes that extend this one to run additional functionality. 76 * 77 * @param coordinates the coordinates for the waypoint. 78 * @throws WaypointDistanceException if the location is too close to another. 79 * @throws WaypointAreaCoveredException if the area covered by the user is too little. 80 * @throws WaypointStartPointException if the location is not close enough to the start. 81 * @throws WaypointRingNotEnteredException if a ring is not entered. 82 */ additionalChecks(float[] coordinates)83 public abstract void additionalChecks(float[] coordinates) 84 throws WaypointStartPointException, WaypointDistanceException, 85 WaypointAreaCoveredException, WaypointRingNotEnteredException; 86 87 /** 88 * Removes the last maker in the current path. 89 * 90 * @return true of the first marker false if any other marker. 91 */ removeLastMarker()92 public boolean removeLastMarker() { 93 Waypoint markerToRemove = mPathMarkers.get(mPathMarkers.size() - 1); 94 mCurrentPath.remove(markerToRemove); 95 mPathMarkers.remove(markerToRemove); 96 return false; 97 } 98 99 /** 100 * Returns the current path. 101 */ getCurrentPath()102 public ArrayList<Waypoint> getCurrentPath() { 103 return new ArrayList<>(mCurrentPath); 104 } 105 106 /** 107 * Returns the markers for the current path. 108 */ getPathMarkers()109 public ArrayList<Waypoint> getPathMarkers() { 110 return new ArrayList<>(mPathMarkers); 111 } 112 113 /** 114 * Returns the size of the path. 115 */ getCurrentPathSize()116 public int getCurrentPathSize() { 117 return mCurrentPath.size(); 118 } 119 120 /** 121 * Returns the number if markers. 122 */ getPathMarkersSize()123 public int getPathMarkersSize() { 124 return mPathMarkers.size(); 125 } 126 } 127