Skip to content

Commit

Permalink
basic path shape
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonMiraj committed Jul 8, 2024
1 parent 9949566 commit 6bec109
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/backends/fig_path_shape.f90
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
15 changes: 15 additions & 0 deletions test/path_test.f90
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

0 comments on commit 6bec109

Please sign in to comment.