-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
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,73 @@ | ||
module fig_path | ||
use fig_shapes | ||
implicit none | ||
|
||
type, extends(shape) :: path | ||
character(len=:), allocatable :: path_string | ||
contains | ||
procedure :: moveTo | ||
procedure :: lineTo | ||
procedure :: bezierCurveTo | ||
procedure :: quadraticCurveTo | ||
procedure :: ellipticalArcTo | ||
procedure :: closePath | ||
end type path | ||
|
||
contains | ||
|
||
subroutine moveTo(this, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x, y | ||
character(len=30) :: command | ||
|
||
write(command, '(A,F6.2,A,F6.2,A)') "M ", x, " ", y | ||
this%path_string = trim(this%path_string) // trim(command) | ||
end subroutine moveTo | ||
|
||
subroutine lineTo(this, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x, y | ||
character(len=30) :: command | ||
|
||
write(command, '(A,F6.2,A,F6.2,A)') "L ", x, " ", y | ||
this%path_string = trim(this%path_string) // trim(command) | ||
end subroutine lineTo | ||
|
||
subroutine bezierCurveTo(this, x1, y1, x2, y2, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x1, y1, x2, y2, x, y | ||
character(len=50) :: command | ||
|
||
write(command, '(A,F6.2,A,F6.2,A,F6.2,A,F6.2,A,F6.2,A,F6.2,A)') "C ", x1, " ", y1, " ", x2, " ", y2, " ", x, " ", y | ||
|
||
this%path_string = trim(this%path_string) // trim(command) | ||
end subroutine bezierCurveTo | ||
|
||
subroutine quadraticCurveTo(this, x1, y1, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x1, y1, x, y | ||
character(len=50):: command | ||
|
||
write(command, '(A,F6.2,A,F6.2,A,F6.2,A,F6.2,A)') "Q ", x1, " ", y1, " ", x, " ", y, " " | ||
this%path_string = trim(this%path_string) // trim(command) | ||
end subroutine quadraticCurveTo | ||
|
||
subroutine ellipticalArcTo(this, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: rx, ry, x_axis_rotation, x, y | ||
INTEGER, intent(in) :: large_arc_flag, sweep_flag | ||
character(len=80) :: command | ||
|
||
write(command, '(A,F6.2,A,F6.2,A,F6.2,A,I0,A,I0,A,F6.2,A,F6.2,A)') & | ||
"A ", rx, " ", ry, " ", x_axis_rotation, " ", large_arc_flag, " ", & | ||
sweep_flag, " ", x, " ", y | ||
this%path_string = trim(this%path_string) // trim(command) | ||
end subroutine ellipticalArcTo | ||
|
||
subroutine closePath(this) | ||
class(path), intent(inout) :: this | ||
|
||
this%path_string = trim(this%path_string) // "Z " | ||
end subroutine closePath | ||
|
||
end module fig_path |
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,15 @@ | ||
program path_test | ||
use fig_path | ||
implicit none | ||
type(path) :: my_path | ||
call my_path%moveTo(10.0, 10.0) | ||
call my_path%lineTo(50.0, 20.0) | ||
call my_path%bezierCurveTo(30.0, 40.0, 60.0, 50.0, 80.0, 30.0) | ||
call my_path%quadraticCurveTo(100.0, 50.0, 120.0, 80.0) | ||
call my_path%ellipticalArcTo(40.0, 20.0, 30.0, 1, 0, 150.0, 100.0) | ||
call my_path%closePath() | ||
print *,my_path%path_string | ||
|
||
|
||
end program path_test | ||
|