Last active
October 22, 2019 13:54
-
-
Save DSCF-1224/58f8af78139f7d9a2c878c60e1df85fb to your computer and use it in GitHub Desktop.
trial module of Julia 2019/10/22 version 01
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
module Mod20191022v01 | |
mutable struct Coordinate{T <: Core.Real} | |
x::T | |
y::T | |
end | |
function Base.:+(cd1::Coordinate{T}, cd2::Coordinate{T}) where T <: Core.Real | |
return Coordinate{T}(cd1.x + cd2.x, cd1.y + cd2.y) | |
end | |
function Base.:-(cd1::Coordinate{T}, cd2::Coordinate{T}) where T <: Core.Real | |
return Coordinate{T}(cd1.x - cd2.x, cd1.y - cd2.y) | |
end | |
function Base.:-(cd::Coordinate{T}) where T <: Core.Real | |
return Coordinate{T}(- cd.x, - cd.y) | |
end | |
function length2(coordinate::Coordinate{<:Core.Real}) | |
return coordinate.x * coordinate.x + coordinate.y * coordinate.y | |
end | |
function length(coordinate::Coordinate{<:Core.Real}) | |
return Base.sqrt(Mod20191022v01.length2(coordinate)) | |
end | |
function distance(;start::Coordinate{T}, finish::Coordinate{T}) where T <: Core.Real | |
return length( finish - start ) | |
end | |
end | |
cd1 = Mod20191022v01.Coordinate{Core.Float64}(1.0, 1.0) | |
Base.println( - cd1 ) | |
cd1 = Mod20191022v01.Coordinate{Core.Float64}(1.0, 1.0) | |
cd2 = Mod20191022v01.Coordinate{Core.Float64}(2.0, 3.0) | |
cd3 = cd1 + cd2 | |
Base.println(cd3) | |
cd1 = Mod20191022v01.Coordinate{Core.Float64}(1.0, 0.0) | |
cd2 = Mod20191022v01.Coordinate{Core.Float64}(0.0, 1.0) | |
cd3 = Mod20191022v01.Coordinate{Core.Float64}(2.0, 3.0) | |
cd4 = cd1 + cd2 + cd3 | |
Base.println(cd4) | |
cd1 = Mod20191022v01.Coordinate{Core.Float64}(4.0, 5.0) | |
cd2 = Mod20191022v01.Coordinate{Core.Float64}(1.0, 1.0) | |
cd3 = cd1 - cd2 | |
Base.println(cd3) | |
cd1 = Mod20191022v01.Coordinate{Core.Float64}(3.0, 4.0) | |
Base.println(Mod20191022v01.length2(cd1)) | |
Base.println(Mod20191022v01.length(cd1)) | |
cd1 = Mod20191022v01.Coordinate{Core.Float64}(1.0, 1.0) | |
cd2 = Mod20191022v01.Coordinate{Core.Float64}(4.0, 5.0) | |
Base.println(Mod20191022v01.distance(start = cd1, finish = cd2)) | |
#= EOF =# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment