3
Licensed to the Apache Software Foundation (ASF) under one or more
4
contributor license agreements. See the NOTICE file distributed with
5
this work for additional information regarding copyright ownership.
6
The ASF licenses this file to You under the Apache License, Version 2.0
7
(the "License"); you may not use this file except in compliance with
8
the License. You may obtain a copy of the License at
10
http://www.apache.org/licenses/LICENSE-2.0
12
Unless required by applicable law or agreed to in writing, software
13
distributed under the License is distributed on an "AS IS" BASIS,
14
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
See the License for the specific language governing permissions and
16
limitations under the License.
19
package org.apache.batik.anim.values;
21
import org.apache.batik.dom.anim.AnimationTarget;
23
import org.w3c.dom.svg.SVGAngle;
26
* An SVG angle value in the animation system.
28
* @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
29
* @version $Id: AnimatableAngleValue.java 532986 2007-04-27 06:30:58Z cam $
31
public class AnimatableAngleValue extends AnimatableNumberValue {
34
* The unit string representations.
36
protected static final String[] UNITS = {
37
"", "", "deg", "rad", "grad"
46
* Creates a new, uninitialized AnimatableAngleValue.
48
public AnimatableAngleValue(AnimationTarget target) {
53
* Creates a new AnimatableAngleValue.
55
public AnimatableAngleValue(AnimationTarget target, float v, short unit) {
61
* Performs interpolation to the given value.
63
public AnimatableValue interpolate(AnimatableValue result,
66
AnimatableValue accumulation,
68
AnimatableAngleValue res;
70
res = new AnimatableAngleValue(target);
72
res = (AnimatableAngleValue) result;
78
AnimatableAngleValue toAngle = (AnimatableAngleValue) to;
79
if (toAngle.unit != u) {
81
v += interpolation * (rad(toAngle.value, toAngle.unit) - v);
82
u = SVGAngle.SVG_ANGLETYPE_RAD;
84
v += interpolation * (toAngle.value - v);
87
if (accumulation != null) {
88
AnimatableAngleValue accAngle = (AnimatableAngleValue) accumulation;
89
if (accAngle.unit != u) {
90
v += multiplier * rad(accAngle.value, accAngle.unit);
91
u = SVGAngle.SVG_ANGLETYPE_RAD;
93
v += multiplier * accAngle.value;
97
if (res.value != v || res.unit != u) {
100
res.hasChanged = true;
106
* Returns the angle unit.
108
public short getUnit() {
113
* Returns the absolute distance between this value and the specified other
116
public float distanceTo(AnimatableValue other) {
117
AnimatableAngleValue o = (AnimatableAngleValue) other;
118
return Math.abs(rad(value, unit) - rad(o.value, o.unit));
122
* Returns a zero value of this AnimatableValue's type.
124
public AnimatableValue getZeroValue() {
125
return new AnimatableAngleValue
126
(target, 0, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
130
* Returns the CSS text representation of the value.
132
public String getCssText() {
133
return super.getCssText() + UNITS[unit];
137
* Converts an angle value to radians.
139
public static float rad(float v, short unit) {
141
case SVGAngle.SVG_ANGLETYPE_RAD:
143
case SVGAngle.SVG_ANGLETYPE_GRAD:
144
return (float) Math.PI * v / 200;
146
return (float) Math.PI * v / 180;