Skip to content

[arkit] Update for Xcode 9.3 beta 1 - #3343

Merged
VincentDondain merged 4 commits into
dotnet:xcode9.3from
VincentDondain:xcode9.3-arkit-b1
Jan 30, 2018
Merged

[arkit] Update for Xcode 9.3 beta 1#3343
VincentDondain merged 4 commits into
dotnet:xcode9.3from
VincentDondain:xcode9.3-arkit-b1

Conversation

@VincentDondain

@VincentDondain VincentDondain commented Jan 26, 2018

Copy link
Copy Markdown
Contributor

Note: I chose to use GetVertices and friends instead of properties to match what was done in ARFaceGeometry (where the properties where wrong and unfortunately obsoleted).

Diff file: https://github.com/xamarin/xamarin-macios/wiki/ARKit-iOS-xcode9.3-beta1

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very small naming detail, otherwise it looks good to me 👍

namespace XamCore.ARKit {
public partial class ARPlaneGeometry {

// Using GetXXX methods so it's similar to the ARFaceGeometry methods.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer methods over props when the operation is "expensive" like interfacing with unmanaged code. Just a personal preference :)

Comment thread src/arkit.cs Outdated
[Static]
[Export ("planeGeometryWithDevice:")]
[return: NullAllowed]
ARSCNPlaneGeometry CreatePlaneGeometry (IMTLDevice device);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just Create? you already know it is a PlaneGeometry because of the type name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmh that was good feedback for #2681 when ARSCNFaceGeometry.CreateFaceGeometry was introduced (:

I agree though, PlaneGeometry should be implied by the type's name.

I'll make CreateFaceGeometry [Obsolete] and move it to Create too for API consistency.

Comment thread src/arkit.cs

[EditorBrowsable (EditorBrowsableState.Advanced)]
[Export ("vertices")]
IntPtr GetRawVertices ();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were not the previous one made internal or protected ? instead of public ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like it was not (from the back port PR)

@monojenkins

Copy link
Copy Markdown
Contributor

Build success

@monojenkins

Copy link
Copy Markdown
Contributor

Build success

Comment thread src/arkit.cs Outdated
ExistingPlane = 1 << 3,
ExistingPlaneUsingExtent = 1 << 4,
[iOS (11,3)]
ExistingPlaneUsingGeometry = (1 << 5),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the (1 << 5) and not simply 1 << 5?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because sharpie :P

I agree it's not needed, if I have to editor this PR again I'll fix it. It's minor though.

Comment thread src/arkit.cs

[EditorBrowsable (EditorBrowsableState.Advanced)]
[Export ("boundaryVertices")]
IntPtr GetRawBoundaryVertices ();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are GetRawTextureCoordinates, GetRawTextureCoordinates and GetRawTextureCoordinates methods and not properties?

At least in the diff we have:

@property (nonatomic, readonly) const vector_float2 *textureCoordinates NS_REFINED_FOR_SWIFT;

@VincentDondain VincentDondain Jan 29, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the description of this PR (consistency with ARFaceGeometry), see #3090 (properties were incorrect and obsoleted) and see Alex's comment #3343 (comment) (Sebastien made the same comment).

public override IntPtr GetRawTriangleIndices ()
{
// Two triangles (set of 3 indices)
indices = new short [] { 1, 2, 3, 4, 5, 6 };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused, is this line creating an array of 6 shorts? can't you do new short [6]?? I might be missing something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I'm setting values that I can then test. See https://github.com/xamarin/xamarin-macios/pull/3343/files#diff-58636f8c30f5f14ba7b2793d5900e7cfR129

I'm simulating the fact that there are actual indices.

var face = new ARPlaneGeometryPoker ();
var vertices = face.GetVertices ();
Assert.AreEqual (new VectorFloat3 (1, 2, 3), vertices [0]);
Assert.AreEqual (new VectorFloat3 (4, 5, 6), vertices [1]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we have as good practice to add a string if we have more than one assert in a test.

@VincentDondain VincentDondain Jan 29, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I missed that good practice (will remember for the next time). Minor comment though no (not sure it's blocking this PR)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't mentioned when the first (similar) tests were added: #3090

var face = new ARPlaneGeometryPoker ();
var textureCoordinates = face.GetTextureCoordinates ();
Assert.AreEqual (new VectorFloat2 (1, 2), textureCoordinates [0]);
Assert.AreEqual (new VectorFloat2 (3, 4), textureCoordinates [1]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the previous one.

var face = new ARPlaneGeometryPoker ();
var boundaryVertices = face.GetBoundaryVertices ();
Assert.AreEqual (new VectorFloat3 (1, 2, 3), boundaryVertices [0]);
Assert.AreEqual (new VectorFloat3 (4, 5, 6), boundaryVertices [1]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comments about several asserts.

Comment thread src/arkit.cs

[iOS (11,3)]
[BaseType (typeof(SCNGeometry))]
interface ARSCNPlaneGeometry {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the base SCNGeometry class does not have a default .ctor
and since there seems to be a requirement for a metal device it seems likely this type cannot be created with init

@VincentDondain VincentDondain Jan 29, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not specified in the headers but I agree with you it makes sense (it's safer to ship it with [DisableDefaultCtor]. Also it's then similar to ARSCNFaceGeometry.

Comment thread src/arkit.cs

[NoWatch, NoTV, NoMac, iOS (11,3)]
[BaseType (typeof(NSObject))]
interface ARReferenceImage : NSCopying, NSSecureCoding {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also not clear it can be created with init, the 2 .ctors don't accept nil images
easier to add it later than removing it (breaking changes)

Comment thread src/arkit.cs
[BaseType (typeof(SCNGeometry))]
[DisableDefaultCtor]
interface ARSCNFaceGeometry {
[Obsolete ("Use the 'Create' static constructor instead.")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put Obsolete under a !XAMCORE_4_0
also invert them, so the right one (this one) does not call the obsolete one
i.e. the bad one should suffer the extra call (and makes the !XAMCORE_4_0 compile

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

Comment thread src/arkit.cs
[Wrap ("CreateFaceGeometry (device)")]
ARSCNFaceGeometry Create (IMTLDevice device);

[Obsolete ("Use the 'Create' static constructor instead.")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Comment thread src/arkit.cs

[NoWatch, NoTV, NoMac, iOS (11,3)]
[BaseType (typeof(ARAnchor))]
interface ARImageAnchor {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the base type ARAnchor has a [DisableDefaultCtor] and I don't see any reason for this subclass not to have it ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmh so ARAnchor.h has:

/**
 Initializes a new anchor object.
 @param transform The transformation matrix that defines the anchor’s rotation, translation and scale in world coordinates.
 */
- (instancetype)initWithTransform:(matrix_float4x4)transform;

/** Unavailable */
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

ARImageAnchor and ARFaceAnchor (the only 2 subclasses) only have:

/** Unavailable */
- (instancetype)initWithTransform:(matrix_float4x4)transform NS_UNAVAILABLE;

Nothing is specified for init and new but given that initWithTransform is unavailable the must still have 1 constructor left (:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, init* are methods in objc so they are inherited
and that's why we need to inline some init* in subclasses
still it means no init - it's the `initWithTransform1 that must be duplicated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea ok so indeed init and new are also unavailable in the subclasses because they are inherited so [DisableDefaultCtor] makes sense (btw that could be caught by a test no? Unless the subclass in ObjC sometimes re-expose init and new even it's marked as unavailable in the parent?).

Now I don't follow your conclusion because initWithTransform is explicitly marked as unavailable. Looks like this type is not meant to be created by the user.

@VincentDondain

Copy link
Copy Markdown
Contributor Author

@spouliot @mandel-macaque @dalexsoto please re-review (:

@monojenkins

Copy link
Copy Markdown
Contributor

Build success

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@VincentDondain
VincentDondain dismissed mandel-macaque’s stale review January 30, 2018 21:59

Sorry Manuel but I have to dismiss your review to merge this PR. I addressed your changes (they were non-blocking)

@VincentDondain
VincentDondain merged commit 4c25aa9 into dotnet:xcode9.3 Jan 30, 2018
@VincentDondain
VincentDondain deleted the xcode9.3-arkit-b1 branch January 30, 2018 22:09
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.

6 participants