Skip to content
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

Merged
merged 10 commits into from
Feb 2, 2015
Merged

A few updates #10

merged 10 commits into from
Feb 2, 2015

Conversation

jminardi
Copy link
Contributor

This PR brings in a few updates:

  1. Paths now print themselves as a valid constructor (see output below)

  2. Paths can now be constructed from a vector of tuples:

    julia> p = Path([(0, 0), (0, 10), (10, 10)])
    Path([(0,0), (0,10), (10,10)])
    

2a. Tuples can be pushed into paths
3. Paths can be compared for equality
4. Some tests of this new functionality

execute!(o, outpaths, -2)
@test length(outpaths) == 2
@show outpaths[1]
@show outpaths

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.

Copy link
Member

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)"

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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)

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.

Copy link
Contributor Author

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.

@jminardi
Copy link
Contributor Author

Things that are still holding this PR up:

  1. Instantiating a Paths() object from an array of Path() objects
  2. Implmenting getindex for PolyTrees

for i = 1:len
print(io, p[i])
if i < len
print(io, ",\n ")

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.

Copy link
Contributor Author

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()

Copy link
Member

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> 

Copy link
Contributor Author

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.

Copy link
Contributor Author

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]

@jminardi
Copy link
Contributor Author

jminardi commented Feb 2, 2015

Ok, I think this PR is ready to merge

@sjkelly
Copy link
Member

sjkelly commented Feb 2, 2015

LGTM 👍

jminardi added a commit that referenced this pull request Feb 2, 2015
@jminardi jminardi merged commit ac445a4 into master Feb 2, 2015
@jminardi jminardi deleted the enh-julian branch February 2, 2015 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants