Code Duplication    Length = 47-47 lines in 2 locations

src/Location/Processor/Polyline/Simplify.php 1 location

@@ 111-157 (lines=47) @@
108
     *
109
     * @return number
110
     */
111
    protected function getPerpendicularDistance(Coordinate $point, Line $line)
112
    {
113
        $ellipsoid = $point->getEllipsoid();
114
115
        $ellipsoidRadius = $ellipsoid->getArithmeticMeanRadius();
116
117
        $firstLinePointLat = $this->deg2radLatitude($line->getPoint1()->getLat());
118
        $firstLinePointLng = $this->deg2radLongitude($line->getPoint1()->getLng());
119
120
        $firstLinePointX = $ellipsoidRadius * cos($firstLinePointLng) * sin($firstLinePointLat);
121
        $firstLinePointY = $ellipsoidRadius * sin($firstLinePointLng) * sin($firstLinePointLat);
122
        $firstLinePointZ = $ellipsoidRadius * cos($firstLinePointLat);
123
124
        $secondLinePointLat = $this->deg2radLatitude($line->getPoint2()->getLat());
125
        $secondLinePointLng = $this->deg2radLongitude($line->getPoint2()->getLng());
126
127
        $secondLinePointX = $ellipsoidRadius * cos($secondLinePointLng) * sin($secondLinePointLat);
128
        $secondLinePointY = $ellipsoidRadius * sin($secondLinePointLng) * sin($secondLinePointLat);
129
        $secondLinePointZ = $ellipsoidRadius * cos($secondLinePointLat);
130
131
        $pointLat = $this->deg2radLatitude($point->getLat());
132
        $pointLng = $this->deg2radLongitude($point->getLng());
133
134
        $pointX = $ellipsoidRadius * cos($pointLng) * sin($pointLat);
135
        $pointY = $ellipsoidRadius * sin($pointLng) * sin($pointLat);
136
        $pointZ = $ellipsoidRadius * cos($pointLat);
137
138
        $normalizedX = $firstLinePointY * $secondLinePointZ - $firstLinePointZ * $secondLinePointY;
139
        $normalizedY = $firstLinePointZ * $secondLinePointX - $firstLinePointX * $secondLinePointZ;
140
        $normalizedZ = $firstLinePointX * $secondLinePointY - $firstLinePointY * $secondLinePointX;
141
142
        $length = sqrt($normalizedX * $normalizedX + $normalizedY * $normalizedY + $normalizedZ * $normalizedZ);
143
144
        $normalizedX /= $length;
145
        $normalizedY /= $length;
146
        $normalizedZ /= $length;
147
148
        $thetaPoint = $normalizedX * $pointX + $normalizedY * $pointY + $normalizedZ * $pointZ;
149
150
        $length = sqrt($pointX * $pointX + $pointY * $pointY + $pointZ * $pointZ);
151
152
        $thetaPoint /= $length;
153
154
        $distance = abs((M_PI / 2) - acos($thetaPoint));
155
156
        return $distance * $ellipsoidRadius;
157
    }
158
159
    /**
160
     * @param float $latitude

src/Location/Utility/PerpendicularDistance.php 1 location

@@ 30-76 (lines=47) @@
27
     *
28
     * @return float
29
     */
30
    public function getPerpendicularDistance(Coordinate $point, Line $line)
31
    {
32
        $ellipsoid = $point->getEllipsoid();
33
34
        $ellipsoidRadius = $ellipsoid->getArithmeticMeanRadius();
35
36
        $firstLinePointLat = $this->deg2radLatitude($line->getPoint1()->getLat());
37
        $firstLinePointLng = $this->deg2radLongitude($line->getPoint1()->getLng());
38
39
        $firstLinePointX = $ellipsoidRadius * cos($firstLinePointLng) * sin($firstLinePointLat);
40
        $firstLinePointY = $ellipsoidRadius * sin($firstLinePointLng) * sin($firstLinePointLat);
41
        $firstLinePointZ = $ellipsoidRadius * cos($firstLinePointLat);
42
43
        $secondLinePointLat = $this->deg2radLatitude($line->getPoint2()->getLat());
44
        $secondLinePointLng = $this->deg2radLongitude($line->getPoint2()->getLng());
45
46
        $secondLinePointX = $ellipsoidRadius * cos($secondLinePointLng) * sin($secondLinePointLat);
47
        $secondLinePointY = $ellipsoidRadius * sin($secondLinePointLng) * sin($secondLinePointLat);
48
        $secondLinePointZ = $ellipsoidRadius * cos($secondLinePointLat);
49
50
        $pointLat = $this->deg2radLatitude($point->getLat());
51
        $pointLng = $this->deg2radLongitude($point->getLng());
52
53
        $pointX = $ellipsoidRadius * cos($pointLng) * sin($pointLat);
54
        $pointY = $ellipsoidRadius * sin($pointLng) * sin($pointLat);
55
        $pointZ = $ellipsoidRadius * cos($pointLat);
56
57
        $normalizedX = $firstLinePointY * $secondLinePointZ - $firstLinePointZ * $secondLinePointY;
58
        $normalizedY = $firstLinePointZ * $secondLinePointX - $firstLinePointX * $secondLinePointZ;
59
        $normalizedZ = $firstLinePointX * $secondLinePointY - $firstLinePointY * $secondLinePointX;
60
61
        $length = sqrt($normalizedX * $normalizedX + $normalizedY * $normalizedY + $normalizedZ * $normalizedZ);
62
63
        $normalizedX /= $length;
64
        $normalizedY /= $length;
65
        $normalizedZ /= $length;
66
67
        $thetaPoint = $normalizedX * $pointX + $normalizedY * $pointY + $normalizedZ * $pointZ;
68
69
        $length = sqrt($pointX * $pointX + $pointY * $pointY + $pointZ * $pointZ);
70
71
        $thetaPoint /= $length;
72
73
        $distance = abs((M_PI / 2) - acos($thetaPoint));
74
75
        return $distance * $ellipsoidRadius;
76
    }
77
78
    /**
79
     * @param float $latitude