RA-Consulting-GmbH / openscenario.api.test

Apache License 2.0
38 stars 11 forks source link

OpenScenarioXMLExporter removes attributes, if value is 0 #206

Open arauschert opened 4 months ago

arauschert commented 4 months ago

Describe the bug There seems to be a general problem, if scenarios are parsed and written again with the OpenScenarioXMLExporter, they are changed regarding double attributes with value 0. The exporter assumes if the value is 0 that is wasn't set in the original scenario and removes it in the export. But 0 is a valid value. With the introduction of the IsSet...() methods this problem can be solved, so that the exporter can distinguish, the two cases that:

  1. an attribute was set with value 0
  2. an attribute was not set

To Reproduce

  1. Parse a scenario with a FollowTrajectoryAction, which includes a Polygon with a vertex with time="0"
  2. write the scenario with OpenScenarioXMLExporter
  3. compare the original scenario with the exported scenario

Expected behavior Vertex still contains attribute time="0"

Observed behavior Vertex doesn't contain attribute "time" anymore

Additional context Example scenario snippet:

<Private entityRef="TrafficVehicle">
  <PrivateAction>
    <RoutingAction>
       <FollowTrajectoryAction>
          <TrajectoryRef>
             <Trajectory name="CarTrajectory" closed="false">
                <Shape>
                   <Polyline>
                   <Vertex time="0">
                         <Position>
                          <LanePosition roadId="0" laneId="-2" offset="-3.5" s="3000.0">
                              <Orientation type="relative"/>
                            </LanePosition>
                         </Position>
                    </Vertex>
                    <Vertex time="5">
                         <Position>
                          <LanePosition roadId="0" laneId="-2" offset="-3.5" s="3010.0">
                              <Orientation type="relative"/>
                            </LanePosition>
                         </Position>
                    </Vertex>
                    <Vertex time="8">
                         <Position>
                          <LanePosition roadId="0" laneId="-2" offset="-3.5" s="3010.0">
                              <Orientation type="relative"/>
                            </LanePosition>
                         </Position>
                    </Vertex>
                    <Vertex time="35">
                      <Position>
                        <LanePosition roadId="0" laneId="-2" offset="-3.5" s="3200">
                           <Orientation type="relative"/>
                        </LanePosition>
                      </Position>
                    </Vertex>
                    <Vertex time="80">
                      <Position>
                        <LanePosition roadId="0" laneId="-2" offset="-3.5" s="3420">
                           <Orientation type="relative"/>
                        </LanePosition>
                      </Position>
                    </Vertex>
                   </Polyline>
                </Shape>
             </Trajectory>
          </TrajectoryRef>
          <TimeReference>
            <Timing domainAbsoluteRelative="relative" scale="1.0" offset="0.0" />
          </TimeReference>
          <TrajectoryFollowingMode followingMode="position" />
       </FollowTrajectoryAction>
    </RoutingAction>
 </PrivateAction>
</Private>