Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
TrackLocation.h
1// trax track library
2// AD 2013
3//
4// "the resolution of all the fruitless searches"
5//
6// Peter Gabriel
7//
8// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
9// Copyright (c) 2019 Marc-Michael Horstmann
10//
11// Permission is hereby granted to any person obtaining a copy of this software
12// and associated source code (the "Software"), to use, view, and study the
13// Software for personal or internal business purposes, subject to the following
14// conditions:
15//
16// 1. Redistribution, modification, sublicensing, or commercial use of the
17// Software is NOT permitted without prior written consent from the copyright
18// holder.
19//
20// 2. The Software is provided "AS IS", without warranty of any kind, express
21// or implied.
22//
23// 3. All copies of the Software must retain this license notice.
24//
25// For further information, please contact: horstmann.marc@trendverlag.de
26
27#pragma once
28
29#include "IDType.h"
30#include "Units.h"
31#include "Orientation.h"
32
33#include "common/Interval.h"
34
35namespace trax{
36
42 struct TrackLocation
43 {
46
47
52 TrackLocation() noexcept
54 explicit TrackLocation( Length param ) noexcept
56 explicit TrackLocation( Length param, bool orient ) noexcept
57 : parameter{param}, orientation{orient}{}
58 TrackLocation( Length param, Orientation::Value orient ) noexcept
59 : parameter{param}, orientation{orient}{}
60 TrackLocation( Length param, Orientation orient ) noexcept
61 : parameter{ param }, orientation{ orient }{}
63
64
65 bool operator==( const TrackLocation& tl ) const noexcept{
66 return parameter == tl.parameter && orientation == tl.orientation;
67 }
68
69 bool operator!=( const TrackLocation& tl ) const noexcept{
70 return !operator==( tl );
71 }
72
73
78 bool Equals( const TrackLocation& loc, Length _epsilon ) const noexcept{
79 return orientation == loc.orientation &&
80 common::Equals( parameter, loc.parameter, _epsilon );
81 }
82
83
86 void Flip() noexcept{
87 orientation.Flip();
88 }
89 };
90
91
93 inline void operator+=( TrackLocation& tl, Length dp ) noexcept;
94
95
97 inline void operator-=( TrackLocation& tl, Length dp ) noexcept;
98
99
101 struct TrackLocationRef
102 {
105
106
110 TrackLocationRef() noexcept = default;
111 explicit TrackLocationRef( const TrackLocation& tl ) noexcept
112 : location{tl}
113 {}
114 TrackLocationRef( Length param, bool orient, IDType id ) noexcept
115 : location{ param, orient },
116 refid{id}
117 {}
119
120
121 bool operator==( const TrackLocationRef& tlr ) const noexcept{
122 return location == tlr.location && refid == tlr.refid;
123 }
124
125 bool operator!=( const TrackLocationRef& tlr ) const noexcept{
126 return !operator==( tlr );
127 }
128 };
129
130
132 struct TrackRange{
135
142 TrackRange() noexcept = default;
143 explicit TrackRange( IDType id ) noexcept
144 : refid{id}
145 {}
146 TrackRange( IDType id, trax::Length near_, trax::Length far_ ) noexcept
147 : range{near_,far_},
148 refid{id}
149 {}
150 explicit TrackRange( const common::Interval<trax::Length>& interval ) noexcept
151 : range{interval}
152 {}
154
155
156 bool operator==( const TrackRange& tr ) const noexcept{
157 return range == tr.range && refid == tr.refid;
158 }
159
160 bool operator!=( const TrackRange& tr ) const noexcept{
161 return !operator==( tr );
162 }
163 };
164
165
166//inlines:
167inline void operator+=( TrackLocation& tl, Length dp ) noexcept{
168 if( tl.orientation )
169 tl.parameter += dp;
170 else
171 tl.parameter -= dp;
172}
173
174inline void operator-=( TrackLocation& tl, Length dp ) noexcept{
175 if( tl.orientation )
176 tl.parameter -= dp;
177 else
178 tl.parameter += dp;
179}
180
181}
void operator+=(Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:586
constexpr bool Equals(T a, T b, T epsilon) noexcept
Tests equality in the sense |a-b| < epsilon.
Definition Helpers.h:66
Value< Dimension< 1, 0, 0 > > Length
Length.
Definition DimensionedValues.h:324
constexpr Value< Dimension< L, M, T > > & operator-=(Value< Dimension< L, M, T > > &a, const Value< Dimension< L, M, T > > &b) noexcept
Dimensionated Values operator.
Definition DimensionedValues.h:490
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
An interval describes the area between two numbers. It is understood to contain the near one and exlu...
Definition Interval.h:42
Type used for IDs in the trax library.
Definition IDType.h:43
Provides two values for orientation.
Definition Orientation.h:37
Value
Values for orientation.
Definition Orientation.h:40
@ para
Denoting the aligned, parallel orientation.
Definition Orientation.h:43
A TrackLocation ist a location on a single track.
Definition TrackLocation.h:43
void Flip() noexcept
Turns the orientation of this TrackLocation to the other side.
Definition TrackLocation.h:86
bool Equals(const TrackLocation &loc, Length _epsilon) const noexcept
Definition TrackLocation.h:78
Orientation orientation
Orientation on the track. True means orientation in track direction.
Definition TrackLocation.h:45
Length parameter
Parameter along a track starting from Track::front.
Definition TrackLocation.h:44
TrackLocation location
location on track.
Definition TrackLocation.h:103
IDType refid
ID of track.
Definition TrackLocation.h:104
IDType refid
ID of track.
Definition TrackLocation.h:134
common::Interval< Length > range
range on track.
Definition TrackLocation.h:133