Skip to content

Commit 22a81fb

Browse files
committed
Degrees to Radians and Radians to Degrees cleaning.
1 parent 2ae283e commit 22a81fb

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/charting/charts/PieChart.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ export class PieChart extends PieRadarChartBase<Entry, PieDataSet, PieData> {
170170
// calculate the text position
171171
let x = (r
172172
* Math.cos(((rotationAngle + this.mAbsoluteAngles[entryIndex] - offset)
173-
* this.mAnimator.getPhaseY()) * (Math.PI / 180)) + center.x);
173+
* this.mAnimator.getPhaseY()) * Utils.DEG2RAD) + center.x);
174174
let y = (r
175175
* Math.sin(((rotationAngle + this.mAbsoluteAngles[entryIndex] - offset)
176-
* this.mAnimator.getPhaseY()) * (Math.PI / 180)) + center.y);
176+
* this.mAnimator.getPhaseY()) * Utils.DEG2RAD) + center.y);
177177

178178
return [x, y];
179179
}

src/charting/charts/PieRadarChartBase.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export abstract class PieRadarChartBase<U extends Entry, D extends IDataSet<U>,
229229
const length = Math.sqrt(tx * tx + ty * ty);
230230
const radians = Math.acos(ty / length);
231231

232-
let angle = radians * (180 / Math.PI);
232+
let angle = radians * Utils.RAD2DEG;
233233

234234
if (x > c.x) {
235235
angle = 360 - angle;
@@ -257,8 +257,8 @@ export abstract class PieRadarChartBase<U extends Entry, D extends IDataSet<U>,
257257
*/
258258
public getPosition(center: MPPointF, dist: number, angle: number, outputPoint: MPPointF = {x: 0, y: 0}): MPPointF {
259259

260-
outputPoint.x = (center.x + dist * Math.cos(angle * (Math.PI / 180)));
261-
outputPoint.y = (center.y + dist * Math.sin(angle * (Math.PI / 180)));
260+
outputPoint.x = (center.x + dist * Math.cos(angle * Utils.DEG2RAD));
261+
outputPoint.y = (center.y + dist * Math.sin(angle * Utils.DEG2RAD));
262262
return outputPoint;
263263
}
264264

src/charting/renderer/PieChartRenderer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,8 @@ export class PieChartRenderer extends DataRenderer {
884884
// draw only if the value is greater than zero
885885
if ((Math.abs(e[yKey]) > Utils.NUMBER_EPSILON)) {
886886

887-
let x = ((r - circleRadius) * Math.cos(((angle + sliceAngle) * phaseY) * (Math.PI / 180)) + center.x);
888-
let y = ((r - circleRadius) * Math.sin(((angle + sliceAngle) * phaseY) * (Math.PI / 180)) + center.y);
887+
let x = ((r - circleRadius) * Math.cos(((angle + sliceAngle) * phaseY) * Utils.DEG2RAD) + center.x);
888+
let y = ((r - circleRadius) * Math.sin(((angle + sliceAngle) * phaseY) * Utils.DEG2RAD) + center.y);
889889

890890
this.mRenderPaint.setColor(dataSet.getColor(j));
891891
this.mBitmapCanvas.drawCircle(x, y, circleRadius, this.mRenderPaint);

src/charting/utils/Utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export namespace Utils {
2929
// const DOUBLE_EPSILON = Number.EPSILON;
3030

3131
export const DEG2RAD = Math.PI / 180.0;
32+
export const RAD2DEG = 180.0 / Math.PI;
3233
export const NUMBER_EPSILON = Number.EPSILON;
3334

3435
const mDrawTextRectBuffer = new Rect(0, 0, 0, 0);

0 commit comments

Comments
 (0)