Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Section.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 "Configuration.h"
30#include "Units.h"
31
32#include "common/Interval.h"
33#include "spat/Rect.h"
34#include "spat/Position2D.h"
35#include "spat/Vector2D.h"
36
37#include "Units.h"
38
39namespace trax{
40
45 struct Section{
46
48 virtual std::string TypeName() const noexcept = 0;
49
50
74
76 static dclspc std::unique_ptr<Section> Make( SpecialSections special = SpecialSections::empty ) noexcept;
77
78 virtual SpecialSections GetSectionType() const noexcept = 0;
79
80
82 struct SectionPoint{
86
87
90 SectionPoint() noexcept
91 : p{},
92 n{},
93 t{}
94 {}
95
96 SectionPoint( const spat::Position2D<Length>& pt ) noexcept
97 : p{pt},
98 n{0,1},
99 t{0}
100 {}
101
102 SectionPoint( const spat::Position2D<Length>& pt, const spat::Vector2D<One>& d, One tex ) noexcept
103 : p{pt},
104 n{d},
105 t{tex}
106 {}
108
109
115 SectionPoint& Scale( One scale ) noexcept{
116 return Scale( scale, scale );
117 }
118
119 SectionPoint& Scale( One x_scale, One y_scale ) noexcept{
120 p.x *= x_scale;
121 p.y *= y_scale;
122 n.dx /= x_scale;
123 n.dy /= y_scale;
124 n.Normalize();
125 return *this;
126 }
128
129 };
130
131
134 virtual void Create( SpecialSections specialSection ) = 0;
135
136
138 virtual int CountPoints() const = 0;
139
140
142 virtual void SetCntPoints( int cnt ) = 0;
143
144
147 virtual const SectionPoint& Get( int id ) const = 0;
148
149
154
155
157 virtual Length PolygonChainLength() const noexcept = 0;
158
159
161 virtual Length Gauge() const noexcept = 0;
162
163
165 virtual spat::Rect<Length> Clearance() const noexcept = 0;
166
167
173 virtual void Set( int id, const SectionPoint& pt, bool bGaugeLeft = false, bool bGaugeRight = false ) = 0;
174
175
177 virtual void Scale( One x_scale, One y_scale ) = 0;
178
179
181 virtual void CalculateNormals() noexcept = 0;
182
184 virtual void CalculateTextureCoordinates() = 0;
185
186
187 virtual ~Section() = default;
188 Section( const Section& ) = delete;
189 Section( Section&& ) = delete;
190 Section& operator=( const Section& ) = delete;
191 Section& operator=( Section&& ) = delete;
192 protected:
193 Section() = default;
194 };
195
196 dclspc std::string ToString( Section::SpecialSections specialSection );
197
198 dclspc Section::SpecialSections SpecialSection( const std::string& string );
199}
Value< Dimension< 0, 0, 0 > > One
Dimensionless value.
Definition DimensionedValues.h:319
Value< Dimension< 1, 0, 0 > > Length
Length.
Definition DimensionedValues.h:324
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
An interval describes the area between two numbers. It is understood to contain the near one and exlu...
Definition Interval.h:42
Implements a 2D - position in cartesian coordinates.
Definition Position2D.h:45
Valtype x
cartesian x coordinate
Definition Position2D.h:48
Valtype y
cartesian y coordinate
Definition Position2D.h:49
Axis aligned rectangle.
Definition Rect.h:41
Implements a 2D - vector in cartesian coordinates.
Definition Vector2D.h:46
auto Normalize() noexcept -> decltype(Valtype{}/Valtype{})
Definition Vector2D.h:292
Valtype dy
cartesian y component.
Definition Vector2D.h:50
Valtype dx
cartesian x component.
Definition Vector2D.h:49
Point structure used to describe a section.
Definition Section.h:82
One t
Texture length along the profile. Used for texture coordinates.
Definition Section.h:85
spat::Position2D< Length > p
Position of profile point.
Definition Section.h:83
spat::Vector2D< One > n
Normal of profile point.
Definition Section.h:84
virtual Length Gauge() const noexcept=0
virtual void Set(int id, const SectionPoint &pt, bool bGaugeLeft=false, bool bGaugeRight=false)=0
Sets the section point with index id.
virtual Length PolygonChainLength() const noexcept=0
SpecialSections
Predefined cross sections.
Definition Section.h:52
@ eep_rack_railway
simple track with cogs in the center
Definition Section.h:61
@ square
four points profile
Definition Section.h:70
@ eep_simple3
very simple epp track. high embankment.
Definition Section.h:68
@ eep_simple2
very simple epp track. high embankment.
Definition Section.h:67
@ eepv7_grooved_convextread
section with grooved rods and convex shaped top
Definition Section.h:58
@ eepv7_track1000
high embankment narrow track narrow rod plus convex shaped top
Definition Section.h:66
@ eep_concrete_roadway
rods fixed in concrete
Definition Section.h:60
@ eep_simple
very simple epp track
Definition Section.h:63
@ eep_grooved_convextread
section with grooved rods and convex shaped top
Definition Section.h:64
@ eep_flatballast_rods
flat ballast with rods
Definition Section.h:69
@ custom
section with no name but generated by custom code
Definition Section.h:55
@ eep_embankment_simple
very simple track and high embankment
Definition Section.h:59
@ eep7_track1435
high embankment narrow rod plus convex shaped top
Definition Section.h:62
@ pipeline
round profile.
Definition Section.h:72
@ vignol_UIC60
vignol UIC60
Definition Section.h:57
@ empty
section with no points in it.
Definition Section.h:54
@ standard
simple section
Definition Section.h:56
@ eep_flatballast
flat ballast without rods
Definition Section.h:65
@ hexagon
six points profile
Definition Section.h:71
virtual std::string TypeName() const noexcept=0
Name for the object type that implements this interface.
virtual void CalculateTextureCoordinates()=0
Calculates the texture coordinate t from positions of the points automatically.
virtual void SetCntPoints(int cnt)=0
Sets the total number of profile points.
virtual common::Interval< One > TextureExtent() const =0
Gives the maximum difference between the t values of any two SectionPoints.
virtual void Create(SpecialSections specialSection)=0
Creates a special section, creates the section points if applicable.
virtual void Scale(One x_scale, One y_scale)=0
Scales all the points and normals by factors.
virtual const SectionPoint & Get(int id) const =0
virtual int CountPoints() const =0
virtual void CalculateNormals() noexcept=0
Calculates the normals from positions of the points automatically.
virtual spat::Rect< Length > Clearance() const noexcept=0
static dclspc std::unique_ptr< Section > Make(SpecialSections special=SpecialSections::empty) noexcept
Makes a Section object.