# Refactor out `_d2` function #262

Closed
opened this issue May 15, 2019 · 2 comments

Projects
None yet
2 participants
Collaborator

## First Time?

This is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.

If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!

We know that the process of creating a pull request is the biggest barrier for new contributors. This issue is for you 💝

If you have contributed before, consider leaving this one for someone new, and looking through our general help wanted issues. Thanks!

### 🤔 What you will need to know.

Nothing. This issue is meant to welcome you to Open Source :) We are happy to walk you through the process.

## The problem

We rewrite the same function, `_d2` in a few of our files for each new "handle" class to have. Instead, we can define this function on `L.EditHandle`, the common class the other handle classes extend, and it will be available to all of them.

## Solution

Where to find the relevant lines of code:

Delete the `_d2` function from the following files:

Lines 56 to 62 in d91b2d7

 /* Distance between two points in cartesian space, squared (distance formula). */ _d2: function(a, b) { var dx = a.x - b.x, dy = a.y - b.y; return Math.pow(dx, 2) + Math.pow(dy, 2); }

Lines 72 to 78 in d91b2d7

 /* Distance between two points in cartesian space, squared (distance formula). */ _d2: function(a, b) { var dx = a.x - b.x, dy = a.y - b.y; return Math.pow(dx, 2) + Math.pow(dy, 2); }

Lines 57 to 63 in d91b2d7

 /* Distance between two points in cartesian space, squared (distance formula). */ _d2: function(a, b) { var dx = a.x - b.x, dy = a.y - b.y; return Math.pow(dx, 2) + Math.pow(dy, 2); }

1. Then, copy it into `src/edit/EditHandle.js` (you can add it as the last function defined on the `L.EditHandle` class).

Thanks!!

## Step by Step

• Claim this issue with a comment here, below, and ask any clarifying questions you need
• Fork the repository and set it up locally following the main repo README instructions https://github.com/publiclab/Leaflet.DistortableImage
• Create a new feature branch with a unique name descriptive to the issue
• Try to fix the issue following the steps above, but even before you're done, you can:
commit your changes to your branch and start a pull request (see contributing to Public Lab software) but mark it as "in progress" if you have questions or if you haven't finished
• Reference this issue in your pull request body
• Once you submit your pull request, if there's an additional checklist provided for getting it merged, get those boxes checked off. Either way, mention me @sashadev-sky for a review.

💬 - We encourage contributors to be respectful to the community and provide an update within a week of claiming a first-timers-only issue. We're happy to keep it assigned to you as long as you need if you update us, but if we don't see any activity a week after you claim it we may reassign it to give someone else a chance. Thank you in advance!

If this happens to you, don't sweat it! Grab another open issue.

## 💬 Get help

If you need any help - here are some options:

Open

Contributor

### esraodaci commented May 15, 2019

 I would like to claim this one
Collaborator Author

### sashadev-sky commented May 15, 2019

 @esraodaci Thank you it is all yours :)

### esraodaci added a commit to esraodaci/Leaflet.DistortableImage that referenced this issue May 16, 2019

``` Fixes publiclab#262 ```
``` a08adae ```

Merged

### sashadev-sky added a commit to esraodaci/Leaflet.DistortableImage that referenced this issue May 20, 2019

``` Fixes publiclab#262 ```
``` a8928c4 ```

### sashadev-sky added a commit that referenced this issue May 20, 2019

``` Fixes #262 (#266) ```
```* Fixes #262

* refactor out d2 function update```
``` 99bef12 ```