All Downloads are FREE. Search and download functionalities are using the official Maven repository.

one.empty3.library1.shader.Vec Maven / Gradle / Ivy

There is a newer version: 2024.5.10
Show newest version
/*
 * Copyright (c) 2022-2023. Manuel Daniel Dahmen
 *
 *
 *    Copyright 2012-2023 Manuel Daniel Dahmen
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package one.empty3.library1.shader;

import java.util.Objects;

import one.empty3.library.Point3D;
import one.empty3.library.StructureMatrix;

public class Vec {
    private int dims;
    private final StructureMatrix vecVal
            = new StructureMatrix(1, Double.class);

    private final StructureMatrix vec
            = new StructureMatrix(1, Vec.class);

    public Vec(Point3D p) {
        for (int i = 0; i < 3; i++) {

            vecVal.add(p.get(i));
        }
    }

    public Vec(Double d) {
        vecVal.getData1d().add(d);
    }

    public Vec(int d) {
        for (int i = 0; i < d; d++)
            vecVal.getData1d().add(0.0);
    }

    public Vec(Double... comps) {
        for (int i = 0; i < comps.length; i++) {
            Double d = comps[i];
            vecVal.add(1, d);
        }
    }

    public Vec(Vec... comps) {
        for (int i = 0; i < comps.length; i++) {
            vec.add(comps[i]);

            for (int j = 0; j < comps[i].size(); j++) {

                vecVal.add(1, comps[i].get(j));
            }

        }
    }

    public double get(int i) {
        return vecVal.getElem(i);
    }


    public int getDims() {
        int dims = 0;
        if (vecVal.getData1d().size() > 0) {
            this.dims += vecVal.getData1d().size();
        }
        return dims;


    }

    public String toString() {
        String s = "vec" + getDims() +
                "(";
        if (vecVal.getData1d().size() > 0)
            for (int i = 0; i < vecVal.getData1d().size();
                 i++)
                s += vecVal.
                        getElem(i) + ", ";
        else
            for (int i = 0; i < vec.getData1d().size();
                 i++)
                s += vec.
                        getElem(i).toString() + ", ";
        s += ")";
        return s;
    }

    public double norme() {
        double d = 0.0;
        for (int i = 0; i < vecVal.getData1d().size(); i++)
            d += vecVal.getData1d().get(i) * vecVal.getData1d().get(i);
        return Math.sqrt(d);
    }

    /*
       public Double value(int i, int j) {
            if(i>=0 && i0) {
            da = new Double[getDims() ];
            int i = 0;
            for(i=0;i getVecVal() {
        return vecVal;
    }

    public StructureMatrix getVec() {
        return vec;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy