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

ADD: getAngle() method #480

Merged
merged 2 commits into from
Dec 22, 2019
Merged

ADD: getAngle() method #480

merged 2 commits into from
Dec 22, 2019

Conversation

VladimirMikulic
Copy link
Contributor

@VladimirMikulic VladimirMikulic commented Dec 20, 2019

The video shows the method in action.
getAngle() returns a value in degrees(0 - 360).

Resolves #102

@keshav234156 @jywarren @rexagod could someone review this?
Thanks.

@SidharthBansal
Copy link
Member

Seems good to me.
Let's wait for Sasha's approval before merge. I have approved this issue at the GCI dashboard as Sasha is busy in the office. This will enable you to work on other tasks in the meantime.
Don't forget to complete this task as per Sasha's suggestions. As marking will be based on the form circulated at the end week of GCI. We will evaluate the tasks at that time.
Thanks

@SidharthBansal
Copy link
Member

Can we write a test here ?

@VladimirMikulic
Copy link
Contributor Author

Hi @SidharthBansal. Thank you for approving the task.
Unfortunately, I can't add a test for this since I access the matrix via CSS.

This HOF task seems to be redundant.
It is already solved, we have rotateBy() method that rotates the image.

@sashadev-sky
Copy link
Member

looking now! thanks guys

Copy link
Member

@sashadev-sky sashadev-sky left a comment

Choose a reason for hiding this comment

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

this is so great!! Just some refactoring stuff and we can merge thank you so much!

also, remember to run $ grunt concat:dist so that your changes get concatenated into the dist file (dist/leaflet.distortableimage.js) and commit that file here too.

Easy way to remember that part is to just run $ grunt in a separate terminal tab as you make changes and it'll update it for you automatically

src/DistortableImageOverlay.js Show resolved Hide resolved
@@ -274,6 +274,21 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
return this;
},

getAngle: function() {
var matrix = this._image.style.transform
Copy link
Member

Choose a reason for hiding this comment

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

small refactor to use Leaflet helper methods:

Suggested change
var matrix = this._image.style.transform
var matrix = L.DomUtil.getStyle(this.getElement(), 'transform')

.slice(1, -1)
.split(',');

var angle = Math.round(Math.atan2(matrix[1], matrix[0]) * (180 / Math.PI));
Copy link
Member

Choose a reason for hiding this comment

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

Any specific reason to round here? If not, lets just leave it unrounded?

Suggested change
var angle = Math.round(Math.atan2(matrix[1], matrix[0]) * (180 / Math.PI));
var angle = Math.atan2(matrix[1], matrix[0]) * (180 / Math.PI);

src/DistortableImageOverlay.js Outdated Show resolved Hide resolved
src/DistortableImageOverlay.js Outdated Show resolved Hide resolved
src/DistortableImageOverlay.js Outdated Show resolved Hide resolved
@SidharthBansal
Copy link
Member

SidharthBansal commented Dec 22, 2019 via email

@sashadev-sky
Copy link
Member

@SidharthBansal @VladimirMikulic setRotate would be different from rotateBy because setRotate would set the img to a specific rotation not rotate by a certain amount. So thats still missing from here!

Also: one more thing - if we flip the image upside down by dragging the top 2 corners lower than the bottom 2, the rotation becomes incorrect. I was thinking maybe the solution would be to do:

var row0x = matrix[0];
var row0y = matrix[1];
var row1x = matrix[4];
var row1y = matrix[5];

var determinant = row0x * row1y - row0y * row1x;

var angle = Math.atan2(row0y, row0x) * (180 / Math.PI);

if (determinant < 0) {
   angle += angle < 0 ? 180 : -180;
 }

if (angle < 0) {
  angle = 360 + angle;
}

// ignore my Math.abs(angle) suggestion earlier
return angle;

@VladimirMikulic can you confirm if you think this is correct or not

@VladimirMikulic
Copy link
Contributor Author

@sashadev-sky you were right. When we flip the image my implementation shows 360 instead of 180.
I didn't calculate the determinant, good catch 👍

Also, thanks for clarifying the difference between rotateBy and setAngle/setRotate.

Copy link
Member

@sashadev-sky sashadev-sky left a comment

Choose a reason for hiding this comment

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

Ok this is great!! We're good to go. It just seems like you made some extra updates to the DragHandle file so if we can undo those and remove them from the dist file were all set to go. Lmk if you'll need help

The old implementation of getAngle() method would show the incorrect angle
when we flip the image by dragging the 2 top corners below the bottom 2
corners.

This change resolves it.
@VladimirMikulic
Copy link
Contributor Author

Resolved

Copy link
Member

@sashadev-sky sashadev-sky left a comment

Choose a reason for hiding this comment

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

👑

@sashadev-sky sashadev-sky merged commit 4f6f71e into publiclab:main Dec 22, 2019
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.

Get rotate angle of image layer
3 participants