-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from j-adel/patch-2
Adding bspline function in polygons.jl (evaluates npoints B-spline curve based on control points)
- Loading branch information
Showing
6 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Luxor | ||
|
||
using Test | ||
|
||
using Random | ||
Random.seed!(42) | ||
|
||
function test_polybspline() | ||
controlpoints = [Point(rand(), rand()) for _ in 1:10] | ||
|
||
resultClamped = polybspline(controlpoints, 10;clamped = true) | ||
resultUnClamped = polybspline(controlpoints, 10;clamped = false) | ||
# Check if the result is an array of the correct length | ||
@test length(resultClamped) == 10 | ||
@test length(resultUnClamped) == 10 | ||
|
||
# Check if the result is an array of Points | ||
@test all(x -> x isa Point, resultClamped) | ||
@test all(x -> x isa Point, resultUnClamped) | ||
|
||
# Check that all the values in the result points are non NaN | ||
@test all(x -> !isnan(x.x) && !isnan(x.y), resultClamped) | ||
@test all(x -> !isnan(x.x) && !isnan(x.y), resultUnClamped) | ||
|
||
# Check that all the result points lie within the bounding box of the control points | ||
min_x, max_x = extrema(p.x for p in controlpoints) | ||
min_y, max_y = extrema(p.y for p in controlpoints) | ||
|
||
@test all(min_x <= p.x <= max_x && min_y <= p.y <= max_y for p in resultClamped) | ||
@test all(min_x <= p.x <= max_x && min_y <= p.y <= max_y for p in resultUnClamped) | ||
end | ||
|
||
test_polybspline() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters