X.XXX.X (20XX-XX-XX)
- ・
+ ・逆正接の分母に小さな値が来たときの判定を甘くした。
+ ・パッケージ構成を変更。
2.102.2 (2013-03-17)
・Maven3対応。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.13</version>
+ <version>2.14</version>
<configuration>
<skipTests>false</skipTests>
<enableAssertions>true</enableAssertions>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
- <version>2.9.1</version>
+ <version>2.10</version>
<!-- config from property value -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.13</version>
+ <version>2.14</version>
<configuration>
<showSuccess>false</showSuccess>
</configuration>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
- <version>2.9.1</version>
+ <version>2.10</version>
<configuration>
<skip>false</skip>
<!-- config from property value -->
<module name="ArrayTrailingComma" />
<module name="AvoidInlineConditionals" />
<module name="CovariantEquals" />
- <module name="DoubleCheckedLocking" />
+<!-- <module name="DoubleCheckedLocking" /> 5.6 obsolete -->
<module name="EmptyStatement" />
<module name="EqualsAvoidNull" />
<module name="EqualsHashCode" />
* Copyright(c) 2011 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.binio;
+package jp.sfjp.mikutoga.bin.export;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
/**
* バイナリデータの出力を行う汎用エクスポーター。
- * <p>デフォルトではリトルエンディアン形式で出力される。
+ * <p>基本的にリトルエンディアン形式で出力される。
*/
public class BinaryExporter implements Closeable, Flushable{
"too long text: "
+ "text \"{0}\" needs {1}bytes encoded but limit={2}bytes";
- private static final int MASK_16 = 0xffff;
- private static final int MASK_8 = 0xff;
-
private static final int BYTES_SHORT = Short .SIZE / Byte.SIZE;
private static final int BYTES_INT = Integer .SIZE / Byte.SIZE;
private static final int BYTES_LONG = Long .SIZE / Byte.SIZE;
private static final int BUFSZ_PRIM = BYTES_DOUBLE;
+ private static final int IDX0 = 0;
+ private static final int IDX1 = 1;
+ private static final int IDX2 = 2;
+ private static final int IDX3 = 3;
+ private static final int IDX4 = 4;
+ private static final int IDX5 = 5;
+ private static final int IDX6 = 6;
+ private static final int IDX7 = 7;
+
+ private static final int SH00 = 0;
+ private static final int SH08 = 8;
+ private static final int SH16 = 16;
+ private static final int SH24 = 24;
+ private static final int SH32 = 32;
+ private static final int SH40 = 40;
+ private static final int SH48 = 48;
+ private static final int SH56 = 56;
+
+ static{
+ assert BYTES_DOUBLE <= BUFSZ_PRIM;
+ assert BYTES_FLOAT <= BUFSZ_PRIM;
+ assert BYTES_LONG <= BUFSZ_PRIM;
+ assert BYTES_INT <= BUFSZ_PRIM;
+ assert BYTES_SHORT <= BUFSZ_PRIM;
+ }
+
private final OutputStream ostream;
* @throws IOException 出力エラー
*/
public BinaryExporter dumpByte(byte bVal) throws IOException{
- this.ostream.write((int)bVal);
+ this.ostream.write(bVal);
return this;
}
*/
public BinaryExporter dumpByteArray(byte[] array)
throws IOException{
- dumpByteArray(array, 0, array.length);
+ this.ostream.write(array);
return this;
}
*/
@SuppressWarnings("PMD.AvoidUsingShortType")
public BinaryExporter dumpLeShort(short sVal) throws IOException{
- this.barray[0] = (byte)( (sVal >> 0) & MASK_8 );
- this.barray[1] = (byte)( (sVal >> 8) & MASK_8 );
+ this.barray[IDX0] = (byte)(sVal >>> SH00);
+ this.barray[IDX1] = (byte)(sVal >>> SH08);
this.ostream.write(this.barray, 0, BYTES_SHORT);
*/
@SuppressWarnings("PMD.AvoidUsingShortType")
public BinaryExporter dumpLeShort(int iVal) throws IOException{
- short sVal = (short)(iVal & MASK_16);
+ short sVal = (short)iVal;
dumpLeShort(sVal);
return this;
}
* @throws IOException 出力エラー
*/
public BinaryExporter dumpLeInt(int iVal) throws IOException{
- this.barray[0] = (byte)( (iVal >> 0) & MASK_8 );
- this.barray[1] = (byte)( (iVal >> 8) & MASK_8 );
- this.barray[2] = (byte)( (iVal >> 16) & MASK_8 );
- this.barray[3] = (byte)( (iVal >> 24) & MASK_8 );
+ this.barray[IDX0] = (byte)(iVal >>> SH00);
+ this.barray[IDX1] = (byte)(iVal >>> SH08);
+ this.barray[IDX2] = (byte)(iVal >>> SH16);
+ this.barray[IDX3] = (byte)(iVal >>> SH24);
this.ostream.write(this.barray, 0, BYTES_INT);
* @throws IOException 出力エラー
*/
public BinaryExporter dumpLeLong(long lVal) throws IOException{
- this.barray[0] = (byte)( (lVal >> 0) & 0xffL );
- this.barray[1] = (byte)( (lVal >> 8) & 0xffL );
- this.barray[2] = (byte)( (lVal >> 16) & 0xffL );
- this.barray[3] = (byte)( (lVal >> 24) & 0xffL );
- this.barray[4] = (byte)( (lVal >> 32) & 0xffL );
- this.barray[5] = (byte)( (lVal >> 40) & 0xffL );
- this.barray[6] = (byte)( (lVal >> 48) & 0xffL );
- this.barray[7] = (byte)( (lVal >> 56) & 0xffL );
+ this.barray[IDX0] = (byte)(lVal >>> SH00);
+ this.barray[IDX1] = (byte)(lVal >>> SH08);
+ this.barray[IDX2] = (byte)(lVal >>> SH16);
+ this.barray[IDX3] = (byte)(lVal >>> SH24);
+ this.barray[IDX4] = (byte)(lVal >>> SH32);
+ this.barray[IDX5] = (byte)(lVal >>> SH40);
+ this.barray[IDX6] = (byte)(lVal >>> SH48);
+ this.barray[IDX7] = (byte)(lVal >>> SH56);
this.ostream.write(this.barray, 0, BYTES_LONG);
*/
public BinaryExporter dumpLeFloat(float fVal) throws IOException{
int rawiVal = Float.floatToRawIntBits(fVal);
-
- this.barray[0] = (byte)( (rawiVal >> 0) & MASK_8 );
- this.barray[1] = (byte)( (rawiVal >> 8) & MASK_8 );
- this.barray[2] = (byte)( (rawiVal >> 16) & MASK_8 );
- this.barray[3] = (byte)( (rawiVal >> 24) & MASK_8 );
-
- this.ostream.write(this.barray, 0, BYTES_FLOAT);
-
+ dumpLeInt(rawiVal);
return this;
}
*/
public BinaryExporter dumpLeDouble(double dVal) throws IOException{
long rawlVal = Double.doubleToRawLongBits(dVal);
-
- this.barray[0] = (byte)( (rawlVal >> 0) & MASK_8 );
- this.barray[1] = (byte)( (rawlVal >> 8) & MASK_8 );
- this.barray[2] = (byte)( (rawlVal >> 16) & MASK_8 );
- this.barray[3] = (byte)( (rawlVal >> 24) & MASK_8 );
- this.barray[4] = (byte)( (rawlVal >> 32) & MASK_8 );
- this.barray[5] = (byte)( (rawlVal >> 40) & MASK_8 );
- this.barray[6] = (byte)( (rawlVal >> 48) & MASK_8 );
- this.barray[7] = (byte)( (rawlVal >> 56) & MASK_8 );
-
- this.ostream.write(this.barray, 0, BYTES_DOUBLE);
-
+ dumpLeLong(rawlVal);
return this;
}
encodedSize =
this.texporter_u16le.encodeToByteStream(text, this.xos);
}catch(CharacterCodingException e){
+ assert false; // これはない
throw new IllegalTextExportException(ERRMSG_ILLENC, e);
}
this.xos.writeTo(this.ostream);
int xferred = this.xos.size();
+
assert xferred == encodedSize;
return xferred;
* Copyright(c) 2011 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.binio;
+package jp.sfjp.mikutoga.bin.export;
import java.nio.charset.CharacterCodingException;
/**
* バイナリファイルへの不正なテキスト情報の出力が検出された場合の例外。
+ * <p>
* {@link java.nio.charset.CharacterCodingException}に由来する異常系を
* {@link java.io.IOException}から分離するために設計された。
* <p>
* Copyright(c) 2011 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.binio;
+package jp.sfjp.mikutoga.bin.export;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
if(encoder == null) throw new NullPointerException();
this.encoder = encoder;
+ this.encoder.reset();
this.encoder.onMalformedInput(CodingErrorAction.REPORT);
this.encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+ this.cbuf.clear();
+ this.bbuf.clear();
+
return;
}
public void setCharBufSize(int newSize)
throws IllegalArgumentException {
if(newSize <= 0) throw new IllegalArgumentException();
+
this.cbuf = CharBuffer.allocate(newSize);
this.cbuf.clear();
+
return;
}
float ratio = this.encoder.maxBytesPerChar();
int minSz = (int)( StrictMath.floor(ratio) );
if(newSize < minSz) throw new IllegalArgumentException();
+
this.barray = new byte[newSize];
this.bbuf = ByteBuffer.wrap(this.barray);
this.bbuf.clear();
+
return;
}
/**
* 入力バッファに文字を埋める。
- * <p>入力バッファが一杯になるか入力文字列がなくなるまでバッファが埋められる。
+ * <p>入力バッファが一杯になるか
+ * 入力文字列がなくなるまでバッファが埋められる。
*/
private void loadCharBuffer(){
while(this.cbuf.hasRemaining() && hasMoreInput()){
--- /dev/null
+/*
+ * binary data output
+ *
+ * License : The MIT License
+ * Copyright(c) 2011 MikuToga Partners
+ */
+
+/**
+ * バイナリデータの出力を補佐する一連のクラス。
+ */
+
+package jp.sfjp.mikutoga.bin.export;
+
+/* EOF */
* Copyright(c) 2010 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.parser;
+package jp.sfjp.mikutoga.bin.parser;
import java.io.EOFException;
import java.io.IOException;
import java.io.PushbackInputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.MalformedInputException;
+import java.nio.charset.UnmappableCharacterException;
/**
- * 各種パーサの共通実装。
+ * 各種バイナリファイルパーサの共通実装。
+ * <p>バイト列、各種プリミティブ型値およびエンコードされた文字列を読み込む。
+ * <p>long,double、およびビッグエンディアン形式のデータは未サポート。
*/
public class CommonParser {
+ private static final String ERRMSG_ILLENC =
+ "illegal character encoding";
+ private static final String ERRMSG_UNMAP =
+ "unmapped character";
+
private static final int BYTES_SHORT = Short .SIZE / Byte.SIZE;
private static final int BYTES_INT = Integer.SIZE / Byte.SIZE;
private static final int BYTES_FLOAT = Float .SIZE / Byte.SIZE;
private final PushbackInputStream is;
private final byte[] readBuffer;
- private final ByteBuffer beBuf;
+// private final ByteBuffer beBuf;
private final ByteBuffer leBuf;
private long position = 0L;
+ private ByteBuffer btextBuf;
+
/**
* コンストラクタ。
this.readBuffer = new byte[BYTES_PRIM];
- this.beBuf = ByteBuffer.wrap(this.readBuffer);
+// this.beBuf = ByteBuffer.wrap(this.readBuffer);
this.leBuf = ByteBuffer.wrap(this.readBuffer);
- this.beBuf.order(ByteOrder.BIG_ENDIAN);
+// this.beBuf.order(ByteOrder.BIG_ENDIAN);
this.leBuf.order(ByteOrder.LITTLE_ENDIAN);
return;
/**
* byte配列を読み込む。
- * 配列要素全ての読み込みが試みられる。
+ * <p>配列要素全ての読み込みが試みられる。
* @param dst 格納先配列
* @throws IOException IOエラー
* @throws NullPointerException 配列がnull
/**
* 内部バッファへ指定バイト数だけ読み込む。
- * @param fillSize
- * @throws IOException
- * @throws MmdEofException
+ * @param fillSize バイト長
+ * @throws IOException IOエラー
+ * @throws MmdEofException 読み込む途中でストリーム終端に達した。
*/
private void fillBuffer(int fillSize)
throws IOException, MmdEofException {
/**
* 符号無し値としてbyte値を読み込み、int型に変換して返す。
- * 符号は拡張されない。(0xffは0x000000ffとなる)
+ * <p>符号は拡張されない。(0xffは0x000000ffとなる)
* @return 読み込まれた値のint値
* @throws IOException IOエラー
* @throws MmdEofException 読み込む途中でストリーム終端に達した。
*/
protected int parseUByteAsInt()
throws IOException, MmdEofException{
- return ((int) parseByte()) & MASK_8BIT;
+ return parseByte() & MASK_8BIT;
}
/**
* byte値を読み込み、boolean型に変換して返す。
- * 0x00は偽、それ以外は真と解釈される。
+ * <p>0x00は偽、それ以外は真と解釈される。
* @return 読み込まれた値のboolean値
* @throws IOException IOエラー
* @throws MmdEofException 読み込む途中でストリーム終端に達した。
/**
* short値を読み込む。
- * short値はリトルエンディアンで格納されていると仮定される。
+ * <p>short値はリトルエンディアンで格納されていると仮定される。
* @return 読み込んだshort値
* @throws IOException IOエラー
* @throws MmdEofException 読み込む途中でストリーム終端に達した。
/**
* 符号無し値としてshort値を読み込み、int型に変換して返す。
- * 符号は拡張されない。(0xffffは0x0000ffffとなる)
- * short値はリトルエンディアンで格納されていると仮定される。
+ * <p>符号は拡張されない。(0xffffは0x0000ffffとなる)
+ * <p>short値はリトルエンディアンで格納されていると仮定される。
* @return 読み込まれた値のint値
* @throws IOException IOエラー
* @throws MmdEofException 読み込む途中でストリーム終端に達した。
*/
protected int parseLeUShortAsInt()
throws IOException, MmdEofException{
- return ((int) parseLeShort()) & MASK_16BIT;
+ return parseLeShort() & MASK_16BIT;
}
/**
* int値を読み込む。
- * int値はリトルエンディアンで格納されていると仮定される。
+ * <p>int値はリトルエンディアンで格納されていると仮定される。
* @return 読み込んだint値
* @throws IOException IOエラー
* @throws MmdEofException 読み込む途中でストリーム終端に達した。
/**
* float値を読み込む。
- * float値はリトルエンディアンで格納されていると仮定される。
+ * <p>float値はリトルエンディアンで格納されていると仮定される。
* @return 読み込んだfloat値
* @throws IOException IOエラー
* @throws MmdEofException 読み込む途中でストリーム終端に達した。
*/
protected String parseString(TextDecoder decoder, int byteLen)
throws IOException, MmdEofException, MmdFormatException {
- byte[] buf = decoder.prepareBuffer(byteLen);
+ if(this.btextBuf == null || this.btextBuf.capacity() < byteLen){
+ this.btextBuf = ByteBuffer.allocate(byteLen);
+ }
+
+ byte[] buf = this.btextBuf.array();
+ this.btextBuf.clear();
parseByteArray(buf, 0, byteLen);
- long basePos = getPosition();
- String result= decoder.decode(basePos, byteLen);
+ this.btextBuf.limit(byteLen);
+
+ String result;
+
+ try{
+ result = decoder.decode(this.btextBuf);
+ }catch(UnmappableCharacterException e){
+ String errmsg = ERRMSG_UNMAP;
+ long errpos = getPosition() - byteLen + e.getInputLength();
+ MmdFormatException ex = new MmdFormatException(errmsg, errpos);
+ ex.initCause(e);
+ throw ex;
+ }catch(MalformedInputException e){
+ String errmsg = ERRMSG_ILLENC;
+ long errpos = getPosition() - byteLen + e.getInputLength();
+ MmdFormatException ex = new MmdFormatException(errmsg, errpos);
+ ex.initCause(e);
+ throw ex;
+ }catch(CharacterCodingException e){ // 状況不明
+ String errmsg = ERRMSG_ILLENC;
+ long errpos = getPosition();
+ MmdFormatException ex = new MmdFormatException(errmsg, errpos);
+ ex.initCause(e);
+ throw ex;
+ }
+
return result;
}
* Copyright(c) 2010 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.parser;
+package jp.sfjp.mikutoga.bin.parser;
/**
- * ループ構造の通知用ハンドラ。
- * ステージ指定により、多重ネストループをもサポートする。
+ * ã\83\90ã\82¤ã\83\8aã\83ªã\83\95ã\82¡ã\82¤ã\83«ä¸ã\83«ã\83¼ã\83\97æ§\8bé\80 ã\81®é\80\9aç\9f¥ç\94¨ã\83\8fã\83³ã\83\89ã\83©ã\80\82
+ * <p>ステージ指定により、多重ネストループをもサポートする。
*/
public interface LoopHandler {
/**
* ループ構造開始の通知を受け取る。
- * 0回ループの場合も含め一度呼ばれる。
+ * <p>0回ループの場合も含め一度呼ばれる。
* @param stage ループ種別
* @param loops ループ予定回数。未知の場合は負の値。
* @throws MmdFormatException 不正フォーマットによる
/**
* ループ構造の1イテレーション終了の通知を受け取る。
- * 1度しか回らないループでも呼ばれる。0回ループでは決して呼ばれない。
+ * <p>1度しか回らないループでも呼ばれる。
+ * 0回ループでは決して呼ばれない。
* @param stage ループ種別
* @throws MmdFormatException 不正フォーマットによる
* パース処理の中断をパーサに指示
/**
* ループ構造終了の通知を受け取る。
- * 0回ループの場合も含め一度呼ばれる。
+ * <p>0回ループの場合も含め一度呼ばれる。
* @param stage ループ種別
* @throws MmdFormatException 不正フォーマットによる
* パース処理の中断をパーサに指示
/*
- * unexpected file EOF founded exception
+ * unexpected binary-file EOF founded exception
*
* License : The MIT License
* Copyright(c) 2010 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.parser;
+package jp.sfjp.mikutoga.bin.parser;
/**
* 入力ソースが予期せずに終了した異常系。
/*
- * unexpected file format founded exception
+ * unexpected binary-file format founded exception
*
* License : The MIT License
* Copyright(c) 2010 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.parser;
+package jp.sfjp.mikutoga.bin.parser;
/**
* MMD関連ファイルのパース異常系。
- * 必要に応じて、パースに失敗した位置を保持する。
+ * <p>必要に応じて、パースに失敗した位置を保持する。
*/
@SuppressWarnings("serial")
public class MmdFormatException extends Exception {
/**
* {@inheritDoc}
- * 有効なエラー発生位置を保持している場合、追加出力される。
+ * 有効なエラー発生位置を保持している場合、
+ * エラー文字列に追加出力される。
* @return {@inheritDoc}
*/
@Override
* Copyright(c) 2010 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.parser;
+package jp.sfjp.mikutoga.bin.parser;
import java.util.concurrent.atomic.AtomicInteger;
/**
* パース処理の進行ステージ種別を表す。
- * ループ構造の識別に用いられる。
+ * <p>ループ構造の識別に用いられる。
+ * <p>enum型と異なり、実行時での要素の追加が可能。
*/
public class ParseStage {
- private static final AtomicInteger lastNo = new AtomicInteger(0);
+ private static final AtomicInteger LAST_NO = new AtomicInteger(0);
- private final int no;
+ /** 全インスタンスに割り振られたユニークな番号。変更不可。 */
+ public final int no;
/**
* コンストラクタ。
*/
public ParseStage(){
super();
- this.no = lastNo.getAndIncrement();
+ this.no = LAST_NO.getAndIncrement();
assert this.no >= 0;
return;
}
--- /dev/null
+/*
+ * character decoder
+ *
+ * License : The MIT License
+ * Copyright(c) 2011 MikuToga Partners
+ */
+
+package jp.sfjp.mikutoga.bin.parser;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+
+/**
+ * 文字デコーダー。
+ * <p>あらかじめバイト長が既知であるバイトバッファを読み取り、
+ * 文字列へのデコード結果を返す。
+ * <p>デコード対象のバイト列が全てメモリ上に展開される必要があるので、
+ * 巨大なテキストのデコードには不適当。
+ * <p>入力バイト値0x00以降をデコード処理の対象から外す
+ * 「ゼロチョップモード」を備える。
+ * デフォルトではゼロチョップモードはオフ。
+ * ゼロチョップモードはUTF16などのデコーディング時に使ってはならない。
+ */
+public class TextDecoder {
+
+ private final CharsetDecoder decoder;
+
+ private CharBuffer charBuffer;
+
+ private boolean chopZero = false;
+
+
+ /**
+ * コンストラクタ。
+ * @param cs キャラクタセット
+ */
+ public TextDecoder(Charset cs){
+ this(cs.newDecoder());
+ return;
+ }
+
+ /**
+ * コンストラクタ。
+ * @param decoder デコーダ
+ */
+ public TextDecoder(CharsetDecoder decoder){
+ super();
+
+ this.decoder = decoder;
+ this.decoder.reset();
+ this.decoder.onMalformedInput (CodingErrorAction.REPORT);
+ this.decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+
+ return;
+ }
+
+ /**
+ * 指定されたバイト長のデコードに必要な出力バッファを用意する。
+ * <p>既存バッファで足りなければ新たに確保し直す。
+ * @param byteLength 入力バイト長
+ * @return 出力バッファ長。(キャラクタ単位)
+ */
+ protected int prepareCharBuffer(int byteLength){
+ float maxCharsPerByte = this.decoder.maxCharsPerByte();
+ int maxChars = (int)( byteLength * maxCharsPerByte ) + 1;
+
+ if(this.charBuffer != null){
+ int capacity = this.charBuffer.capacity();
+ if(capacity >= maxChars){
+ return capacity;
+ }
+ }
+
+ this.charBuffer = CharBuffer.allocate(maxChars);
+
+ return maxChars;
+ }
+
+ /**
+ * ゼロチョップモードを設定する。
+ * ゼロチョップモードをオンにすると、
+ * 入力バイト値0x00以降はデコード対象外となる。
+ * @param chop trueならゼロチョップモードオン
+ */
+ public void setZeroChopMode(boolean chop){
+ this.chopZero = chop;
+ return;
+ }
+
+ /**
+ * ゼロチョップモードか否か判定する。
+ * @return ゼロチョップモードならtrue
+ */
+ public boolean isZeroChopMode(){
+ return this.chopZero;
+ }
+
+ /**
+ * 入力バイトバッファのバイト値'0'出現以降をチョップする。
+ * ゼロチョップモードでなければ何もしない。
+ * @param bBuf 入力バイトバッファ
+ */
+ protected void chopZeroTermed(ByteBuffer bBuf){
+ if( ! this.chopZero ) return;
+
+ int start = bBuf.position();
+ int limit = bBuf.limit();
+ for(int idx = start; idx < limit; idx++){
+ byte bVal = bBuf.get(idx);
+ if(bVal == 0x00){
+ bBuf.limit(idx);
+ break;
+ }
+ }
+
+ return;
+ }
+
+ /**
+ * バイトバッファの文字列デコードを行う。
+ * @param bBuf バイトバッファ
+ * @return デコードされた文字列
+ * @throws CharacterCodingException デコード異常
+ */
+ public String decode(ByteBuffer bBuf) throws CharacterCodingException{
+ chopZeroTermed(bBuf);
+
+ int blen = bBuf.remaining();
+ prepareCharBuffer(blen);
+ this.charBuffer.clear();
+
+ this.decoder.reset();
+ CoderResult decResult;
+ decResult = this.decoder.decode(bBuf, this.charBuffer, true);
+
+ if(decResult.isError()){
+ decResult.throwException();
+ assert false;
+ }
+
+ assert ! decResult.isOverflow();
+
+ String result = this.charBuffer.flip().toString();
+ return result;
+ }
+
+}
*/
/**
- * MMD用各種パーサ共通ライブラリ。
+ * MMDç\94¨å\90\84種ã\83\90ã\82¤ã\83\8aã\83ªã\83\95ã\82¡ã\82¤ã\83«ã\83\91ã\83¼ã\82µå\85±é\80\9aã\83©ã\82¤ã\83\96ã\83©ã\83ªã\80\82
* <p>
* PMDモデルファイルやVMDモーションファイルなどの個別のパーサは
* 別パッケージにより提供される。
*/
-package jp.sourceforge.mikutoga.parser;
+package jp.sfjp.mikutoga.bin.parser;
/* EOF */
/*
- * international text
+ * internationalization text
*
* License : The MIT License
* Copyright(c) 2010 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.corelib;
+package jp.sfjp.mikutoga.corelib;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* 多言語のバリアントを持つ文字列情報。
+ * 言語はISO639言語コードで区別される。
* <ul>
- * <li>プライマリ:識別子にはこちらを使う。基本は日本語。
+ * <li>プライマリ:識別子にはこちらを使う。
+ * 基本はMMD発祥の地に敬意を表して日本語。
* <li>グローバル:基本は英語。UCS Basic-Latinオンリーの貧弱な言語環境でも
* 読める文字列が望ましい。
* <li>その他:必要に応じて好きな言語を。
/** プライマリ言語のロケール。 */
public static final Locale LOCALE_PRIMARY = Locale.JAPANESE;
- /** プライマリ言語の言語コード。 */
- public static final String CODE639_PRIMARY = LOCALE_PRIMARY.getLanguage();
+ /** プライマリ言語のISO639言語コード。 */
+ public static final String CODE639_PRIMARY =
+ LOCALE_PRIMARY.getLanguage();
/** グローバル言語のロケール。 */
public static final Locale LOCALE_GLOBAL = Locale.ENGLISH;
- /** グローバル言語の言語コード。 */
- public static final String CODE639_GLOBAL = LOCALE_GLOBAL.getLanguage();
+ /** グローバル言語のISO639言語コード。 */
+ public static final String CODE639_GLOBAL =
+ LOCALE_GLOBAL.getLanguage();
static{
assert "ja".equals(CODE639_PRIMARY);
assert "en".equals(CODE639_GLOBAL);
}
- private final Map<String, String> nameMap = new HashMap<String, String>();
+
+ /**
+ * キーはISO639、値は多言語テキスト。
+ */
+ private final Map<String, String> nameMap =
+ new HashMap<String, String>();
+
/**
* コンストラクタ。
/**
* プライマリ文字列を返す。
- * 見つからなければグローバル文字列を返す。
- * それでも見つからなければ空文字列を返す。
+ * <p>見つからなければグローバル文字列を返す。
+ * それでも見つからなければ長さ0の空文字列を返す。
+ * <p>※決してnullは返さない。
* @return 文字列
*/
public String getText(){
/**
* 実行環境のデフォルトロケールに応じた文字列を返す。
- * 見つからなければグローバル文字列、プライマリ文字列の順に返す。
+ * <p>見つからなければグローバル文字列、プライマリ文字列の順に返す。
* それでも見つからなければ適当な言語コードの文字列を返す。
* それでも見つからなければ長さ0の空文字列を返す。
- * デフォルトロケールの確認はその都度行われる。
+ * <p>デフォルトロケールの確認はその都度行われる。
+ * <p>※決してnullは返さない。
* @return 文字列
*/
public String getLocalizedText(){
if(result == null){
Set<String> langSet = this.nameMap.keySet();
- Iterator<String> it = langSet.iterator();
- while(it.hasNext()){
- String lang = it.next();
+ for(String lang : langSet){
result = this.nameMap.get(lang);
if(result != null) break;
}
/**
* {@inheritDoc}
- * {@link #getText()}に準ずる。
+ * {@link #getText()}仕様に準ずる。
* @param index {@inheritDoc}
* @return {@inheritDoc}
*/
/**
* {@inheritDoc}
- * {@link #getText()}に準ずる。
+ * {@link #getText()}仕様に準ずる。
* @return {@inheritDoc}
*/
@Override
/**
* {@inheritDoc}
- * {@link #getText()}に準ずる。
+ * {@link #getText()}仕様に準ずる。
* @param start {@inheritDoc}
* @param end {@inheritDoc}
* @return {@inheritDoc}
/**
* {@inheritDoc}
- * {@link #getText()}に準ずる。
+ * {@link #getText()}仕様に準ずる。
* @return {@inheritDoc}
*/
@Override
* MikuToga共通基盤ライブラリ。
*/
-package jp.sourceforge.mikutoga.corelib;
+package jp.sfjp.mikutoga.corelib;
/* EOF */
* Copyright(c) 2011 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.math;
+package jp.sfjp.mikutoga.math;
/**
* YXZオイラー角。
/**
* X軸回転量を設定する。
- * @param xRot X軸回転量。(ラジアン)
+ * @param xRotArg X軸回転量。(ラジアン)
*/
- public void setXRot(double xRot){
- this.xRot = xRot;
+ public void setXRot(double xRotArg){
+ this.xRot = xRotArg;
return;
}
/**
* Y軸回転量を設定する。
- * @param yRot Y軸回転量。(ラジアン)
+ * @param yRotArg Y軸回転量。(ラジアン)
*/
- public void setYRot(double yRot){
- this.yRot = yRot;
+ public void setYRot(double yRotArg){
+ this.yRot = yRotArg;
return;
}
/**
* Z軸回転量を設定する。
- * @param zRot Z軸回転量。(ラジアン)
+ * @param zRotArg Z軸回転量。(ラジアン)
*/
- public void setZRot(double zRot){
- this.zRot = zRot;
+ public void setZRot(double zRotArg){
+ this.zRot = zRotArg;
return;
}
/**
- * {@inheritDoc}
- * @return {@inheritDoc}
+ * 三軸の回転量を設定する。
+ * @param xRotArg X軸回転量。(ラジアン)
+ * @param yRotArg Y軸回転量。(ラジアン)
+ * @param zRotArg Z軸回転量。(ラジアン)
*/
- @Override
- public String toString(){
+ public void setRot(double xRotArg, double yRotArg, double zRotArg){
+ this.xRot = xRotArg;
+ this.yRot = yRotArg;
+ this.zRot = zRotArg;
+ return;
+ }
+
+ /**
+ * パラメータ情報の文字列化。
+ * @param x x値
+ * @param y y値
+ * @param z z値
+ * @return 文字列
+ */
+ private static String toString(double x, double y, double z){
StringBuilder result = new StringBuilder();
- result.append("x=") .append(this.xRot);
- result.append(" y=").append(this.yRot);
- result.append(" z=").append(this.zRot);
+ result.append("x=") .append(x);
+ result.append(" y=").append(y);
+ result.append(" z=").append(z);
return result.toString();
}
/**
+ * {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ @Override
+ public String toString(){
+ String result;
+ result = toString(this.xRot, this.yRot, this.zRot);
+ return result;
+ }
+
+ /**
* 度数法による文字列表現を返す。
* @return 文字列表現
*/
public String toDegString(){
- StringBuilder result = new StringBuilder();
-
- result.append("x=") .append(StrictMath.toDegrees(this.xRot));
- result.append(" y=").append(StrictMath.toDegrees(this.yRot));
- result.append(" z=").append(StrictMath.toDegrees(this.zRot));
+ double xDeg = StrictMath.toDegrees(this.xRot);
+ double yDeg = StrictMath.toDegrees(this.yRot);
+ double zDeg = StrictMath.toDegrees(this.zRot);
- return result.toString();
+ String result;
+ result = toString(xDeg, yDeg, zDeg);
+ return result;
}
}
* Copyright(c) 2010 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.math;
+package jp.sfjp.mikutoga.math;
/**
* 二次元空間座標及び変量を表す。
* <p>直交座標を二つの倍精度値で表す。
* <p>主な用途はUVマッピングなど。
*/
-public class MkPos2D {
+public strictfp class MkPos2D {
private double xPos;
private double yPos;
* Copyright(c) 2011 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.math;
+package jp.sfjp.mikutoga.math;
/**
* 三次元位置情報。
* コンストラクタ。
*/
public MkPos3D(){
- this.xPos = 0.0;
- this.yPos = 0.0;
- this.zPos = 0.0;
+ this(0.0, 0.0, 0.0);
return;
}
+ /**
+ * コンストラクタ。
+ * @param xPosArg X軸座標
+ * @param yPosArg Y軸座標
+ * @param zPosArg Z軸座標
+ */
+ public MkPos3D(double xPosArg, double yPosArg, double zPosArg){
+ this.xPos = xPosArg;
+ this.yPos = yPosArg;
+ this.zPos = zPosArg;
+ return;
+ }
/**
* X軸座標を返す。
* Copyright(c) 2011 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.math;
+package jp.sfjp.mikutoga.math;
/**
* クォータニオンによる回転表現。
public strictfp class MkQuat {
private static final double HALF_PI = StrictMath.PI / 2.0;
+ private static final double EPSILON = StrictMath.ulp(1.0);
+ private static final double TDELTA = EPSILON * 4;
+
+ static{
+ assert StrictMath.ulp(StrictMath.PI) <= TDELTA;
+ }
private double q1;
/**
* 逆元クォータニオンを求め格納する。
- * <p>対象クォータニオンの絶対値が小さい場合、無限大が虚部実部に入る可能性がある。
+ * <p>対象クォータニオンの絶対値が小さい場合、
+ * 無限大が虚部実部に入る可能性がある。
* <p>引数は同一インスタンスでもよい。
* @param q クォータニオン
* @param result 格納先
/**
* 虚部1を設定する。
- * @param q1 虚部1
+ * @param q1Arg 虚部1
*/
- public void setQ1(double q1) {
- this.q1 = q1;
+ public void setQ1(double q1Arg) {
+ this.q1 = q1Arg;
return;
}
/**
* 虚部2を設定する。
- * @param q2 虚部2
+ * @param q2Arg 虚部2
*/
- public void setQ2(double q2) {
- this.q2 = q2;
+ public void setQ2(double q2Arg) {
+ this.q2 = q2Arg;
return;
}
/**
* 虚部3を設定する。
- * @param q3 虚部3
+ * @param q3Arg 虚部3
*/
- public void setQ3(double q3) {
- this.q3 = q3;
+ public void setQ3(double q3Arg) {
+ this.q3 = q3Arg;
return;
}
/**
* 実部を設定する。
- * @param w 実部
+ * @param wArg 実部
+ */
+ public void setQW(double wArg) {
+ this.qw = wArg;
+ return;
+ }
+
+ /**
+ * 虚部実部を設定する。
+ * @param q1Arg 虚部1
+ * @param q2Arg 虚部2
+ * @param q3Arg 虚部3
+ * @param wArg 実部
*/
- public void setQW(double w) {
- this.qw = w;
+ public void setQ123W(double q1Arg, double q2Arg, double q3Arg,
+ double wArg ){
+ this.q1 = q1Arg;
+ this.q2 = q2Arg;
+ this.q3 = q3Arg;
+ this.qw = wArg;
return;
}
* @param yPos Y位置
* @param zPos Z位置
*/
- public void readPos3D(double xPos, double yPos, double zPos){
+ public void setPos3D(double xPos, double yPos, double zPos){
this.q1 = xPos;
this.q2 = yPos;
this.q3 = zPos;
* <p>実部には0が入る。
* @param pos 位置情報
*/
- public void readPos3D(MkPos3D pos){
- readPos3D(pos.getXpos(), pos.getYpos(), pos.getZpos());
+ public void setPos3D(MkPos3D pos){
+ setPos3D(pos.getXpos(), pos.getYpos(), pos.getZpos());
return;
}
/**
* YXZオイラー角を読み込む。
- * <p>Y軸回転、X軸回転、Z軸回転の順に個別回転クォータニオンの積をとったものと等しい。
+ * <p>Y軸回転、X軸回転、Z軸回転の順に
+ * 個別回転クォータニオンの積をとったものと等しい。
* @param xRot X軸回転量(ラジアン)。第2軸
* @param yRot Y軸回転量(ラジアン)。第1軸
* @param zRot Z軸回転量(ラジアン)。第3軸
*/
- public void readEulerYXZ(double xRot, double yRot, double zRot){
+ public void setEulerYXZ(double xRot, double yRot, double zRot){
double hx = xRot / 2.0;
double hy = yRot / 2.0;
double hz = zRot / 2.0;
/**
* YXZオイラー角を読み込む。
- * <p>Y軸回転、X軸回転、Z軸回転の順に個別回転クォータニオンの積をとったものと等しい。
+ * <p>Y軸回転、X軸回転、Z軸回転の順に
+ * 個別回転クォータニオンの積をとったものと等しい。
* @param rot YXZオイラー角
*/
- public void readEulerYXZ(EulerYXZ rot){
- readEulerYXZ(rot.getXRot(), rot.getYRot(), rot.getZRot());
+ public void setEulerYXZ(EulerYXZ rot){
+ setEulerYXZ(rot.getXRot(), rot.getYRot(), rot.getZRot());
return;
}
* クォータニオンをYXZオイラー角へと変換する。
* <p>ジンバルロック時のYZ配分が指定可能。
* @param result YXZオイラー角
- * @param oldY ジンバルロック時に使われるY軸回転量
+ * @param oldY ジンバルロック時(オイラー角Xが直角etc.)
+ * に使われるY軸回転量
*/
public void toEulerYXZ(EulerYXZ result, double oldY){
double qx = this.q1;
else if(m12 > +1.0) resultX = -HALF_PI;
else resultX = StrictMath.asin(-m12);
- if(m11 == 0.0 || m22 == 0.0){ // Y,Zが一意に定まらない場合
+ if( StrictMath.abs(m11) <= TDELTA // Y,Zが一意に定まらない場合
+ || StrictMath.abs(m22) <= TDELTA ){
resultY = oldY;
resultZ = StrictMath.atan2(-m01, m00) + oldY;
}else{
* Copyright(c) 2010 MikuToga Partners
*/
-package jp.sourceforge.mikutoga.math;
+package jp.sfjp.mikutoga.math;
/**
* XYZ三次元ベクトル。
*/
-public class MkVec3D {
+public strictfp class MkVec3D {
+
+ private static final String DELIM = ", ";
private double xVal;
private double yVal;
* コンストラクタ。
*/
public MkVec3D(){
- super();
+ this(0.0, 0.0, 0.0);
+ return;
+ }
+
+ /**
+ * コンストラクタ。
+ * @param xValArg X値
+ * @param yValArg Y値
+ * @param zValArg Z値
+ */
+ public MkVec3D(double xValArg, double yValArg, double zValArg){
+ this.xVal = xValArg;
+ this.yVal = yValArg;
+ this.zVal = zValArg;
return;
}
/**
* X値を設定する。
- * @param xVal X値
+ * @param xValArg X値
*/
- public void setXVal(double xVal){
- this.xVal = xVal;
+ public void setXVal(double xValArg){
+ this.xVal = xValArg;
return;
}
/**
* Y値を設定する。
- * @param yVal Y値
+ * @param yValArg Y値
*/
- public void setYVal(double yVal){
- this.yVal = yVal;
+ public void setYVal(double yValArg){
+ this.yVal = yValArg;
return;
}
/**
* Z値を設定する。
- * @param zVal Z値
+ * @param zValArg Z値
*/
- public void setZVal(double zVal){
- this.zVal = zVal;
+ public void setZVal(double zValArg){
+ this.zVal = zValArg;
return;
}
StringBuilder result = new StringBuilder();
result.append("vec=[")
- .append(this.xVal).append(", ")
- .append(this.yVal).append(", ")
+ .append(this.xVal).append(DELIM)
+ .append(this.yVal).append(DELIM)
.append(this.zVal).append(']');
return result.toString();
* <p>javax.vecmathの代替品。
*/
-package jp.sourceforge.mikutoga.math;
+package jp.sfjp.mikutoga.math;
/* EOF */
+++ /dev/null
-/*
- * file utils
- *
- * License : The MIT License
- * Copyright(c) 2011 MikuToga Partners
- */
-
-package jp.sourceforge.mikutoga.binio;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.channels.FileChannel;
-
-/**
- * ファイルユーティリティ。
- */
-public final class FileUtils {
-
- /**
- * コンストラクタ。
- */
- private FileUtils(){
- super();
- assert false;
- throw new AssertionError();
- }
-
-
- /**
- * 既に存在する通常ファイルか否か判定する。
- * @param file 判定対象
- * @return 既に存在する通常ファイルならtrue
- */
- public static boolean isExistsNormalFile(File file){
- if( ! file.exists() ) return false;
- if( ! file.isFile() ) return false;
- return true;
- }
-
- /**
- * 既に存在する特殊ファイルか否か判定する。
- * @param file 判定対象
- * @return 既に存在する特殊ファイルならtrue
- */
- public static boolean isExistsUnnormalFile(File file){
- if( ! file.exists() ) return false;
- if( file.isFile() ) return false;
- return true;
- }
-
- /**
- * ファイルサイズを0に切り詰める。
- * <p>既に存在する通常ファイルでないならなにもしない。
- * @param file ファイル
- * @throws IOException 入出力エラー
- */
- public static void trunc(File file) throws IOException{
- if( ! isExistsNormalFile(file) ) return;
- if(file.length() <= 0L) return;
-
- FileOutputStream foStream = new FileOutputStream(file);
- try{
- FileChannel channnel = foStream.getChannel();
- try{
- channnel.truncate(0L);
- }finally{
- channnel.close();
- }
- }finally{
- foStream.close();
- }
-
- assert file.length() <= 0L;
-
- return;
- }
-
-}
+++ /dev/null
-/*
- * binary data I/O
- *
- * License : The MIT License
- * Copyright(c) 2011 MikuToga Partners
- */
-
-/**
- * バイナリデータの入出力を補佐する一連のクラス。
- */
-
-package jp.sourceforge.mikutoga.binio;
-
-/* EOF */
+++ /dev/null
-/*
- * character decoder
- *
- * License : The MIT License
- * Copyright(c) 2011 MikuToga Partners
- */
-
-package jp.sourceforge.mikutoga.parser;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-
-/**
- * 文字デコーダー。
- * <p>あらかじめ長さが既知であるバイト列を読み取り、
- * 文字列へのデコード結果を返す。
- * <p>デコード対象のバイト列が全てメモリ上に展開されるので、
- * 巨大なテキストのデコードには不適当。
- * <p>入力バイト値0x00以降をデコード処理の対象から外す
- * 「ゼロチョップモード」を備える。
- * デフォルトではゼロチョップモードはオフ。
- * ゼロチョップモードはUTF16などのデコーディング時に使ってはならない。
- */
-public class TextDecoder {
-
- /** デコード作業用入力バッファ長のデフォルト。バイト単位。 */
- public static final int DEF_BUFSZ = 512;
-
-
- private final CharsetDecoder decoder;
-
- private byte[] byteArray;
- private ByteBuffer byteBuffer; // byteArrayの別ビュー
- private CharBuffer charBuffer;
-
- private boolean chopZero = false;
-
-
- /**
- * コンストラクタ。
- * @param cs キャラクタセット
- */
- public TextDecoder(Charset cs){
- this(cs.newDecoder());
- return;
- }
-
- /**
- * コンストラクタ。
- * @param decoder デコーダ
- */
- public TextDecoder(CharsetDecoder decoder){
- super();
-
- if(decoder == null) throw new NullPointerException();
-
- this.decoder = decoder;
- this.decoder.onMalformedInput (CodingErrorAction.REPORT);
- this.decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
-
- return;
- }
-
- /**
- * 指定されたバイト長を満たす、デコード用入力バッファを用意する。
- * 既存バッファで足りなければ新たに確保し直す。
- * <p>内部用出力用バッファも同時に適切な長さで確保される。
- * @param newSize 新たなバッファ長。単位はバイト数。
- * @return 入力バッファ。指定バイト長より長いかもしれない。他用厳禁
- */
- public byte[] prepareBuffer(int newSize){
- if(this.byteArray != null && this.byteArray.length >= newSize){
- return this.byteArray;
- }
-
- int rounded = newSize;
- if(rounded < DEF_BUFSZ) rounded = DEF_BUFSZ;
-
- this.byteArray = new byte[rounded];
- this.byteBuffer = ByteBuffer.wrap(this.byteArray);
-
- float maxCharsPerByte = this.decoder.maxCharsPerByte();
- int maxChars =
- (int)( this.byteArray.length * maxCharsPerByte ) + 1;
- this.charBuffer = CharBuffer.allocate(maxChars);
-
- return this.byteArray;
- }
-
- /**
- * ゼロチョップモードを設定する。
- * ゼロチョップモードをオンにすると、
- * 入力バイト値0x00以降はデコード対象外となる。
- * @param chop trueならゼロチョップモードオン
- */
- public void setZeroChopMode(boolean chop){
- this.chopZero = chop;
- return;
- }
-
- /**
- * ゼロチョップモードか否か判定する。
- * @return ゼロチョップモードならtrue
- */
- public boolean isZeroChopMode(){
- return this.chopZero;
- }
-
- /**
- * 入力バイト列のバイト値'0'出現以降をチョップする。
- * ゼロチョップモードでなければ何もしない。
- */
- protected void chopZeroTermed(){
- if( ! this.chopZero ) return;
-
- int limit = this.byteBuffer.limit();
-
- for(int idx = 0; idx < limit; idx++){
- byte bVal = this.byteArray[idx];
- if(bVal == 0x00){
- this.byteBuffer.limit(idx);
- break;
- }
- }
-
- return;
- }
-
- /**
- * 指定配列を内部にコピーした後、デコード処理を行う。
- * @param basePos エラー情報に含まれるストリーム位置
- * @param buf 入力バッファ
- * @return デコードされた文字列
- * @throws MmdFormatException デコード異常
- */
- public String decode(long basePos, byte[] buf)
- throws MmdFormatException {
- String result = decode(basePos, buf, 0, buf.length);
- return result;
- }
-
- /**
- * 指定配列の一部を内部にコピーした後、デコード処理を行う。
- * @param basePos エラー情報に含まれるストリーム位置
- * @param buf 入力バッファ
- * @param off 位置オフセット
- * @param byteLen バイト長
- * @return デコードされた文字列
- * @throws MmdFormatException デコード異常
- * @throws IndexOutOfBoundsException 不正な位置指定。
- */
- public String decode(long basePos, byte[] buf, int off, int byteLen)
- throws MmdFormatException, IndexOutOfBoundsException {
- prepareBuffer(byteLen);
- System.arraycopy(buf, off, this.byteArray, 0, byteLen);
- String result = decode(basePos, byteLen);
- return result;
- }
-
- /**
- * 内部バッファのデコード処理を行う。
- * @param basePos エラー情報に含まれるストリーム位置
- * @param byteLen バイト長
- * @return デコードされた文字列
- * @throws MmdFormatException デコード異常
- * @throws IndexOutOfBoundsException 不正なバイト長。
- */
- public String decode(long basePos, int byteLen)
- throws MmdFormatException, IndexOutOfBoundsException {
- if(this.byteArray.length < byteLen){
- throw new IndexOutOfBoundsException();
- }
-
- this.byteBuffer.rewind().limit(byteLen);
- chopZeroTermed();
-
- this.charBuffer.clear();
-
- this.decoder.reset();
- CoderResult decResult =
- this.decoder.decode(this.byteBuffer, this.charBuffer, true);
-
- if(decResult.isError()){
- String errMsg;
- if(decResult.isUnmappable()){
- errMsg = "unmapped character";
- }else{
- errMsg = "illegal character encoding";
- }
- long errPos = basePos + decResult.length();
- throw new MmdFormatException(errMsg, errPos);
- }
-
- assert ! decResult.isOverflow();
-
- String result = this.charBuffer.flip().toString();
- return result;
- }
-
-}
*/
public class Deg3d {
+ private static final String DELIM = ", ";
+
private float xDeg;
private float yDeg;
private float zDeg;
/**
* X軸回転量を設定する。
- * @param xDeg X軸回転量(degree)
+ * @param xDegArg X軸回転量(degree)
*/
- public void setXDeg(float xDeg){
- this.xDeg = xDeg;
+ public void setXDeg(float xDegArg){
+ this.xDeg = xDegArg;
return;
}
/**
* Y軸回転量を設定する。
- * @param yDeg Y軸回転量(degree)
+ * @param yDegArg Y軸回転量(degree)
*/
- public void setYDeg(float yDeg){
- this.yDeg = yDeg;
+ public void setYDeg(float yDegArg){
+ this.yDeg = yDegArg;
return;
}
/**
* Z軸回転量を設定する。
- * @param zDeg Z軸回転量(degree)
+ * @param zDegArg Z軸回転量(degree)
*/
- public void setZDeg(float zDeg){
- this.zDeg = zDeg;
+ public void setZDeg(float zDegArg){
+ this.zDeg = zDegArg;
return;
}
StringBuilder result = new StringBuilder();
result.append("deg=[")
- .append(this.xDeg).append(", ")
- .append(this.yDeg).append(", ")
+ .append(this.xDeg).append(DELIM)
+ .append(this.yDeg).append(DELIM)
.append(this.zDeg).append(']');
return result.toString();
*/
public class Rad3d {
+ private static final String DELIM = ", ";
+
private float xRad;
private float yRad;
private float zRad;
/**
* X軸回転量を設定する。
- * @param xRad X軸回転量(radian)
+ * @param xRadArg X軸回転量(radian)
*/
- public void setXRad(float xRad){
- this.xRad = xRad;
+ public void setXRad(float xRadArg){
+ this.xRad = xRadArg;
return;
}
/**
* Y軸回転量を設定する。
- * @param yRad Y軸回転量(radian)
+ * @param yRadArg Y軸回転量(radian)
*/
- public void setYRad(float yRad){
- this.yRad = yRad;
+ public void setYRad(float yRadArg){
+ this.yRad = yRadArg;
return;
}
/**
* Z軸回転量を設定する。
- * @param zRad Z軸回転量(radian)
+ * @param zRadArg Z軸回転量(radian)
*/
- public void setZRad(float zRad){
- this.zRad = zRad;
+ public void setZRad(float zRadArg){
+ this.zRad = zRadArg;
return;
}
StringBuilder result = new StringBuilder();
result.append("rad=[")
- .append(this.xRad).append(", ")
- .append(this.yRad).append(", ")
+ .append(this.xRad).append(DELIM)
+ .append(this.yRad).append(DELIM)
.append(this.zRad).append(']');
return result.toString();
package jp.sourceforge.mikutoga.pmd.parser;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
/**
* PMDモデル情報ファイルの基本情報の通知用ハンドラ。
package jp.sourceforge.mikutoga.pmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* PMDモデルの各種ボーン情報の通知用ハンドラ。
package jp.sourceforge.mikutoga.pmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* PMDモデルの英語情報の通知用ハンドラ。
package jp.sourceforge.mikutoga.pmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* PMDモデルの各種剛体間ジョイント情報の通知用ハンドラ。
package jp.sourceforge.mikutoga.pmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* PMDモデルの各種材質情報の通知用ハンドラ。
package jp.sourceforge.mikutoga.pmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* PMDモデルのモーフ情報の通知用ハンドラ。
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
-import jp.sourceforge.mikutoga.parser.CommonParser;
-import jp.sourceforge.mikutoga.parser.MmdEofException;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.TextDecoder;
+import jp.sfjp.mikutoga.bin.parser.CommonParser;
+import jp.sfjp.mikutoga.bin.parser.MmdEofException;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.TextDecoder;
/**
* PMDモデルファイルのパーサ基本部。
import java.io.IOException;
import java.io.InputStream;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
/**
* PMDモデルファイルのパーサ拡張その1。
import java.io.IOException;
import java.io.InputStream;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
/**
* PMDモデルファイルのパーサ拡張その2。
import java.io.IOException;
import java.io.InputStream;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
/**
* PMDモデルファイルのパーサ拡張その3。
package jp.sourceforge.mikutoga.pmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* PMDモデルの各種剛体情報の通知用ハンドラ。
package jp.sourceforge.mikutoga.pmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* PMDモデルの各種形状(頂点、面)の通知用ハンドラ。
package jp.sourceforge.mikutoga.pmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* PMDモデルの独自トゥーンテクスチャファイル名の通知用ハンドラ。
package jp.sourceforge.mikutoga.vmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* VMDモーションファイルの基本情報(ボーンモーション/モーフモーション)
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
-import jp.sourceforge.mikutoga.parser.CommonParser;
-import jp.sourceforge.mikutoga.parser.MmdEofException;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.TextDecoder;
+import jp.sfjp.mikutoga.bin.parser.CommonParser;
+import jp.sfjp.mikutoga.bin.parser.MmdEofException;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.TextDecoder;
import jp.sourceforge.mikutoga.vmd.VmdConst;
/**
package jp.sourceforge.mikutoga.vmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* VMDモーションファイルのカメラワーク情報の通知用ハンドラ。
import java.io.IOException;
import java.io.InputStream;
-import jp.sourceforge.mikutoga.parser.CommonParser;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.CommonParser;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
import jp.sourceforge.mikutoga.vmd.VmdConst;
/**
package jp.sourceforge.mikutoga.vmd.parser;
-import jp.sourceforge.mikutoga.parser.LoopHandler;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.LoopHandler;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
/**
* VMDモーションファイルのライティング情報(照明光源・セルフシャドウ)
import java.io.IOException;
import java.io.InputStream;
-import jp.sourceforge.mikutoga.parser.CommonParser;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.CommonParser;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
import jp.sourceforge.mikutoga.vmd.VmdConst;
/**
import java.io.IOException;
import java.io.InputStream;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
/**
* VMDモーションファイルのパーサ。
/*
*/
-package jp.sourceforge.mikutoga.binio;
+package jp.sfjp.mikutoga.bin.export;
import java.io.ByteArrayOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
}
/**
+ * Test of constructor, of class BinaryExporter.
+ * @throws Exception
+ */
+ @Test
+ public void testCons() throws Exception {
+ System.out.println("constructor");
+
+ BinaryExporter ex;
+ OutputStream stream;
+
+ stream = new ByteArrayOutputStream();
+ ex = new BinaryExporter(stream);
+
+ try{
+ ex = new BinaryExporter(null);
+ fail();
+ }catch(NullPointerException e){
+ // GOOD
+ }
+
+ return;
+ }
+
+ /**
* Test of close method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testClose() throws Exception {
/**
* Test of flush method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testFlush() throws Exception {
/**
* Test of dumpByte method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpByte_byte() throws Exception {
/**
* Test of dumpByte method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpByte_int() throws Exception {
/**
* Test of dumpByteArray method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpByteArray_byteArr() throws Exception {
/**
* Test of dumpByteArray method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpByteArray_3args() throws Exception {
/**
* Test of dumpLeShort method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpLeShort_short() throws Exception {
/**
* Test of dumpLeShort method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpLeShort_int() throws Exception {
/**
* Test of dumpLeInt method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpLeInt() throws Exception {
/**
* Test of dumpLeLong method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpLeLong() throws Exception {
/**
* Test of dumpLeFloat method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpLeFloat() throws Exception {
/**
* Test of dumpLeDouble method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpLeDouble() throws Exception {
/**
* Test of dumpFiller method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpFiller() throws Exception {
assertEquals((byte)0x01, barr[0]);
assertEquals((byte)0x02, barr[1]);
+ bos.reset();
+ bex.dumpFiller(new byte[]{}, 3);
+ bex.flush();
+ assertEquals(0, bos.size());
+
+ bos.reset();
+ bex.dumpFiller(new byte[]{0x01, 0x02, 0x03}, 0);
+ bex.flush();
+ assertEquals(0, bos.size());
+
return;
}
/**
* Test of dumpFixedW31j method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpFixedW31j() throws Exception {
assertEquals((byte)0x02, barr[6]);
bos.reset();
+ bex.dumpFixedW31j("あい", 4, new byte[]{0x01, 0x02});
+ bex.flush();
+ barr = bos.toByteArray();
+ assertEquals(4, barr.length);
+ assertEquals((byte)0x82, barr[0]);
+ assertEquals((byte)0xA0, barr[1]);
+ assertEquals((byte)0x82, barr[2]);
+ assertEquals((byte)0xA2, barr[3]);
+
+ bos.reset();
+ bex.dumpFixedW31j("あい", 0, new byte[]{0x01, 0x02});
+ bex.flush();
+ barr = bos.toByteArray();
+ assertEquals(4, barr.length);
+ assertEquals((byte)0x82, barr[0]);
+ assertEquals((byte)0xA0, barr[1]);
+ assertEquals((byte)0x82, barr[2]);
+ assertEquals((byte)0xA2, barr[3]);
+
+ bos.reset();
try{
bex.dumpFixedW31j("あい", 3, new byte[]{0x00});
fail();
/**
* Test of dumpHollerithUtf16LE method, of class BinaryExporter.
+ * @throws Exception
*/
@Test
public void testDumpHollerithUtf16LE() throws Exception {
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.bin.export;
+
+import java.nio.charset.CharacterCodingException;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class IllegalTextExportExceptionTest {
+
+ public IllegalTextExportExceptionTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void testSomeMethod() {
+ System.out.println("constructor");
+
+ IllegalTextExportException ex;
+
+ ex = new IllegalTextExportException();
+ assertNull(ex.getCause());
+ assertNull(ex.getMessage());
+
+ ex = new IllegalTextExportException("msg");
+ assertNull(ex.getCause());
+ assertEquals("msg", ex.getMessage());
+
+ CharacterCodingException cex = new CharacterCodingException();
+ ex = new IllegalTextExportException(cex);
+ assertEquals(cex, ex.getCause());
+ assertEquals(cex.toString(), ex.getMessage());
+
+ ex = new IllegalTextExportException("msg", cex);
+ assertEquals(cex, ex.getCause());
+ assertEquals("msg", ex.getMessage());
+
+ return;
+ }
+
+}
/*
*/
-package jp.sourceforge.mikutoga.binio;
+package jp.sfjp.mikutoga.bin.export;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
}
/**
+ * Test of constructor, of class TextExporter.
+ * @throws Exception
+ */
+ @Test
+ public void testCons() throws Exception {
+ System.out.println("constructor");
+
+ TextExporter exp;
+
+ try{
+ exp = new TextExporter((Charset)null);
+ fail();
+ }catch(NullPointerException e){
+ // GOOD
+ }
+
+ try{
+ exp = new TextExporter((CharsetEncoder)null);
+ fail();
+ }catch(NullPointerException e){
+ // GOOD
+ }
+
+ return;
+ }
+
+ /**
* Test of getEncoder method, of class TextExporter.
*/
@Test
// GOOD
}
+ try{
+ exporter.setCharBufSize(0);
+ fail();
+ }catch(IllegalArgumentException e){
+ // GOOD
+ }
+
return;
}
/**
* Test of dumpText method, of class TextExporter.
+ * @throws Exception
*/
@Test
public void testDumpText() throws Exception {
/**
* Test of encodeToByteStream method, of class TextExporter.
+ * @throws Exception
*/
@Test
public void testEncodeToByteStream() throws Exception {
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.bin.parser;
+
+import java.nio.charset.Charset;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class CommonParserTest {
+
+ public CommonParserTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of getPosition method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testGetPosition() throws Exception{
+ System.out.println("getPosition");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(new byte[100]);
+ parser = new CommonParser(is);
+
+ assertEquals(0, parser.getPosition());
+
+ parser.parseByte();
+ assertEquals(1, parser.getPosition());
+
+ parser.parseLeInt();
+ assertEquals(5, parser.getPosition());
+
+ parser.skip(10);
+ assertEquals(15, parser.getPosition());
+
+ return;
+ }
+
+ /**
+ * Test of hasMore method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testHasMore() throws Exception {
+ System.out.println("hasMore");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(0x00, 0x01, 0x02);
+ parser = new CommonParser(is);
+
+ assertTrue(parser.hasMore());
+
+ assertEquals((byte)0x00, parser.parseByte());
+ assertTrue(parser.hasMore());
+
+ assertEquals((byte)0x01, parser.parseByte());
+ assertTrue(parser.hasMore());
+
+ assertEquals((byte)0x02, parser.parseByte());
+ assertFalse(parser.hasMore());
+
+ return;
+ }
+
+ /**
+ * Test of skip method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testSkip() throws Exception {
+ System.out.println("skip");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(0x00, 0x01, 0x02);
+ parser = new CommonParser(is);
+
+ assertEquals((byte)0x00, parser.parseByte());
+
+ parser.skip(1L);
+ assertEquals((byte)0x02, parser.parseByte());
+
+ try{
+ parser.skip(1L);
+ fail();
+ }catch(MmdEofException e){
+ // GOOD
+ }
+
+ return;
+ }
+
+ /**
+ * Test of parseByteArray method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testParseByteArray_3args() throws Exception {
+ System.out.println("parseByteArray");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(0x01, 0x02, 0x03);
+ parser = new CommonParser(is);
+
+ byte[] dst = {
+ (byte)0xf1, (byte)0xf2, (byte)0xf3, (byte)0xf4, (byte)0xf5
+ };
+
+ parser.parseByteArray(dst, 1, 2);
+
+ assertEquals((byte)0xf1, dst[0]);
+ assertEquals((byte)0x01, dst[1]);
+ assertEquals((byte)0x02, dst[2]);
+ assertEquals((byte)0xf4, dst[3]);
+ assertEquals((byte)0xf5, dst[4]);
+
+ return;
+ }
+
+ /**
+ * Test of parseByteArray method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testParseByteArray_byteArr() throws Exception {
+ System.out.println("parseByteArray");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(0x01, 0x02, 0x03);
+ parser = new CommonParser(is);
+
+ byte[] dst = {
+ (byte)0xf1, (byte)0xf2
+ };
+
+ parser.parseByteArray(dst);
+
+ assertEquals((byte)0x01, dst[0]);
+ assertEquals((byte)0x02, dst[1]);
+
+ return;
+ }
+
+ /**
+ * Test of parseByte method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testParseByte() throws Exception {
+ System.out.println("parseByte");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(0x01, 0x02, 0x03);
+ parser = new CommonParser(is);
+
+ assertEquals((byte)0x01, parser.parseByte());
+ assertEquals((byte)0x02, parser.parseByte());
+ assertEquals((byte)0x03, parser.parseByte());
+
+ try{
+ parser.parseByte();
+ fail();
+ }catch(MmdEofException e){
+ // GOOD
+ }
+
+ return;
+ }
+
+ /**
+ * Test of parseUByteAsInt method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testParseUByteAsInt() throws Exception {
+ System.out.println("parseUByteAsInt");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(0x00, 0x01, 0xff);
+ parser = new CommonParser(is);
+
+ assertEquals(0x00, parser.parseUByteAsInt());
+ assertEquals(0x01, parser.parseUByteAsInt());
+ assertEquals(0xff, parser.parseUByteAsInt());
+
+ try{
+ parser.parseUByteAsInt();
+ fail();
+ }catch(MmdEofException e){
+ // GOOD
+ }
+
+ return;
+ }
+
+ /**
+ * Test of parseBoolean method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testParseBoolean() throws Exception {
+ System.out.println("parseBoolean");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(0x00, 0x01, 0x02, 0xff);
+ parser = new CommonParser(is);
+
+ assertFalse(parser.parseBoolean());
+ assertTrue(parser.parseBoolean());
+ assertTrue(parser.parseBoolean());
+ assertTrue(parser.parseBoolean());
+
+ try{
+ parser.parseBoolean();
+ fail();
+ }catch(MmdEofException e){
+ // GOOD
+ }
+
+ return;
+ }
+
+ /**
+ * Test of parseLeShort method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testParseLeShort() throws Exception {
+ System.out.println("parseLeShort");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(0xfe, 0xff, 0x01, 0x00, 0x80);
+ parser = new CommonParser(is);
+
+ assertEquals((short)-2, parser.parseLeShort());
+ assertEquals((short)1, parser.parseLeShort());
+
+ try{
+ parser.parseLeShort();
+ fail();
+ }catch(MmdEofException e){
+ // GOOD
+ }
+
+ return;
+ }
+
+ /**
+ * Test of parseLeUShortAsInt method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testParseLeUShortAsInt() throws Exception {
+ System.out.println("parseLeUShortAsInt");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(0xfe, 0xff, 0x01, 0x00, 0x80);
+ parser = new CommonParser(is);
+
+ assertEquals(0xfffe, parser.parseLeUShortAsInt());
+ assertEquals(1, parser.parseLeUShortAsInt());
+
+ try{
+ parser.parseLeUShortAsInt();
+ fail();
+ }catch(MmdEofException e){
+ // GOOD
+ }
+
+ return;
+ }
+
+ /**
+ * Test of parseLeInt method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testParseLeInt() throws Exception {
+ System.out.println("parseLeInt");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(
+ 0xfe, 0xff, 0xff, 0xff,
+ 0x78, 0x56, 0x34, 0x12,
+ 0x7f );
+ parser = new CommonParser(is);
+
+ assertEquals(-2, parser.parseLeInt());
+ assertEquals(0x12345678, parser.parseLeInt());
+
+ try{
+ parser.parseLeInt();
+ fail();
+ }catch(MmdEofException e){
+ // GOOD
+ }
+
+ return;
+ }
+
+ /**
+ * Test of parseLeFloat method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testParseLeFloat() throws Exception {
+ System.out.println("parseLeFloat");
+
+ CommonParser parser;
+ DummyInputStream is;
+
+ is = new DummyInputStream(
+ 0x00, 0x00, 0xc0, 0xbf,
+ 0x78, 0x56, 0x34, 0x12,
+ 0x7f );
+ parser = new CommonParser(is);
+
+ assertEquals(-1.5f, parser.parseLeFloat(), 0.0);
+ assertEquals(
+ Float.intBitsToFloat(0x12345678), parser.parseLeFloat(),
+ 0.0 );
+
+ try{
+ parser.parseLeFloat();
+ fail();
+ }catch(MmdEofException e){
+ // GOOD
+ }
+
+ return;
+ }
+
+ /**
+ * Test of parseString method, of class CommonParser.
+ * @throws Exception
+ */
+ @Test
+ public void testParseString() throws Exception {
+ System.out.println("parseString");
+
+ CommonParser parser;
+ DummyInputStream is;
+ TextDecoder decoder;
+
+ decoder = new TextDecoder(Charset.forName("Shift_JIS"));
+
+ is = new DummyInputStream(0x82, 0xa0, 0x82, 0xa2, 0x46);
+ parser = new CommonParser(is);
+
+ assertEquals("あ", parser.parseString(decoder, 2));
+ assertEquals("い", parser.parseString(decoder, 2));
+
+ try{
+ parser.parseString(decoder, 2);
+ fail();
+ }catch(MmdEofException e){
+ // GOOD
+ }
+
+ is = new DummyInputStream(0x82, 0xa0, 0x82, 0xa2);
+ parser = new CommonParser(is);
+
+ assertEquals("あい", parser.parseString(decoder, 4));
+
+ is = new DummyInputStream(0x82, 0xa0, 0x82, 0xff);
+ parser = new CommonParser(is);
+
+ try{
+ parser.parseString(decoder, 4);
+ fail();
+ }catch(MmdFormatException e){
+// assertEquals("unmapped character(position:2)", e.getMessage());
+ // GOOD
+ }
+
+ is = new DummyInputStream(0x82, 0xa0, 0x82);
+ parser = new CommonParser(is);
+
+ try{
+ parser.parseString(decoder, 3);
+ fail();
+ }catch(MmdFormatException e){
+// assertEquals("illegal character encoding(position:1)", e.getMessage());
+ // GOOD
+ }
+
+ is = new DummyInputStream(0x41, 0x42, 0x43);
+ parser = new CommonParser(is);
+
+ assertEquals("A", parser.parseString(decoder, 1));
+ assertEquals("BC", parser.parseString(decoder, 2));
+
+ return;
+ }
+
+}
/*
*/
-package jp.sourceforge.mikutoga.parser;
+package jp.sfjp.mikutoga.bin.parser;
import java.io.IOException;
import java.io.InputStream;
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.bin.parser;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class MmdEofExceptionTest {
+
+ public MmdEofExceptionTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void testSomeMethod() {
+
+ MmdFormatException ex;
+
+ ex = new MmdEofException();
+ assertNull(ex.getMessage());
+
+ ex = new MmdEofException("ERROR");
+ assertEquals("ERROR", ex.getMessage());
+
+ ex = new MmdEofException(99);
+ assertEquals("(position:99)", ex.getMessage());
+
+ ex = new MmdEofException("ERROR", 99);
+ assertEquals("ERROR(position:99)", ex.getMessage());
+
+ return;
+ }
+
+}
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.bin.parser;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class MmdFormatExceptionTest {
+
+ public MmdFormatExceptionTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of getMessage method, of class MmdFormatException.
+ */
+ @Test
+ public void testGetMessage() {
+ System.out.println("getMessage");
+
+ MmdFormatException ex;
+
+ ex = new MmdFormatException();
+ assertNull(ex.getMessage());
+
+ ex = new MmdFormatException("ERROR");
+ assertEquals("ERROR", ex.getMessage());
+
+ ex = new MmdFormatException(99);
+ assertEquals("(position:99)", ex.getMessage());
+
+ ex = new MmdFormatException("ERROR", 99);
+ assertEquals("ERROR(position:99)", ex.getMessage());
+
+ return;
+ }
+
+ /**
+ * Test of toString method, of class MmdFormatException.
+ */
+ @Test
+ public void testToString() {
+ System.out.println("toString");
+
+ MmdFormatException ex;
+
+ ex = new MmdFormatException();
+ assertNull(ex.getMessage());
+ assertEquals(MmdFormatException.class.getName(), ex.toString());
+
+ ex = new MmdFormatException("ERROR", 99);
+ assertEquals(MmdFormatException.class.getName()
+ + ": ERROR(position:99)",
+ ex.toString() );
+
+ return;
+ }
+
+ /**
+ * Test of getPosition method, of class MmdFormatException.
+ */
+ @Test
+ public void testGetPosition() {
+ System.out.println("getPosition");
+
+ MmdFormatException ex;
+
+ ex = new MmdFormatException();
+ assertTrue(ex.getPosition() < 0);
+
+ ex = new MmdFormatException("ERROR");
+ assertTrue(ex.getPosition() < 0);
+
+ ex = new MmdFormatException(99);
+ assertEquals(99, ex.getPosition());
+
+ ex = new MmdFormatException("ERROR", 99);
+ assertEquals(99, ex.getPosition());
+
+ return;
+ }
+
+ /**
+ * Test of hasPosition method, of class MmdFormatException.
+ */
+ @Test
+ public void testHasPosition() {
+ System.out.println("hasPosition");
+
+ MmdFormatException ex;
+
+ ex = new MmdFormatException();
+ assertFalse(ex.hasPosition());
+
+ ex = new MmdFormatException("ERROR");
+ assertFalse(ex.hasPosition());
+
+ ex = new MmdFormatException(99);
+ assertTrue(ex.hasPosition());
+
+ ex = new MmdFormatException("ERROR", 99);
+ assertTrue(ex.hasPosition());
+
+ return;
+ }
+
+}
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.bin.parser;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class ParseStageTest {
+
+ public ParseStageTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of getNo method, of class ParseStage.
+ */
+ @Test
+ public void testGetNo() {
+ System.out.println("getNo");
+
+ ParseStage p1 = new ParseStage();
+ ParseStage p2 = new ParseStage();
+ ParseStage p3 = new ParseStage();
+
+ assertEquals(1, p2.getNo() - p1.getNo());
+ assertEquals(1, p3.getNo() - p2.getNo());
+
+ return;
+ }
+
+}
/*
*/
-package jp.sourceforge.mikutoga.parser;
+package jp.sfjp.mikutoga.bin.parser;
+import java.nio.ByteBuffer;
+import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
}
/**
- * Test of prepareBuffer method, of class TextDecoder.
- */
- @Test
- public void testPrepareBuffer() {
- System.out.println("prepareBuffer");
- return;
- }
-
- /**
* Test of setChopMode, getChopMode method, of class TextDecoder.
* @throws Exception
*/
assertDecoded("41:00:42", "A", decoder);
assertDecoded("00:41:42", "", decoder);
assertDecoded("41:00:88", "A", decoder);
+ assertDecoded("", "", decoder);
decoder.setZeroChopMode(false);
assertDecoded("41:00:42", "A\u0000B", decoder);
+ assertDecoded("", "", decoder);
return;
}
TextDecoder decoder)
throws Exception{
byte[] bdata = byteArray(bin);
- assertDecoded(bin, desired, decoder, bdata.length);
+ ByteBuffer bBuf = ByteBuffer.wrap(bdata);
+ assertDecoded(bBuf, desired, decoder);
return;
}
public void assertDecoded(String bin, String desired,
TextDecoder decoder, int len)
throws Exception{
- byte[] bdata;
-
- bdata = byteArray(bin);
+ byte[] bdata = byteArray(bin);
+ ByteBuffer bBuf = ByteBuffer.wrap(bdata, 0, len);
+ assertDecoded(bBuf, desired, decoder);
+ return;
+ }
+ public void assertDecoded(ByteBuffer bBuf, String desired,
+ TextDecoder decoder)
+ throws Exception{
String result;
- result = decoder.decode(0, bdata, 0, len);
+ result = decoder.decode(bBuf);
assertEquals(desired, result);
public void assertFormatError(String bin,
TextDecoder decoder, int len)
throws Exception{
- byte[] bdata;
-
- bdata = byteArray(bin);
+ byte[] bdata = byteArray(bin);
+ ByteBuffer bBuf = ByteBuffer.wrap(bdata, 0, len);
try{
- decoder.decode(0, bdata, 0, len);
+ decoder.decode(bBuf);
fail();
- }catch(MmdFormatException e){
+ }catch(CharacterCodingException e){
// OK
}
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.corelib;
+
+import java.util.List;
+import java.util.Locale;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class I18nTextTest {
+
+ public I18nTextTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of setPrimaryText method, of class I18nText.
+ */
+ @Test
+ public void testSetPrimaryText() {
+ System.out.println("setPrimaryText");
+
+ I18nText text;
+
+ text = new I18nText();
+ text.setPrimaryText("pri");
+ assertEquals("pri", text.getPrimaryText());
+
+ text.setPrimaryText(null);
+ assertNull(text.getPrimaryText());
+
+ return;
+ }
+
+ /**
+ * Test of setGlobalText method, of class I18nText.
+ */
+ @Test
+ public void testSetGlobalText() {
+ System.out.println("setGlobalText");
+
+ I18nText text;
+
+ text = new I18nText();
+ text.setGlobalText("glo");
+
+ assertEquals("glo", text.getGlobalText());
+
+ text.setGlobalText(null);
+ assertNull(text.getGlobalText());
+
+ return;
+ }
+
+ /**
+ * Test of setI18nText method, of class I18nText.
+ */
+ @Test
+ public void testSetI18nText_Locale_CharSequence() {
+ System.out.println("setI18nText");
+
+ I18nText text;
+
+ text = new I18nText();
+ text.setI18nText(Locale.JAPANESE, "pri");
+ assertEquals("pri", text.getPrimaryText());
+
+ text.setI18nText(Locale.JAPANESE, null);
+ assertNull(text.getPrimaryText());
+
+ return;
+ }
+
+ /**
+ * Test of setI18nText method, of class I18nText.
+ */
+ @Test
+ public void testSetI18nText_String_CharSequence() {
+ System.out.println("setI18nText");
+
+ I18nText text;
+
+ text = new I18nText();
+ text.setI18nText("ja", "pri");
+ assertEquals("pri", text.getPrimaryText());
+
+ text.setI18nText("ja", null);
+ assertNull(text.getPrimaryText());
+
+ return;
+ }
+
+ /**
+ * Test of getPrimaryText method, of class I18nText.
+ */
+ @Test
+ public void testGetPrimaryText() {
+ System.out.println("getPrimaryText");
+
+ I18nText text;
+
+ text = new I18nText();
+ assertNull(text.getPrimaryText());
+
+ text.setPrimaryText("pri");
+ assertEquals("pri", text.getPrimaryText());
+
+ return;
+ }
+
+ /**
+ * Test of getGlobalText method, of class I18nText.
+ */
+ @Test
+ public void testGetGlobalText() {
+ System.out.println("getGlobalText");
+
+ I18nText text;
+
+ text = new I18nText();
+ assertNull(text.getGlobalText());
+
+ text.setGlobalText("glo");
+ assertEquals("glo", text.getGlobalText());
+
+ return;
+ }
+
+ /**
+ * Test of getI18nText method, of class I18nText.
+ */
+ @Test
+ public void testGetI18nText_Locale() {
+ System.out.println("getI18nText");
+
+ I18nText text;
+
+ text = new I18nText();
+ text.setPrimaryText("pri");
+
+ assertEquals("pri", text.getI18nText(Locale.JAPANESE));
+ assertNull(text.getI18nText(Locale.ENGLISH));
+
+ return;
+ }
+
+ /**
+ * Test of getI18nText method, of class I18nText.
+ */
+ @Test
+ public void testGetI18nText_String() {
+ System.out.println("getI18nText");
+
+ I18nText text;
+
+ text = new I18nText();
+ text.setPrimaryText("pri");
+
+ assertEquals("pri", text.getI18nText("ja"));
+ assertNull(text.getI18nText("en"));
+
+ return;
+ }
+
+ /**
+ * Test of getText method, of class I18nText.
+ */
+ @Test
+ public void testGetText() {
+ System.out.println("getText");
+
+ I18nText text;
+
+ text = new I18nText();
+ assertEquals("", text.getText());
+
+ text.setPrimaryText("pri");
+ assertEquals("pri", text.getText());
+
+ return;
+ }
+
+ /**
+ * Test of getLocalizedText method, of class I18nText.
+ */
+ @Test
+ public void testGetLocalizedText() {
+ System.out.println("getLocalizedText");
+
+ I18nText text;
+
+ text = new I18nText();
+ assertEquals("", text.getLocalizedText());
+
+ text = new I18nText();
+ text.setPrimaryText("pri");
+ assertEquals("pri", text.getLocalizedText());
+
+ text = new I18nText();
+ text.setGlobalText("glo");
+ assertEquals("glo", text.getLocalizedText());
+
+ text = new I18nText();
+ text.setI18nText(Locale.CHINESE, "chi");
+ assertEquals("chi", text.getLocalizedText());
+
+ // default locale...
+
+ return;
+ }
+
+ /**
+ * Test of clearI18nText method, of class I18nText.
+ */
+ @Test
+ public void testClearI18nText() {
+ System.out.println("clearI18nText");
+
+ I18nText text;
+
+ text = new I18nText();
+
+ text.setPrimaryText("pri");
+ text.setGlobalText("glo");
+
+ assertNotNull(text.getPrimaryText());
+ assertNotNull(text.getGlobalText());
+
+ text.clearI18nText();
+
+ assertNull(text.getPrimaryText());
+ assertNull(text.getGlobalText());
+
+ return;
+ }
+
+ /**
+ * Test of lang639CodeList method, of class I18nText.
+ */
+ @Test
+ public void testLang639CodeList() {
+ System.out.println("lang639CodeList");
+
+ I18nText text;
+ List<String> list;
+
+ text = new I18nText();
+
+ list = text.lang639CodeList();
+ assertTrue(list.isEmpty());
+
+ text.setI18nText(Locale.CHINA, "chi");
+ text.setPrimaryText("pri");
+ text.setGlobalText("glo");
+
+ list = text.lang639CodeList();
+
+ assertEquals(3, list.size());
+ assertEquals("ja", list.get(0));
+ assertEquals("en", list.get(1));
+ assertEquals("zh", list.get(2));
+
+ return;
+ }
+
+ /**
+ * Test of hasPrimaryText method, of class I18nText.
+ */
+ @Test
+ public void testHasPrimaryText() {
+ System.out.println("hasPrimaryText");
+
+ I18nText text;
+
+ text = new I18nText();
+ assertFalse(text.hasPrimaryText());
+
+ text.setPrimaryText("pri");
+ assertTrue(text.hasPrimaryText());
+
+ text.setPrimaryText(null);
+ assertFalse(text.hasPrimaryText());
+
+ text.setGlobalText("glo");
+ assertFalse(text.hasPrimaryText());
+
+ return;
+ }
+
+ /**
+ * Test of hasGlobalText method, of class I18nText.
+ */
+ @Test
+ public void testHasGlobalText() {
+ System.out.println("hasGlobalText");
+
+ I18nText text;
+
+ text = new I18nText();
+ assertFalse(text.hasGlobalText());
+
+ text.setGlobalText("glo");
+ assertTrue(text.hasGlobalText());
+
+ text.setGlobalText(null);
+ assertFalse(text.hasGlobalText());
+
+ text.setPrimaryText("pri");
+ assertFalse(text.hasGlobalText());
+
+ return;
+ }
+
+ /**
+ * Test of charAt method, of class I18nText.
+ */
+ @Test
+ public void testCharAt() {
+ System.out.println("charAt");
+
+ I18nText text;
+
+ text = new I18nText();
+
+ text.setPrimaryText("pri");
+ text.setGlobalText("glo");
+ text.setI18nText(Locale.CHINA, "chi");
+
+ assertEquals('r', text.charAt(1));
+
+ return;
+ }
+
+ /**
+ * Test of length method, of class I18nText.
+ */
+ @Test
+ public void testLength() {
+ System.out.println("length");
+
+ I18nText text;
+
+ text = new I18nText();
+
+ text.setPrimaryText("pri");
+ text.setGlobalText("glob");
+ text.setI18nText(Locale.CHINA, "china");
+
+ assertEquals(3, text.length());
+
+ return;
+ }
+
+ /**
+ * Test of subSequence method, of class I18nText.
+ */
+ @Test
+ public void testSubSequence() {
+ System.out.println("subSequence");
+
+ I18nText text;
+
+ text = new I18nText();
+
+ text.setPrimaryText("pri");
+ text.setGlobalText("glo");
+ text.setI18nText(Locale.CHINA, "chi");
+
+ assertEquals("p", text.subSequence(0, 1));
+
+ return;
+ }
+
+ /**
+ * Test of toString method, of class I18nText.
+ */
+ @Test
+ public void testToString() {
+ System.out.println("toString");
+
+ I18nText text;
+
+ text = new I18nText();
+
+ text.setPrimaryText("pri");
+ text.setGlobalText("glo");
+ text.setI18nText(Locale.CHINA, "chi");
+
+ assertEquals("pri", text.toString());
+
+ return;
+ }
+
+}
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.math;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public strictfp class EulerYXZTest {
+
+ public EulerYXZTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of constructor, of class EulerYXZ.
+ */
+ @Test
+ public void testCons() {
+ System.out.println("constructor");
+
+ EulerYXZ euler;
+
+ euler = new EulerYXZ();
+ assertEquals(0.0, euler.getXRot(), 0.0);
+ assertEquals(0.0, euler.getYRot(), 0.0);
+ assertEquals(0.0, euler.getZRot(), 0.0);
+
+ euler = new EulerYXZ(1.0, 2.0, 3.0);
+ assertEquals(1.0, euler.getXRot(), 0.0);
+ assertEquals(2.0, euler.getYRot(), 0.0);
+ assertEquals(3.0, euler.getZRot(), 0.0);
+
+ euler.setXRot(4.0);
+ assertEquals(4.0, euler.getXRot(), 0.0);
+ assertEquals(2.0, euler.getYRot(), 0.0);
+ assertEquals(3.0, euler.getZRot(), 0.0);
+
+ euler.setYRot(5.0);
+ assertEquals(4.0, euler.getXRot(), 0.0);
+ assertEquals(5.0, euler.getYRot(), 0.0);
+ assertEquals(3.0, euler.getZRot(), 0.0);
+
+ euler.setZRot(6.0);
+ assertEquals(4.0, euler.getXRot(), 0.0);
+ assertEquals(5.0, euler.getYRot(), 0.0);
+ assertEquals(6.0, euler.getZRot(), 0.0);
+
+ euler.setRot(10.0, 11.0, 12.0);
+ assertEquals(10.0, euler.getXRot(), 0.0);
+ assertEquals(11.0, euler.getYRot(), 0.0);
+ assertEquals(12.0, euler.getZRot(), 0.0);
+
+ return;
+ }
+
+ /**
+ * Test of toString method, of class EulerYXZ.
+ */
+ @Test
+ public void testToString() {
+ System.out.println("toString");
+
+ EulerYXZ euler;
+
+ euler = new EulerYXZ(1.0, 2.0, 3.0);
+ assertEquals("x=1.0 y=2.0 z=3.0", euler.toString());
+
+ euler = new EulerYXZ(-0.0, Double.MIN_VALUE, Double.MAX_VALUE);
+ assertEquals("x=-0.0 y=4.9E-324 z=1.7976931348623157E308", euler.toString());
+
+ euler = new EulerYXZ(0.5, 0.25, StrictMath.PI);
+ assertEquals("x=0.5 y=0.25 z=3.141592653589793", euler.toString());
+
+ return;
+ }
+
+ /**
+ * Test of toDegString method, of class EulerYXZ.
+ */
+ @Test
+ public void testToDegString() {
+ System.out.println("toDegString");
+
+ EulerYXZ euler;
+
+ euler = new EulerYXZ(1.0, 2.0, 3.0);
+ assertEquals("x=57.29577951308232 y=114.59155902616465 z=171.88733853924697", euler.toDegString());
+
+ return;
+ }
+
+}
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.math;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public strictfp class MkPos2DTest {
+
+ public MkPos2DTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of constructor, of class MkPos2D.
+ */
+ @Test
+ public void testCons() {
+ System.out.println("constructor");
+
+ MkPos2D pos;
+
+ pos = new MkPos2D();
+ assertTrue(pos.isOriginPoint());
+ assertEquals(0.0, pos.getXpos(), 0.0);
+ assertEquals(0.0, pos.getYpos(), 0.0);
+
+ pos.setXpos(1.0);
+ assertFalse(pos.isOriginPoint());
+ assertEquals(1.0, pos.getXpos(), 0.0);
+ assertEquals(0.0, pos.getYpos(), 0.0);
+
+ pos.setYpos(2.0);
+ assertEquals(1.0, pos.getXpos(), 0.0);
+ assertEquals(2.0, pos.getYpos(), 0.0);
+
+ pos.setPosition(3.0, 4.0);
+ assertEquals(3.0, pos.getXpos(), 0.0);
+ assertEquals(4.0, pos.getYpos(), 0.0);
+
+ pos = new MkPos2D(5.0, 6.0);
+ assertEquals(5.0, pos.getXpos(), 0.0);
+ assertEquals(6.0, pos.getYpos(), 0.0);
+
+ return;
+ }
+
+ /**
+ * Test of toString method, of class MkPos2D.
+ */
+ @Test
+ public void testToString() {
+ System.out.println("toString");
+
+ MkPos2D pos;
+
+ pos = new MkPos2D();
+ assertEquals("pos=[0.0, 0.0]", pos.toString());
+
+ pos = new MkPos2D(-0.0, StrictMath.PI);
+ assertEquals("pos=[-0.0, 3.141592653589793]", pos.toString());
+
+ return;
+ }
+
+}
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.math;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public strictfp class MkPos3DTest {
+
+ public MkPos3DTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of constructor, of class MkPos3D.
+ */
+ @Test
+ public void testCons() {
+ System.out.println("constructor");
+
+ MkPos3D pos;
+
+ pos = new MkPos3D();
+ assertTrue(pos.isOriginPoint());
+ assertEquals(0.0, pos.getXpos(), 0.0);
+ assertEquals(0.0, pos.getYpos(), 0.0);
+ assertEquals(0.0, pos.getZpos(), 0.0);
+
+ pos.setXpos(1.0);
+ assertFalse(pos.isOriginPoint());
+ assertEquals(1.0, pos.getXpos(), 0.0);
+ assertEquals(0.0, pos.getYpos(), 0.0);
+ assertEquals(0.0, pos.getZpos(), 0.0);
+
+ pos.setYpos(2.0);
+ assertEquals(1.0, pos.getXpos(), 0.0);
+ assertEquals(2.0, pos.getYpos(), 0.0);
+ assertEquals(0.0, pos.getZpos(), 0.0);
+
+ pos.setZpos(3.0);
+ assertEquals(1.0, pos.getXpos(), 0.0);
+ assertEquals(2.0, pos.getYpos(), 0.0);
+ assertEquals(3.0, pos.getZpos(), 0.0);
+
+ pos.setPosition(4.0, 5.0, 6.0);
+ assertEquals(4.0, pos.getXpos(), 0.0);
+ assertEquals(5.0, pos.getYpos(), 0.0);
+ assertEquals(6.0, pos.getZpos(), 0.0);
+
+ pos = new MkPos3D(7.0, 8.0, 9.0);
+ assertEquals(7.0, pos.getXpos(), 0.0);
+ assertEquals(8.0, pos.getYpos(), 0.0);
+ assertEquals(9.0, pos.getZpos(), 0.0);
+
+ return;
+ }
+
+ /**
+ * Test of toString method, of class MkPos3D.
+ */
+ @Test
+ public void testToString() {
+ System.out.println("toString");
+
+ MkPos3D pos;
+
+ pos = new MkPos3D();
+ assertEquals("x=0.0 y=0.0 z=0.0", pos.toString());
+
+ pos = new MkPos3D(-0.0, StrictMath.PI, Double.MAX_VALUE);
+ assertEquals("x=-0.0 y=3.141592653589793 z=1.7976931348623157E308", pos.toString());
+
+ return;
+ }
+
+}
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.math;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public strictfp class MkQuatTest {
+
+ private static final double RAD_90DEG = StrictMath.PI / 2.0;
+ private static final double RAD_60DEG = StrictMath.PI / 3.0;
+ private static final double RAD_45DEG = StrictMath.PI / 4.0;
+ private static final double RAD_30DEG = StrictMath.PI / 6.0;
+ private static final double RAD_15DEG = StrictMath.PI / 12.0;
+ private static final double EPSILON = StrictMath.ulp(1.0);
+
+ public MkQuatTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ private void assert0UlpEquals(double expected, double x){
+ assertUlpEquals(expected, x, 0);
+ return;
+ }
+
+ private void assertUlpEquals(double expected, double x, int ulpNum){
+ double ulp = StrictMath.ulp(expected);
+ double delta = ulp * ulpNum;
+
+ assertEquals(expected, x, delta);
+
+ return;
+ }
+
+ /**
+ * Test of constructor, of class MkQuat.
+ */
+ @Test
+ public void testCons() {
+ System.out.println("constructor");
+
+ MkQuat qq;
+
+ qq = new MkQuat();
+ assert0UlpEquals(0.0, qq.getQ1());
+ assert0UlpEquals(0.0, qq.getQ2());
+ assert0UlpEquals(0.0, qq.getQ3());
+ assert0UlpEquals(1.0, qq.getQW());
+
+ qq.setQ1(2.0);
+ assert0UlpEquals(2.0, qq.getQ1());
+ assert0UlpEquals(0.0, qq.getQ2());
+ assert0UlpEquals(0.0, qq.getQ3());
+ assert0UlpEquals(1.0, qq.getQW());
+
+ qq.setQ2(3.0);
+ assert0UlpEquals(2.0, qq.getQ1());
+ assert0UlpEquals(3.0, qq.getQ2());
+ assert0UlpEquals(0.0, qq.getQ3());
+ assert0UlpEquals(1.0, qq.getQW());
+
+ qq.setQ3(4.0);
+ assert0UlpEquals(2.0, qq.getQ1());
+ assert0UlpEquals(3.0, qq.getQ2());
+ assert0UlpEquals(4.0, qq.getQ3());
+ assert0UlpEquals(1.0, qq.getQW());
+
+ qq.setQW(5.0);
+ assert0UlpEquals(2.0, qq.getQ1());
+ assert0UlpEquals(3.0, qq.getQ2());
+ assert0UlpEquals(4.0, qq.getQ3());
+ assert0UlpEquals(5.0, qq.getQW());
+
+ qq.setQ123W(6.0, 7.0, 8.0, 9.0);
+ assert0UlpEquals(6.0, qq.getQ1());
+ assert0UlpEquals(7.0, qq.getQ2());
+ assert0UlpEquals(8.0, qq.getQ3());
+ assert0UlpEquals(9.0, qq.getQW());
+
+ qq = new MkQuat(0.1, 0.2, 0.3, 0.4);
+ assert0UlpEquals(0.1, qq.getQ1());
+ assert0UlpEquals(0.2, qq.getQ2());
+ assert0UlpEquals(0.3, qq.getQ3());
+ assert0UlpEquals(0.4, qq.getQW());
+
+ MkQuat qqx = new MkQuat(1.0, 2.0, 3.0, 4.0);
+ qq = new MkQuat(qqx);
+ assert0UlpEquals(1.0, qq.getQ1());
+ assert0UlpEquals(2.0, qq.getQ2());
+ assert0UlpEquals(3.0, qq.getQ3());
+ assert0UlpEquals(4.0, qq.getQW());
+
+ return;
+ }
+
+ /**
+ * Test of mul method, of class MkQuat.
+ */
+ @Test
+ public void testMul() {
+ System.out.println("mul");
+
+ MkQuat qqa;
+ MkQuat qqb;
+ MkQuat result;
+
+ result = new MkQuat();
+
+ qqa = new MkQuat(1.0, 2.0, 3.0, 4.0);
+ qqb = new MkQuat(5.0, 6.0, 7.0, 8.0);
+ MkQuat.mul(qqa, qqb, result);
+ assert0UlpEquals(24.0, result.getQ1());
+ assert0UlpEquals(48.0, result.getQ2());
+ assert0UlpEquals(48.0, result.getQ3());
+ assert0UlpEquals(-6.0, result.getQW());
+
+ qqa = new MkQuat(1.0, 2.0, 3.0, 4.0);
+ qqb = new MkQuat(6.0, 7.0, 8.0, 9.0);
+ MkQuat.mul(qqa, qqb, result);
+ assert0UlpEquals(28.0, result.getQ1());
+ assert0UlpEquals(56.0, result.getQ2());
+ assert0UlpEquals(54.0, result.getQ3());
+ assert0UlpEquals(-8.0, result.getQW());
+
+ return;
+ }
+
+ /**
+ * Test of conjugate method, of class MkQuat.
+ */
+ @Test
+ public void testConjugate() {
+ System.out.println("conjugate");
+
+ MkQuat qq;
+ MkQuat result;
+
+ qq = new MkQuat(1.0, 2.0, 3.0, 4.0);
+ result = new MkQuat();
+ MkQuat.conjugate(qq, result);
+ assert0UlpEquals(-1.0, result.getQ1());
+ assert0UlpEquals(-2.0, result.getQ2());
+ assert0UlpEquals(-3.0, result.getQ3());
+ assert0UlpEquals(4.0, result.getQW());
+
+ return;
+ }
+
+ /**
+ * Test of normalize method, of class MkQuat.
+ */
+ @Test
+ public void testNormalize() {
+ System.out.println("normalize");
+
+ MkQuat qq;
+ MkQuat result;
+
+ qq = new MkQuat();
+ result = new MkQuat();
+ MkQuat.normalize(qq, result);
+ assert0UlpEquals(0.0, result.getQ1());
+ assert0UlpEquals(0.0, result.getQ2());
+ assert0UlpEquals(0.0, result.getQ3());
+ assert0UlpEquals(1.0, result.getQW());
+
+ qq = new MkQuat(2.0, 2.0, 2.0, 2.0);
+ MkQuat.normalize(qq, result);
+ assertUlpEquals(0.5, result.getQ1(), 0);
+ assertUlpEquals(0.5, result.getQ2(), 0);
+ assertUlpEquals(0.5, result.getQ3(), 0);
+ assertUlpEquals(0.5, result.getQW(), 0);
+
+ return;
+ }
+
+ /**
+ * Test of inverse method, of class MkQuat.
+ */
+ @Test
+ public void testInverse() {
+ System.out.println("inverse");
+
+ MkQuat qq;
+ MkQuat result;
+
+ qq = new MkQuat();
+ result = new MkQuat();
+ MkQuat.inverse(qq, result);
+ assert0UlpEquals(0.0, result.getQ1());
+ assert0UlpEquals(0.0, result.getQ2());
+ assert0UlpEquals(0.0, result.getQ3());
+ assert0UlpEquals(1.0, result.getQW());
+
+ qq = new MkQuat(2.0, 2.0, 2.0, 2.0);
+ MkQuat.inverse(qq, result);
+ assertUlpEquals(-0.125, result.getQ1(), 0);
+ assertUlpEquals(-0.125, result.getQ2(), 0);
+ assertUlpEquals(-0.125, result.getQ3(), 0);
+ assertUlpEquals(0.125, result.getQW(), 0);
+
+ return;
+ }
+
+ /**
+ * Test of abs method, of class MkQuat.
+ */
+ @Test
+ public void testAbs() {
+ System.out.println("abs");
+
+ MkQuat qq;
+
+ qq = new MkQuat();
+ assert0UlpEquals(1.0, qq.abs());
+
+ qq = new MkQuat(0.0, 0.0, 0.0, 0.0);
+ assert0UlpEquals(0.0, qq.abs());
+
+ qq = new MkQuat(1.0, 2.0, 0.0, 2.0);
+ assertUlpEquals(3.0, qq.abs(), 0);
+
+ qq = new MkQuat(2.0, 2.0, 2.0, 2.0);
+ assertUlpEquals(4.0, qq.abs(), 0);
+
+ return;
+ }
+
+ /**
+ * Test of setPos3D method, of class MkQuat.
+ */
+ @Test
+ public void testReadPos3D_3args() {
+ System.out.println("readPos3D");
+
+ MkQuat qq;
+
+ qq = new MkQuat(9, 9, 9, 9);
+ qq.setPos3D(1.0, 2.0, 3.0);
+ assert0UlpEquals(1.0, qq.getQ1());
+ assert0UlpEquals(2.0, qq.getQ2());
+ assert0UlpEquals(3.0, qq.getQ3());
+ assert0UlpEquals(0.0, qq.getQW());
+
+ return;
+ }
+
+ /**
+ * Test of setPos3D method, of class MkQuat.
+ */
+ @Test
+ public void testReadPos3D_MkPos3D() {
+ System.out.println("readPos3D");
+
+ MkQuat qq;
+ MkPos3D pos;
+
+ qq = new MkQuat(9, 9, 9, 9);
+ pos = new MkPos3D(1.0, 2.0, 3.0);
+ qq.setPos3D(pos);
+ assert0UlpEquals(1.0, qq.getQ1());
+ assert0UlpEquals(2.0, qq.getQ2());
+ assert0UlpEquals(3.0, qq.getQ3());
+ assert0UlpEquals(0.0, qq.getQW());
+
+ return;
+ }
+
+ /**
+ * Test of setEulerYXZ method, of class MkQuat.
+ */
+ @Test
+ public void testReadEulerYXZ_3args() {
+ System.out.println("readEulerYXZ");
+
+ MkQuat qq;
+
+ qq = new MkQuat(9, 9, 9, 9);
+ qq.setEulerYXZ(0.0, 0.0, 0.0);
+ assert0UlpEquals(0.0, qq.getQ1());
+ assert0UlpEquals(0.0, qq.getQ2());
+ assert0UlpEquals(0.0, qq.getQ3());
+ assert0UlpEquals(1.0, qq.getQW());
+
+ return;
+ }
+
+ /**
+ * Test of setEulerYXZ method, of class MkQuat.
+ */
+ @Test
+ public void testReadEulerYXZ_EulerYXZ() {
+ System.out.println("readEulerYXZ");
+
+ MkQuat qq;
+ EulerYXZ yxz;
+
+ qq = new MkQuat(9, 9, 9, 9);
+ yxz = new EulerYXZ();
+ qq.setEulerYXZ(yxz);
+ assert0UlpEquals(0.0, qq.getQ1());
+ assert0UlpEquals(0.0, qq.getQ2());
+ assert0UlpEquals(0.0, qq.getQ3());
+ assert0UlpEquals(1.0, qq.getQW());
+
+ return;
+ }
+
+ /**
+ * Test of toEulerYXZ method, of class MkQuat.
+ */
+ @Test
+ public void testToEulerYXZ_EulerYXZ_double() {
+ System.out.println("toEulerYXZ");
+
+ EulerYXZ eu;
+ MkQuat qq;
+
+ qq = new MkQuat();
+
+ qq.setEulerYXZ(1.0, 2.0, 3.0);
+ eu = new EulerYXZ();
+ qq.toEulerYXZ(eu, 0.0);
+ assertUlpEquals(1.0, eu.getXRot(), 1);
+ assertUlpEquals(2.0, eu.getYRot(), 2);
+ assertUlpEquals(3.0, eu.getZRot(), 0);
+
+ qq.setEulerYXZ(RAD_90DEG, 0.0, 0.0);
+ qq.toEulerYXZ(eu, 0.0);
+ assert0UlpEquals(RAD_90DEG, eu.getXRot());
+ assert0UlpEquals(0.0, eu.getYRot());
+ assert0UlpEquals(0.0, eu.getZRot());
+
+ qq.setEulerYXZ(RAD_90DEG, RAD_30DEG, 0.0);
+ qq.toEulerYXZ(eu, 0.0);
+ assert0UlpEquals(RAD_90DEG, eu.getXRot());
+ assert0UlpEquals(0.0, eu.getYRot());
+ assertUlpEquals(-RAD_30DEG, eu.getZRot(), 1);
+
+ qq.toEulerYXZ(eu, RAD_15DEG);
+ assert0UlpEquals(RAD_90DEG, eu.getXRot());
+ assert0UlpEquals(RAD_15DEG, eu.getYRot());
+ assertUlpEquals(-RAD_15DEG, eu.getZRot(), 2);
+
+ qq.setEulerYXZ(RAD_90DEG, RAD_45DEG, 0.0);
+ qq.toEulerYXZ(eu, 0.0);
+ assert0UlpEquals(RAD_90DEG, eu.getXRot());
+ assert0UlpEquals(0.0, eu.getYRot());
+ assert0UlpEquals(-RAD_45DEG, eu.getZRot());
+
+ qq.setEulerYXZ(RAD_90DEG, RAD_45DEG, RAD_45DEG);
+ qq.toEulerYXZ(eu, 0.0);
+ assertEquals(RAD_90DEG, eu.getXRot(), 1E-7);
+ assert0UlpEquals(0.0, eu.getYRot());
+ assertEquals(0.0, eu.getZRot(), EPSILON);
+
+ qq.setEulerYXZ(RAD_90DEG, RAD_30DEG, RAD_60DEG);
+ qq.toEulerYXZ(eu, 0.0);
+ assert0UlpEquals(RAD_90DEG, eu.getXRot());
+ assert0UlpEquals(0.0, eu.getYRot());
+ assert0UlpEquals(RAD_30DEG, eu.getZRot());
+
+ qq.setEulerYXZ(RAD_30DEG, RAD_45DEG, RAD_45DEG);
+ qq.toEulerYXZ(eu, 0.0);
+ assertUlpEquals(RAD_30DEG, eu.getXRot(), 1);
+ assertUlpEquals(RAD_45DEG, eu.getYRot(), 1);
+ assertUlpEquals(RAD_45DEG, eu.getZRot(), 1);
+
+ return;
+ }
+
+ /**
+ * Test of toEulerYXZ method, of class MkQuat.
+ */
+ @Test
+ public void testToEulerYXZ_EulerYXZ() {
+ System.out.println("toEulerYXZ");
+
+ EulerYXZ eu;
+ MkQuat qq;
+
+ qq = new MkQuat();
+
+ qq.setEulerYXZ(1.0, 2.0, 3.0);
+ eu = new EulerYXZ();
+ qq.toEulerYXZ(eu);
+ assertUlpEquals(1.0, eu.getXRot(), 1);
+ assertUlpEquals(2.0, eu.getYRot(), 2);
+ assertUlpEquals(3.0, eu.getZRot(), 0);
+
+ qq.setEulerYXZ(StrictMath.PI, 0.0, 0.0);
+ qq.toEulerYXZ(eu);
+ assertEquals(0.0, eu.getXRot(), EPSILON);
+ assert0UlpEquals(StrictMath.PI, eu.getYRot());
+ assert0UlpEquals(StrictMath.PI, eu.getZRot());
+
+ return;
+ }
+
+ /**
+ * Test of rotatePos method, of class MkQuat.
+ */
+ @Test
+ public void testRotatePos() {
+ System.out.println("rotatePos");
+
+ MkPos3D pos;
+ MkPos3D result;
+ MkQuat qq;
+
+ qq = new MkQuat();
+
+ pos = new MkPos3D(1.0, 1.0, 1.0);
+ result = new MkPos3D();
+
+ qq.setEulerYXZ(0.0, RAD_90DEG, 0.0);
+ qq.rotatePos(pos, result);
+ assertUlpEquals(1.0, result.getXpos(), 0);
+ assertUlpEquals(1.0, result.getYpos(), 0);
+ assertUlpEquals(-1.0, result.getZpos(), 2);
+
+ qq.setEulerYXZ(RAD_90DEG, 0.0, 0.0);
+ qq.rotatePos(pos, result);
+ assertUlpEquals(1.0, result.getXpos(), 0);
+ assertUlpEquals(-1.0, result.getYpos(), 2);
+ assertUlpEquals(1.0, result.getZpos(), 0);
+
+ qq.setEulerYXZ(0.0, 0.0, RAD_90DEG);
+ qq.rotatePos(pos, result);
+ assertUlpEquals(-1.0, result.getXpos(), 2);
+ assertUlpEquals(1.0, result.getYpos(), 0);
+ assertUlpEquals(1.0, result.getZpos(), 0);
+
+ qq.setEulerYXZ(RAD_90DEG, RAD_90DEG, 0.0);
+ qq.rotatePos(pos, result);
+ assertUlpEquals(1.0, result.getXpos(), 2);
+ assertUlpEquals(-1.0, result.getYpos(), 1);
+ assertUlpEquals(-1.0, result.getZpos(), 1);
+
+ qq.setEulerYXZ(0.0, RAD_90DEG, RAD_90DEG);
+ qq.rotatePos(pos, result);
+ assertUlpEquals(1.0, result.getXpos(), 1);
+ assertUlpEquals(1.0, result.getYpos(), 1);
+ assertUlpEquals(1.0, result.getZpos(), 0);
+
+ qq.setEulerYXZ(RAD_90DEG, 0.0, RAD_90DEG);
+ qq.rotatePos(pos, result);
+ assertUlpEquals(-1.0, result.getXpos(), 1);
+ assertUlpEquals(-1.0, result.getYpos(), 1);
+ assertUlpEquals(1.0, result.getZpos(), 2);
+
+ pos = new MkPos3D(1.0, 2.0, 3.0);
+
+ qq.setEulerYXZ(0.0, RAD_90DEG, 0.0);
+ qq.rotatePos(pos, result);
+ assertUlpEquals(3.0, result.getXpos(), 0);
+ assertUlpEquals(2.0, result.getYpos(), 0);
+ assertUlpEquals(-1.0, result.getZpos(), 3);
+
+ qq.setEulerYXZ(RAD_90DEG, 0.0, 0.0);
+ qq.rotatePos(pos, result);
+ assertUlpEquals(1.0, result.getXpos(), 0);
+ assertUlpEquals(-3.0, result.getYpos(), 0);
+ assertUlpEquals(2.0, result.getZpos(), 2);
+
+ qq.setEulerYXZ(0.0, 0.0, RAD_90DEG);
+ qq.rotatePos(pos, result);
+ assertUlpEquals(-2.0, result.getXpos(), 0);
+ assertUlpEquals(1.0, result.getYpos(), 2);
+ assertUlpEquals(3.0, result.getZpos(), 0);
+
+ return;
+ }
+
+ /**
+ * Test of toString method, of class MkQuat.
+ */
+ @Test
+ public void testToString() {
+ System.out.println("toString");
+
+ MkQuat qq;
+
+ qq = new MkQuat(-0.0, Double.MIN_NORMAL, Double.MAX_EXPONENT, StrictMath.PI);
+ assertEquals("q1=-0.0 q2=2.2250738585072014E-308 q3=1023.0 w=3.141592653589793", qq.toString());
+
+ return;
+ }
+
+}
--- /dev/null
+/*
+ */
+
+package jp.sfjp.mikutoga.math;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public strictfp class MkVec3DTest {
+
+ public MkVec3DTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of constructor, of class MkVec3D.
+ */
+ @Test
+ public void testCons() {
+ System.out.println("constructor");
+
+ MkVec3D vec;
+
+ vec = new MkVec3D();
+ assertEquals(0.0, vec.getXVal(), 0.0);
+ assertEquals(0.0, vec.getYVal(), 0.0);
+ assertEquals(0.0, vec.getZVal(), 0.0);
+
+ vec.setXVal(1.0);
+ assertEquals(1.0, vec.getXVal(), 0.0);
+ assertEquals(0.0, vec.getYVal(), 0.0);
+ assertEquals(0.0, vec.getZVal(), 0.0);
+
+ vec.setYVal(2.0);
+ assertEquals(1.0, vec.getXVal(), 0.0);
+ assertEquals(2.0, vec.getYVal(), 0.0);
+ assertEquals(0.0, vec.getZVal(), 0.0);
+
+ vec.setZVal(3.0);
+ assertEquals(1.0, vec.getXVal(), 0.0);
+ assertEquals(2.0, vec.getYVal(), 0.0);
+ assertEquals(3.0, vec.getZVal(), 0.0);
+
+ vec.setVector(4.0, 5.0, 6.0);
+ assertEquals(4.0, vec.getXVal(), 0.0);
+ assertEquals(5.0, vec.getYVal(), 0.0);
+ assertEquals(6.0, vec.getZVal(), 0.0);
+
+ vec = new MkVec3D(7.0, 8.0, 9.0);
+ assertEquals(7.0, vec.getXVal(), 0.0);
+ assertEquals(8.0, vec.getYVal(), 0.0);
+ assertEquals(9.0, vec.getZVal(), 0.0);
+
+ return;
+ }
+
+ /**
+ * Test of toString method, of class MkVec3D.
+ */
+ @Test
+ public void testToString() {
+ System.out.println("toString");
+
+ MkVec3D vec;
+
+ vec = new MkVec3D();
+ assertEquals("vec=[0.0, 0.0, 0.0]", vec.toString());
+
+ vec = new MkVec3D(-0.0, StrictMath.PI, Double.MAX_VALUE);
+ assertEquals("vec=[-0.0, 3.141592653589793, 1.7976931348623157E308]", vec.toString());
+
+ return;
+ }
+
+}
package sample.pmd;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
import jp.sourceforge.mikutoga.pmd.parser.PmdBasicHandler;
import jp.sourceforge.mikutoga.pmd.parser.PmdBoneHandler;
import jp.sourceforge.mikutoga.pmd.parser.PmdEngHandler;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
import jp.sourceforge.mikutoga.pmd.parser.PmdParser;
/**
package sample.vmd;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.ParseStage;
import jp.sourceforge.mikutoga.vmd.VmdConst;
-import jp.sourceforge.mikutoga.vmd.parser.VmdLightingHandler;
-import jp.sourceforge.mikutoga.vmd.parser.VmdCameraHandler;
import jp.sourceforge.mikutoga.vmd.parser.VmdBasicHandler;
+import jp.sourceforge.mikutoga.vmd.parser.VmdCameraHandler;
+import jp.sourceforge.mikutoga.vmd.parser.VmdLightingHandler;
/**
* サンプルのハンドラ。
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
import jp.sourceforge.mikutoga.vmd.parser.VmdParser;
/**