Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Location.h
1// trax track library
2// AD 2013
3//
4// "Sooner or later in life
5// the things you love you'll loose"
6//
7// Florence + The Machine
8//
9// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
10// Copyright (c) 2019 Marc-Michael Horstmann
11//
12// Permission is hereby granted to any person obtaining a copy of this software
13// and associated source code (the "Software"), to use, view, and study the
14// Software for personal or internal business purposes, subject to the following
15// conditions:
16//
17// 1. Redistribution, modification, sublicensing, or commercial use of the
18// Software is NOT permitted without prior written consent from the copyright
19// holder.
20//
21// 2. The Software is provided "AS IS", without warranty of any kind, express
22// or implied.
23//
24// 3. All copies of the Software must retain this license notice.
25//
26// For further information, please contact: horstmann.marc@trendverlag.de
27
28#pragma once
29
88
89#include "Units.h"
90#include "Track.h"
91#include "TrackLocation.h"
92
93#include <memory>
94
95namespace trax
96{
97 struct Event;
98 struct SignalTarget;
99
100 struct TrackLocation;
101 template<typename> struct TrackData;
102
110 class Location{
111 public:
118 dclspc Location() noexcept = default;
119 dclspc Location( const Location& location ) noexcept = default;
120 dclspc Location( Location&& location ) noexcept = default;
121 dclspc Location( std::shared_ptr<const Track> pTrack, const TrackLocation& tl );
122 dclspc Location( const Track& track, const TrackLocation& tl );
124
125 dclspc virtual ~Location() = default;
126
129 dclspc Location& operator=( const Location& location ) noexcept = default;
130 dclspc Location& operator=( Location&& location ) noexcept = default;
132
133
145 dclspc void PutOn( std::shared_ptr<const Track> pTrack, const TrackLocation& tl );
146
147
149 dclspc void PutOff() noexcept;
150
151
153 dclspc bool IsOnTrack() const noexcept;
154
155
159 dclspc std::shared_ptr<const Track> GetTrack() const noexcept;
160
161
163 dclspc Length Param() const noexcept;
164
165
167 dclspc Orientation Orient() const noexcept;
168
169
172 dclspc AnglePerLength Curvature() const;
173
174
177 dclspc AnglePerLength Torsion() const;
178
179
185 dclspc void TNBFrame( spat::Frame<Length,One>& frame ) const;
186
187
189 dclspc void Get( TrackLocation& tl ) const noexcept;
190
191
193 dclspc void Get( TrackLocationRef& tlr ) const noexcept;
194
195
212 dclspc void Transition( spat::Position<Length>& pos ) const;
213
214 dclspc void Transition( spat::Vector<One>& tan ) const;
215
216 dclspc void Transition( spat::VectorBundle<Length,One>& bundle ) const;
217
218 dclspc void Transition( spat::VectorBundle2<Length,One>& bundle ) const;
219
220 dclspc void Transition( spat::Frame<Length,One>& frame ) const;
221
222 dclspc void Transition( TrackData<Real>& td, Real engine_meters_per_unit ) const;
224
225
258 dclspc std::pair<Length,bool> Move( Length dParam );
259
260 dclspc std::pair<Length,bool> Move( Length dParam, const Event* pEvent );
261
262 dclspc std::pair<Length,bool> Move( Length dParam, Orientation principalDirection, SignalTarget* pSignalTarget );
263
264 dclspc std::pair<Length,bool> Move( Length dParam, Orientation principalDirection, const Event* pEvent, SignalTarget* pSignalTarget );
266
267
276 dclspc Length MoveToEnd( Orientation direction = Orientation::Value::para, const Event* pEvent = nullptr, SignalTarget* pSignalTarget = nullptr );
277
278
288 dclspc std::pair<Length,bool> MoveTransit( Orientation direction = Orientation::Value::para, const Event* pEvent = nullptr, SignalTarget* pSignalTarget = nullptr );
289
290
292 dclspc Location& Flip() noexcept;
293
294
301 dclspc bool Equals( const Location& loc, Length epsilon ) const noexcept;
302
303
316 dclspc Length Distance( const Location& loc, Length maxdistance ) const;
317
318
325 dclspc void Reserve( common::Interval<Length> range, IDType forID );
326
327
330 dclspc void DeleteReservation( IDType forID = anyID );
331
332
336 dclspc std::vector<Track::Overlap> Overlaps( IDType forID ) const;
338
339
342 dclspc std::shared_ptr<Track> GetMutableTrack() const noexcept;
343 private:
344 std::shared_ptr<const Track> m_pTrack;
345 TrackLocation m_TLocation;
346
347 // Calculates this track location relative to the coupled track at front or end.
348 // This might lead to a parameter out of track ranges.
349 // Returns false if the track is uncoupled at the specified end.
350 bool TrackTransition( Track::EndType frontend, const Event* pEvent ) noexcept;
351
352 // Transition tracks until parameter is on track.
353 bool Resolve() noexcept;
354
355 bool IsResolved() const noexcept;
356 };
357
358
359
360 inline bool operator==( const Location& locationA, const Location& locationB ) noexcept{
361 return locationA.Equals( locationB, epsilon__length );
362 }
363
364 inline bool operator!=( const Location& locationA, const Location& locationB ) noexcept{
365 return !locationA.Equals( locationB, epsilon__length );
366 }
367
368
377 dclspc Length ParameterDistanceFrom3DDistance( const Location& location, Length distanceIn3D, Length maxParameter, Length _epsilon = epsilon__length );
378
379
394 dclspc std::tuple<std::shared_ptr<const Track>,Track::EndType,Length> EndOfLine( const Location& location, Length maxDistance, bool bDeadConnectorOnly = false );
395}
Home of the Track and TrackBuilder interfaces.
Value type, dependend from dimensions.
Definition DimensionedValues.h:233
A Location specifies a position on a track system by referencing a track and a TrackLocation on it.
Definition Location.h:110
dclspc void TNBFrame(spat::Frame< Length, One > &frame) const
Receives the TNB - Frame of the curve at the location.
dclspc Location & Flip() noexcept
Turns the direction of this location to the other side.
dclspc bool IsOnTrack() const noexcept
dclspc void DeleteReservation(IDType forID=anyID)
Deletes a reservation.
dclspc void Reserve(common::Interval< Length > range, IDType forID)
Reserves a range on the track relative to this Location.
dclspc void Get(TrackLocation &tl) const noexcept
Gets the TrackLocation - data of this track location.
dclspc Orientation Orient() const noexcept
dclspc bool Equals(const Location &loc, Length epsilon) const noexcept
Compares two Locations.
dclspc AnglePerLength Curvature() const
dclspc Length Param() const noexcept
dclspc std::shared_ptr< const Track > GetTrack() const noexcept
Gets the track this Location is on.
dclspc Location() noexcept=default
Construction.
dclspc AnglePerLength Torsion() const
dclspc Length MoveToEnd(Orientation direction=Orientation::Value::para, const Event *pEvent=nullptr, SignalTarget *pSignalTarget=nullptr)
Moves the location to the track's end and transitions it to the coupled track's end if any.
dclspc std::shared_ptr< Track > GetMutableTrack() const noexcept
Gets mutable track access.
dclspc void PutOff() noexcept
Removes the Location from its position on the track.
dclspc std::vector< Track::Overlap > Overlaps(IDType forID) const
Finds overlapping areas for reservations.
dclspc std::pair< Length, bool > MoveTransit(Orientation direction=Orientation::Value::para, const Event *pEvent=nullptr, SignalTarget *pSignalTarget=nullptr)
Moves the location to the track's end and transitions it to the coupled track's end if any.
dclspc Length Distance(const Location &loc, Length maxdistance) const
Gets the parameter distance between two locations.
dclspc void PutOn(std::shared_ptr< const Track > pTrack, const TrackLocation &tl)
Attaches this Location onto the specified track.
Namespace of common utility classes and methods.
Definition Helpers.h:43
constexpr bool operator!=(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:701
Value< Dimension< 0, 0, 0 > > One
Dimensionless value.
Definition DimensionedValues.h:319
Value< Dimension< 1, 0, 0 > > Length
Length.
Definition DimensionedValues.h:324
Value< Dimension<-1, 0, 0 > > AnglePerLength
Angle per length.
Definition DimensionedValues.h:321
float Real
Underlying floating point type to be used with the dim library.
Definition DimensionedValues.h:190
constexpr Real epsilon
Marginal difference in calculations.
Definition DimensionedValues.h:344
constexpr Value< Dimension< 0, 0, 0 > > tan(Value< Dimension< 0, 0, 0 > > a) noexcept
Dimensionated Values math function.
Definition DimensionedValues.h:702
The namespace provides classes and methods for spatial computations.
Definition Box.h:32
STL namespace.
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
dclspc Length ParameterDistanceFrom3DDistance(const Location &location, Length distanceIn3D, Length maxParameter, Length _epsilon=epsilon__length)
Calculate parameter for given 3D distance.
dclspc std::tuple< std::shared_ptr< const Track >, Track::EndType, Length > EndOfLine(const Location &location, Length maxDistance, bool bDeadConnectorOnly=false)
Gets the end of a line.
An interval describes the area between two numbers. It is understood to contain the near one and exlu...
Definition Interval.h:42
A Frame ("TNBFrame") describes a location in 3d space and an orientation using a right handed coordin...
Definition Frame.h:52
Implements a 3D - position in cartesian coordinates.
Definition Position.h:46
Implements a tangential space bundle.
Definition VectorBundle2.h:43
Implements a Vector bundle.
Definition VectorBundle.h:42
Implements a 3D - vector in cartesian coordinates.
Definition Vector.h:48
Definition Event.h:40
Type used for IDs in the trax library.
Definition IDType.h:43
Provides two values for orientation.
Definition Orientation.h:37
Target for signal notification.
Definition Signal.h:407
Full geometrical data at a point on a track.
Definition TrackData.h:36
Interface for a track used to calculate 3D positions.
Definition Track.h:275
EndType
Designates one of the two ends of a track.
Definition Track.h:292
A TrackLocation ist a location on a single track.
Definition TrackLocation.h:43
bool Equals(const TrackLocation &loc, Length _epsilon) const noexcept
Definition TrackLocation.h:78
A track location, referencing the track by id.
Definition TrackLocation.h:102