package com.njcn.advance.event.cause.model;

/**
 * 向量结构
 * 对应C语言中的vec_struct
 */
public class VecStruct {
    private float r;  // 实部
    private float x;  // 虚部

    public VecStruct() {
        this(0.0f, 0.0f);
    }

    public VecStruct(float r, float x) {
        this.r = r;
        this.x = x;
    }

    // 向量模长
    public float magnitude() {
        return (float) Math.sqrt(r * r + x * x);
    }

    // 向量相角
    public float phase() {
        return (float) Math.atan2(x, r);
    }

    // Getters and Setters
    public float getR() {
        return r;
    }

    public void setR(float r) {
        this.r = r;
    }

    public float getX() {
        return x;
    }

    public void setX(float x) {
        this.x = x;
    }

    @Override
    public String toString() {
        return String.format("VecStruct{r=%.6f, x=%.6f}", r, x);
    }
}