package com.airbnb.lottie.animation.content; import android.graphics.Path; import android.graphics.PointF; import com.airbnb.lottie.LottieDrawable; import com.airbnb.lottie.LottieProperty; import com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation; import com.airbnb.lottie.model.KeyPath; import com.airbnb.lottie.model.content.PolystarShape; import com.airbnb.lottie.model.content.ShapeTrimPath; import com.airbnb.lottie.model.layer.BaseLayer; import com.airbnb.lottie.utils.MiscUtils; import com.airbnb.lottie.value.LottieValueCallback; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import java.util.List; /* loaded from: classes.dex */ public class PolystarContent implements PathContent, BaseKeyframeAnimation.AnimationListener, KeyPathElementContent { private static final float POLYGON_MAGIC_NUMBER = 0.25f; private static final float POLYSTAR_MAGIC_NUMBER = 0.47829f; private final boolean hidden; private final BaseKeyframeAnimation innerRadiusAnimation; private final BaseKeyframeAnimation innerRoundednessAnimation; private boolean isPathValid; private final boolean isReversed; private final LottieDrawable lottieDrawable; private final String name; private final BaseKeyframeAnimation outerRadiusAnimation; private final BaseKeyframeAnimation outerRoundednessAnimation; private final BaseKeyframeAnimation pointsAnimation; private final BaseKeyframeAnimation positionAnimation; private final BaseKeyframeAnimation rotationAnimation; private final PolystarShape.Type type; private final Path path = new Path(); private final CompoundTrimPathContent trimPaths = new CompoundTrimPathContent(); public PolystarContent(LottieDrawable lottieDrawable, BaseLayer baseLayer, PolystarShape polystarShape) { BaseKeyframeAnimation baseKeyframeAnimation; this.lottieDrawable = lottieDrawable; this.name = polystarShape.getName(); PolystarShape.Type type = polystarShape.getType(); this.type = type; this.hidden = polystarShape.isHidden(); this.isReversed = polystarShape.isReversed(); BaseKeyframeAnimation createAnimation = polystarShape.getPoints().createAnimation(); this.pointsAnimation = createAnimation; BaseKeyframeAnimation createAnimation2 = polystarShape.getPosition().createAnimation(); this.positionAnimation = createAnimation2; BaseKeyframeAnimation createAnimation3 = polystarShape.getRotation().createAnimation(); this.rotationAnimation = createAnimation3; BaseKeyframeAnimation createAnimation4 = polystarShape.getOuterRadius().createAnimation(); this.outerRadiusAnimation = createAnimation4; BaseKeyframeAnimation createAnimation5 = polystarShape.getOuterRoundedness().createAnimation(); this.outerRoundednessAnimation = createAnimation5; if (type == PolystarShape.Type.STAR) { this.innerRadiusAnimation = polystarShape.getInnerRadius().createAnimation(); baseKeyframeAnimation = polystarShape.getInnerRoundedness().createAnimation(); } else { baseKeyframeAnimation = null; this.innerRadiusAnimation = null; } this.innerRoundednessAnimation = baseKeyframeAnimation; baseLayer.addAnimation(createAnimation); baseLayer.addAnimation(createAnimation2); baseLayer.addAnimation(createAnimation3); baseLayer.addAnimation(createAnimation4); baseLayer.addAnimation(createAnimation5); if (type == PolystarShape.Type.STAR) { baseLayer.addAnimation(this.innerRadiusAnimation); baseLayer.addAnimation(this.innerRoundednessAnimation); } createAnimation.addUpdateListener(this); createAnimation2.addUpdateListener(this); createAnimation3.addUpdateListener(this); createAnimation4.addUpdateListener(this); createAnimation5.addUpdateListener(this); if (type == PolystarShape.Type.STAR) { this.innerRadiusAnimation.addUpdateListener(this); this.innerRoundednessAnimation.addUpdateListener(this); } } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.AnimationListener public void onValueChanged() { invalidate(); } private void invalidate() { this.isPathValid = false; this.lottieDrawable.invalidateSelf(); } @Override // com.airbnb.lottie.animation.content.Content public void setContents(List list, List list2) { for (int i = 0; i < list.size(); i++) { Content content = list.get(i); if (content instanceof TrimPathContent) { TrimPathContent trimPathContent = (TrimPathContent) content; if (trimPathContent.getType() == ShapeTrimPath.Type.SIMULTANEOUSLY) { this.trimPaths.addTrimPath(trimPathContent); trimPathContent.addListener(this); } } } } @Override // com.airbnb.lottie.animation.content.PathContent public Path getPath() { if (this.isPathValid) { return this.path; } this.path.reset(); if (this.hidden) { this.isPathValid = true; return this.path; } int i = AnonymousClass1.$SwitchMap$com$airbnb$lottie$model$content$PolystarShape$Type[this.type.ordinal()]; if (i == 1) { createStarPath(); } else if (i == 2) { createPolygonPath(); } this.path.close(); this.trimPaths.apply(this.path); this.isPathValid = true; return this.path; } /* renamed from: com.airbnb.lottie.animation.content.PolystarContent$1, reason: invalid class name */ /* loaded from: classes.dex */ static /* synthetic */ class AnonymousClass1 { static final int[] $SwitchMap$com$airbnb$lottie$model$content$PolystarShape$Type; static { int[] iArr = new int[PolystarShape.Type.values().length]; $SwitchMap$com$airbnb$lottie$model$content$PolystarShape$Type = iArr; try { iArr[PolystarShape.Type.STAR.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { $SwitchMap$com$airbnb$lottie$model$content$PolystarShape$Type[PolystarShape.Type.POLYGON.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } } } private void createStarPath() { int i; float f; float f2; double d; float f3; float f4; float f5; float f6; double d2; float f7; float f8; float f9; double d3; float floatValue = this.pointsAnimation.getValue().floatValue(); double radians = Math.toRadians((this.rotationAnimation == null ? 0.0d : r2.getValue().floatValue()) - 90.0d); double d4 = floatValue; float f10 = (float) (6.283185307179586d / d4); if (this.isReversed) { f10 = -f10; } float f11 = f10 / 2.0f; float f12 = floatValue - ((int) floatValue); int i2 = (f12 > BitmapDescriptorFactory.HUE_RED ? 1 : (f12 == BitmapDescriptorFactory.HUE_RED ? 0 : -1)); if (i2 != 0) { radians += (1.0f - f12) * f11; } float floatValue2 = this.outerRadiusAnimation.getValue().floatValue(); float floatValue3 = this.innerRadiusAnimation.getValue().floatValue(); BaseKeyframeAnimation baseKeyframeAnimation = this.innerRoundednessAnimation; float floatValue4 = baseKeyframeAnimation != null ? baseKeyframeAnimation.getValue().floatValue() / 100.0f : 0.0f; BaseKeyframeAnimation baseKeyframeAnimation2 = this.outerRoundednessAnimation; float floatValue5 = baseKeyframeAnimation2 != null ? baseKeyframeAnimation2.getValue().floatValue() / 100.0f : 0.0f; if (i2 != 0) { f4 = ((floatValue2 - floatValue3) * f12) + floatValue3; i = i2; double d5 = f4; float cos = (float) (d5 * Math.cos(radians)); f3 = (float) (d5 * Math.sin(radians)); this.path.moveTo(cos, f3); d = radians + ((f10 * f12) / 2.0f); f = cos; f2 = f11; } else { i = i2; double d6 = floatValue2; float cos2 = (float) (Math.cos(radians) * d6); float sin = (float) (d6 * Math.sin(radians)); this.path.moveTo(cos2, sin); f = cos2; f2 = f11; d = radians + f2; f3 = sin; f4 = BitmapDescriptorFactory.HUE_RED; } double ceil = Math.ceil(d4) * 2.0d; int i3 = 0; float f13 = f2; float f14 = f; boolean z = false; while (true) { double d7 = i3; if (d7 < ceil) { float f15 = z ? floatValue2 : floatValue3; if (f4 == BitmapDescriptorFactory.HUE_RED || d7 != ceil - 2.0d) { f5 = f10; f6 = f13; } else { f5 = f10; f6 = (f10 * f12) / 2.0f; } if (f4 == BitmapDescriptorFactory.HUE_RED || d7 != ceil - 1.0d) { d2 = d7; f7 = f4; f4 = f15; } else { d2 = d7; f7 = f4; } double d8 = f4; double d9 = ceil; float cos3 = (float) (d8 * Math.cos(d)); float sin2 = (float) (d8 * Math.sin(d)); if (floatValue4 == BitmapDescriptorFactory.HUE_RED && floatValue5 == BitmapDescriptorFactory.HUE_RED) { this.path.lineTo(cos3, sin2); d3 = d; f8 = floatValue4; f9 = floatValue5; } else { f8 = floatValue4; double atan2 = (float) (Math.atan2(f3, f14) - 1.5707963267948966d); float cos4 = (float) Math.cos(atan2); float sin3 = (float) Math.sin(atan2); f9 = floatValue5; d3 = d; double atan22 = (float) (Math.atan2(sin2, cos3) - 1.5707963267948966d); float cos5 = (float) Math.cos(atan22); float sin4 = (float) Math.sin(atan22); float f16 = z ? f8 : f9; float f17 = z ? f9 : f8; float f18 = z ? floatValue3 : floatValue2; float f19 = z ? floatValue2 : floatValue3; float f20 = f18 * f16 * POLYSTAR_MAGIC_NUMBER; float f21 = cos4 * f20; float f22 = f20 * sin3; float f23 = f19 * f17 * POLYSTAR_MAGIC_NUMBER; float f24 = cos5 * f23; float f25 = f23 * sin4; if (i != 0) { if (i3 == 0) { f21 *= f12; f22 *= f12; } else if (d2 == d9 - 1.0d) { f24 *= f12; f25 *= f12; } } this.path.cubicTo(f14 - f21, f3 - f22, cos3 + f24, sin2 + f25, cos3, sin2); } d = d3 + f6; z = !z; i3++; f14 = cos3; f3 = sin2; floatValue5 = f9; floatValue4 = f8; f4 = f7; f10 = f5; ceil = d9; } else { PointF value = this.positionAnimation.getValue(); this.path.offset(value.x, value.y); this.path.close(); return; } } } private void createPolygonPath() { int i; double d; double d2; double d3; int floor = (int) Math.floor(this.pointsAnimation.getValue().floatValue()); double radians = Math.toRadians((this.rotationAnimation == null ? 0.0d : r2.getValue().floatValue()) - 90.0d); double d4 = floor; float floatValue = this.outerRoundednessAnimation.getValue().floatValue() / 100.0f; float floatValue2 = this.outerRadiusAnimation.getValue().floatValue(); double d5 = floatValue2; float cos = (float) (Math.cos(radians) * d5); float sin = (float) (Math.sin(radians) * d5); this.path.moveTo(cos, sin); double d6 = (float) (6.283185307179586d / d4); double d7 = radians + d6; double ceil = Math.ceil(d4); int i2 = 0; while (i2 < ceil) { float cos2 = (float) (Math.cos(d7) * d5); double d8 = ceil; float sin2 = (float) (d5 * Math.sin(d7)); if (floatValue != BitmapDescriptorFactory.HUE_RED) { d2 = d5; i = i2; d = d7; double atan2 = (float) (Math.atan2(sin, cos) - 1.5707963267948966d); float cos3 = (float) Math.cos(atan2); float sin3 = (float) Math.sin(atan2); d3 = d6; double atan22 = (float) (Math.atan2(sin2, cos2) - 1.5707963267948966d); float cos4 = (float) Math.cos(atan22); float sin4 = (float) Math.sin(atan22); float f = floatValue2 * floatValue * POLYGON_MAGIC_NUMBER; this.path.cubicTo(cos - (cos3 * f), sin - (sin3 * f), cos2 + (cos4 * f), sin2 + (f * sin4), cos2, sin2); } else { i = i2; d = d7; d2 = d5; d3 = d6; this.path.lineTo(cos2, sin2); } d7 = d + d3; i2 = i + 1; sin = sin2; cos = cos2; ceil = d8; d5 = d2; d6 = d3; } PointF value = this.positionAnimation.getValue(); this.path.offset(value.x, value.y); this.path.close(); } @Override // com.airbnb.lottie.model.KeyPathElement public void resolveKeyPath(KeyPath keyPath, int i, List list, KeyPath keyPath2) { MiscUtils.resolveKeyPath(keyPath, i, list, keyPath2, this); } @Override // com.airbnb.lottie.model.KeyPathElement public void addValueCallback(T t, LottieValueCallback lottieValueCallback) { BaseKeyframeAnimation baseKeyframeAnimation; BaseKeyframeAnimation baseKeyframeAnimation2; if (t == LottieProperty.POLYSTAR_POINTS) { this.pointsAnimation.setValueCallback(lottieValueCallback); return; } if (t == LottieProperty.POLYSTAR_ROTATION) { this.rotationAnimation.setValueCallback(lottieValueCallback); return; } if (t == LottieProperty.POSITION) { this.positionAnimation.setValueCallback(lottieValueCallback); return; } if (t == LottieProperty.POLYSTAR_INNER_RADIUS && (baseKeyframeAnimation2 = this.innerRadiusAnimation) != null) { baseKeyframeAnimation2.setValueCallback(lottieValueCallback); return; } if (t == LottieProperty.POLYSTAR_OUTER_RADIUS) { this.outerRadiusAnimation.setValueCallback(lottieValueCallback); return; } if (t == LottieProperty.POLYSTAR_INNER_ROUNDEDNESS && (baseKeyframeAnimation = this.innerRoundednessAnimation) != null) { baseKeyframeAnimation.setValueCallback(lottieValueCallback); } else if (t == LottieProperty.POLYSTAR_OUTER_ROUNDEDNESS) { this.outerRoundednessAnimation.setValueCallback(lottieValueCallback); } } @Override // com.airbnb.lottie.animation.content.Content public String getName() { return this.name; } }