LIBRARY
Math.Tests.WrapAngle
Wraps constant and time-varying angles to the interval ]-π, π].
Connects a constant source with value 4.0 (≈ 1.27π) to a WrapAngle block with default positiveRange=false and verifies the output is wrapped to ]-π, π]. Expected: 4.0 - 2π ≈ -2.2832. A second WrapAngle block is driven by a sine wave (amplitude 6 rad) that sweeps several periods of ±π, exercising the wrapping across negative and positive angles.
Usage
BlockComponents.Math.Tests.WrapAngle()
Behavior
Source
dyad
"""
Wraps constant and time-varying angles to the interval ]-π, π].
Connects a constant source with value 4.0 (≈ 1.27π) to a WrapAngle block
with default positiveRange=false and verifies the output is wrapped to
]-π, π]. Expected: 4.0 - 2π ≈ -2.2832. A second WrapAngle block is driven
by a sine wave (amplitude 6 rad) that sweeps several periods of ±π,
exercising the wrapping across negative and positive angles.
"""
test component WrapAngle
"Constant source providing an angle > π"
c1 = BlockComponents.Sources.Constant(k = 4.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Sine source sweeping angles beyond ±π"
sine = BlockComponents.Sources.Sine(amplitude = 6, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
},
"tags": []
}
}
"WrapAngle block under test"
wrap_block = BlockComponents.Math.WrapAngle() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Second WrapAngle block driven by the sine source"
wrap_block_2 = BlockComponents.Math.WrapAngle() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
},
"tags": []
}
}
relations
connect(c1.y, wrap_block.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sine.y, wrap_block_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {"stop": 1, "expect": {"signals": ["wrap_block.y", "wrap_block_2.y", "sine.y"]}}
}
}
}
endFlattened Source
dyad
"""
Wraps constant and time-varying angles to the interval ]-π, π].
Connects a constant source with value 4.0 (≈ 1.27π) to a WrapAngle block
with default positiveRange=false and verifies the output is wrapped to
]-π, π]. Expected: 4.0 - 2π ≈ -2.2832. A second WrapAngle block is driven
by a sine wave (amplitude 6 rad) that sweeps several periods of ±π,
exercising the wrapping across negative and positive angles.
"""
test component WrapAngle
"Constant source providing an angle > π"
c1 = BlockComponents.Sources.Constant(k = 4.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Sine source sweeping angles beyond ±π"
sine = BlockComponents.Sources.Sine(amplitude = 6, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
},
"tags": []
}
}
"WrapAngle block under test"
wrap_block = BlockComponents.Math.WrapAngle() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Second WrapAngle block driven by the sine source"
wrap_block_2 = BlockComponents.Math.WrapAngle() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
},
"tags": []
}
}
relations
connect(c1.y, wrap_block.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sine.y, wrap_block_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {"stop": 1, "expect": {"signals": ["wrap_block.y", "wrap_block_2.y", "sine.y"]}}
}
}
}
endTest Cases
Test Case case1
julia
pltjulia
pltjulia
plt