Skip to content

Commit

Permalink
Abstract functions getGraphX() and getGraphY() now receive value of g…
Browse files Browse the repository at this point in the history
…etT()

More comments in code
  • Loading branch information
Vladimir Jovanovic committed Jan 26, 2017
1 parent 2a4229f commit c2b17e0
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -23,7 +23,7 @@ Add to your module's build.gradle:
and to your app build.gradle:

dependencies {
compile 'com.github.vlad1m1r990:Lemniscate:1.0.2'
compile 'com.github.vlad1m1r990:Lemniscate:1.1.0'
}

Usage
Expand Down
4 changes: 2 additions & 2 deletions lemniscate/build.gradle
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 25
versionCode 100
versionName "1.0.0"
versionCode 110
versionName "1.1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
11 changes: 4 additions & 7 deletions lemniscate/src/main/AndroidManifest.xml
@@ -1,11 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vlad1m1r.lemniscate.sample.lemniscate">

<application android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
>

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
</application>

</manifest>
Expand Up @@ -23,14 +23,11 @@ public BernoullisProgressView(Context context, AttributeSet attrs, int defStyleA
super(context, attrs, defStyleAttr);
}

public double getGraphY(int i){
double t = getT(i);
public double getGraphY(double t){
return (mLemniscateParamY * Math.sin(t) * Math.cos(t)) / (1 + Math.pow(Math.sin(t), 2));
}

public double getGraphX(int i){
// function is repeating every 2π and is defined from [0, 2π] so this is putting i∈[0, mPrecision) points between these two values
double t = getT(i);
public double getGraphX(double t){
// trigonometric function for value of x for t∈[0, 2π)
return (mLemniscateParamX * Math.cos(t)) / (1 + Math.pow(Math.sin(t), 2));
}
Expand Down
Expand Up @@ -24,14 +24,12 @@ public GeronosProgressView(Context context, AttributeSet attrs, int defStyleAttr
}

@Override
public double getGraphY(int i) {
double t = getT(i);
public double getGraphY(double t) {
return mLemniscateParamX * Math.sin(t) * Math.cos(t);
}

@Override
public double getGraphX(int i) {
double t = getT(i);
public double getGraphX(double t) {
return mLemniscateParamX * Math.sin(t);
}
}
Expand Up @@ -41,6 +41,9 @@ public abstract class BaseCurveProgressView extends View {

protected float mStrokeWidth = getResources().getDimension(R.dimen.lemniscate_stroke_width);

/**
* Default size of view will be multiplied with this number
*/
protected float mSizeMultiplier = 1;

protected double mLemniscateParamX, mLemniscateParamY;
Expand All @@ -56,6 +59,9 @@ public abstract class BaseCurveProgressView extends View {
*/
protected float mLineMinLength = 0.4f, mLineMaxLength = 0.8f;

/**
* If true, the line length will oscillate between mLineMinLength and mLineMaxLength
*/
protected boolean mIsLineLengthChangeable = true;

/**
Expand Down Expand Up @@ -149,9 +155,21 @@ private void init() {
mPaint.setStrokeCap(Paint.Cap.ROUND);
}

public abstract double getGraphY(int i);
/**
* This method should return values of y for t∈[0, upper limit of getT() function].
* We should use parametric representation of curve for y.
* Curve should be closed and periodic on interval that returns getT().
* Resulting value should satisfy y∈[-mLemniscateParamY, mLemniscateParamY].
*/
public abstract double getGraphY(double t);

public abstract double getGraphX(int i);
/**
* This method should return values of x for t∈[0, upper limit of getT() function].
* We should use parametric representation of curve for x.
* Curve should be closed and periodic on interval that returns getT().
* Resulting value should satisfy x∈[-mLemniscateParamX, upper limit of getT() function].
*/
public abstract double getGraphX(double t);

@Override
protected void onDraw(Canvas canvas) {
Expand Down Expand Up @@ -216,8 +234,8 @@ private int getPointsOnCurve(ArrayList<Pair<Float, Float>> list, @Nullable Integ
for (int i = start != null ? start : 0; i < mPrecision; i++) {

// translates points to positive coordinates
double x = getGraphX(i) + mLemniscateParamX;
double y = getGraphY(i) + mLemniscateParamY;
double x = getGraphX(getT(i)) + mLemniscateParamX;
double y = getGraphY(getT(i)) + mLemniscateParamY;

addPointToList(list, x, y);

Expand All @@ -232,15 +250,14 @@ private int getPointsOnCurve(ArrayList<Pair<Float, Float>> list, @Nullable Integ

private void addPointToList(ArrayList<Pair<Float, Float>> list, double x, double y) {

//finds smallest ratio for which lemniscate should be resized because of stroke width
//it's not just 1 * mStrokeWidth because it's behavior is strange for tick lines
//finds smallest ratio for which curve should be resized because of stroke width
float ratio = mViewHeight/(mViewHeight + 2 * mStrokeWidth);

//move every point for ratio
x = x * ratio;
y = y * ratio;

//moves points so that lemniscate is centered
//moves points so that curve is centered
x = x + mStrokeWidth * ratio;
y = y + mStrokeWidth * ratio;

Expand Down Expand Up @@ -544,7 +561,12 @@ public void setPrecision(int precision) {
invalidate();
}

public double getT(int i) {

/**
* @param i ∈ [0, mPrecision)
* @return function is putting i∈[0, mPrecision) points between [0, 2π]
*/
protected double getT(int i) {
return i*2*Math.PI/mPrecision;
}
}
Expand Up @@ -24,14 +24,12 @@ public CannabisProgressView(Context context, AttributeSet attrs, int defStyleAtt
}

@Override
public double getGraphY(int i) {
double t = getT(i);
public double getGraphY(double t) {
return -mLemniscateParamY/3 * Math.sin(t) * (Math.sin(t) + 1) * (9/10f * Math.cos(8*t) + 1) * (1/10f * Math.cos(24*t) + 1) * (1/10f * Math.cos(200*t) + 9/10f) + mLemniscateParamY/2;
}

@Override
public double getGraphX(int i) {
double t = getT(i);
public double getGraphX(double t) {
return mLemniscateParamX/3 * (Math.sin(t) + 1) * Math.cos(t) * (9/10f * Math.cos(8*t) + 1) * (1/10f * Math.cos(24*t) + 1) * (1/10f * Math.cos(200*t) + 9/10f);
}
}
Expand Up @@ -24,14 +24,12 @@ public HeartProgressView(Context context, AttributeSet attrs, int defStyleAttr)
}

@Override
public double getGraphY(int i) {
double t = getT(i);
public double getGraphY(double t) {
return -mLemniscateParamY/17 * (13 * Math.cos(t) - 5 * Math.cos(2*t) - 2 * Math.cos(3*t) - Math.cos(4*t));
}

@Override
public double getGraphX(int i) {
double t = getT(i);
public double getGraphX(double t) {
return mLemniscateParamX/17 * 16 * Math.pow(Math.sin(t), 3);
}
}
Expand Up @@ -94,7 +94,7 @@ public void setNumberOfCycles(float numberOfCycles) {

@Override
public double getT(int i) {
return i* mNumberOfCycles *2*Math.PI/mPrecision;
return i * mNumberOfCycles * 2 * Math.PI / mPrecision;
}

@Override
Expand Down
Expand Up @@ -24,16 +24,14 @@ public EpitrochoidProgressView(Context context, AttributeSet attrs, int defStyle
}

@Override
public double getGraphY(int i) {
public double getGraphY(double t) {
//y = (mRadiusFixed + mRadiusMoving) sin(t) - mDistanceFromCenter sin(((mRadiusFixed+mRadiusMoving)/mRadiusMoving)*t)
double t = getT(i);
return mLemniscateParamY/((mRadiusFixed + mDistanceFromCenter + mRadiusMoving))*((mRadiusFixed + mRadiusMoving)*Math.sin(t) - mDistanceFromCenter *Math.sin(((mRadiusFixed + mRadiusMoving)/ mRadiusMoving)*t));
}

@Override
public double getGraphX(int i) {
public double getGraphX(double t) {
//x = (mRadiusFixed + mRadiusMoving) cos(t) + mRadiusMoving cos(((mRadiusFixed+mRadiusMoving)/mRadiusMoving)*t),
double t = getT(i);
return mLemniscateParamY/((mRadiusFixed + mDistanceFromCenter + mRadiusMoving))*((mRadiusFixed + mRadiusMoving)*Math.cos(t) - mDistanceFromCenter *Math.cos(((mRadiusFixed + mRadiusMoving)/ mRadiusMoving)*t));
}

Expand Down
Expand Up @@ -24,16 +24,14 @@ public HypotrochoidProgressView(Context context, AttributeSet attrs, int defStyl
}

@Override
public double getGraphY(int i) {
public double getGraphY(double t) {
//y = (mRadiusFixed - mRadiusMoving) sin(t) - mRadiusMoving sin(((mRadiusFixed-mRadiusMoving)/mRadiusMoving)*t)
double t = getT(i);
return mLemniscateParamY/((mRadiusFixed + mDistanceFromCenter - mRadiusMoving))*((mRadiusFixed - mRadiusMoving)*Math.sin(t) + mDistanceFromCenter *Math.sin(((mRadiusFixed - mRadiusMoving)/ mRadiusMoving)*t));
}

@Override
public double getGraphX(int i) {
public double getGraphX(double t) {
//x = (mRadiusFixed - mRadiusMoving) cos(t) + mRadiusMoving cos(((mRadiusFixed-mRadiusMoving)/mRadiusMoving)*t),
double t = getT(i);
return mLemniscateParamY/((mRadiusFixed + mDistanceFromCenter - mRadiusMoving))*((mRadiusFixed - mRadiusMoving)*Math.cos(t) - mDistanceFromCenter *Math.cos(((mRadiusFixed - mRadiusMoving)/ mRadiusMoving)*t));
}

Expand Down

0 comments on commit c2b17e0

Please sign in to comment.