-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A few updates #10
A few updates #10
Conversation
execute!(o, outpaths, -2) | ||
@test length(outpaths) == 2 | ||
@show outpaths[1] | ||
@show outpaths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra prints should be removed. For testing, silent == all good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a lot of these. We can keep everything silent by making an IOBuffer and checking string equality:
julia> p = Path(5)
(0,0), (0,0), (0,0), (0,0), (0,0)
julia> a = IOBuffer()
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1)
julia> show(a, p)
julia> ASCIIString(a.data)
"(0,0), (0,0), (0,0), (0,0), (0,0)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented the tests using an IOBuffer
function child_count(c::__ClipperPolyTree) | ||
@cxx c->ChildCount() | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs tests.
Apparently the PolyTree is just an array of PolyNodes: https://github.com/Voxel8/Clipper.jl/blob/6a3cce9ea409d7b4977024e3bbee1830955cb205/src/clipper_cpp.jl#L138
It would be convenient if we could define getindex
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote a test for child_count
.
I am struggling with implementing getindex
. Here is what I tried:
@inline function Base.getindex(p::__ClipperPolyTree, i::Integer)
icxx"$p[$i-1];"
end
I get the following error when I try to call getindex
ERROR: LoadError: MethodError: `getindex` has no method matching getindex(::Cxx.CppValue{Cxx.CppBaseType{symbol("ClipperLib::PolyTree")},(false,false,false)}, ::Int64)
Closest candidates are:
getindex(::(Any...,), ::Int64)
getindex(::(Any...,), ::Real)
getindex{T}(::FloatRange{T}, ::Integer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PolyTree
is a subclass of PolyNode
, so I don't think getindex
makes sense. See definition here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed getindex
from this PR. If we later decide we want it we can add it back in in another PR.
Things that are still holding this PR up:
|
for i = 1:len | ||
print(io, p[i]) | ||
if i < len | ||
print(io, ",\n ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's good practice to put newlines in show()
output. If it's nested inside another object, the whole output is broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Julia's arrays use newlines in their output:
julia> a = [1 2;3 4]
2x2 Array{Int64,2}:
1 2
3 4
I think newlines make the arrays significantly easier to read, and I think the same can be said about Paths()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think under the covers the REPL's 'P' is println
:
julia> 6
6
julia> print(6)
6
julia>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this show()
is being deprecated in favor of write()
anyway. It seems like println()
just calls show()
under the covers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@show
still uses newlines for arrays:
julia> @show a
a = [1 2
3 4]
Ok, I think this PR is ready to merge |
LGTM 👍 |
This PR brings in a few updates:
Paths now print themselves as a valid constructor (see output below)
Paths can now be constructed from a vector of tuples:
2a. Tuples can be pushed into paths
3. Paths can be compared for equality
4. Some tests of this new functionality