Worldedit
  Worldedit
Le site sur l'éditeur de warcraft 3 !
 
  FAQFAQ   RechercherRechercher   Liste des MembresListe des Membres    Groupes d'utilisateursGroupes d'utilisateurs   medals.php?sid=951f8e43210b736ba409753147cc8758Médailles   S'enregistrerS'enregistrer 
 ProfilProfil   Se connecter pour vérifier ses messages privésSe connecter pour vérifier ses messages privés   ConnexionConnexion 
  FAQFAQ World Editor   UploadUploader une map ou une image    UploadAjouter sa map à l'annuaire   UploadConsulter l'annuaire

[vjass] calculette

 
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Fonction Jass
Voir le sujet précédent :: Voir le sujet suivant  
Auteur Message
 kungfu-sheep
Anomalie floodiforme


Inscrit le: 14 Avr 2011
Messages: 1846
Sujets: 119
Spécialité en worldedit: fonctions paramétriques, équation de mouvement.


MessagePosté le: 01/08/14 01:14    Sujet du message: [vjass] calculette Citer

Nom de la fonction : Calculette
Créateur : kungfu-sheep
Fonctions requises : rien
Code :
Jass:
/*========================================================API========================================================
//      Function list :
//          struct : calcul
//              static method create takes string formule returns thistype
//                  traduit le string en calcul et retourne le premier noeud d'un arbre le contenant.
//
//              method executeCalcul takes nothing returns real
//                  permet d'exécuter le calcul se trouvant actuellement dans l'arbre. x EST A 0 PAR DEFAUT.
//
//              method setIntervalle takes real a, real b, real iteration returns nothing
//                  défini l'intervalle dans lequel on calcule la fonction avec la variable x ainsi que l'itération qu'on fera dans l'intervalle.
//                  PAR DEFAUT L'INTERVALLE EST [0;0]
//
//              method setTabReal takes nothing returns nothing
//                  enregistre l'intégralité des valeurs pour une fonction dans l'intervalle donné. LIMITE A 8000 VALEURS.
//
//              method getRealValue takes integer i returns real
//                  récupère la valeur numéro i de la fonction.
//
//              le membre static x se modifie à la main de la manière suivante : set calcul.x[NomInstance.i] = TaValeur
//                       
===================================================================================================================*/

library Calculette
    globals
        private integer I = 0
        private hashtable Hash = InitHashtable()
    endglobals
   
   
    private struct intervalle
        real begin
        real end
       
        static method create takes real begin, real end returns thistype
            local thistype this = thistype.allocate()

            set this.begin = begin
            set this.end = end
           
            return this
        endmethod
    endstruct
   
   
    struct calcul
        private string symb = ""
        private real value
        private integer sad
        private integer sag
        readonly integer i
        readonly real iteration
        static real array x[8000]
        readonly intervalle E
        private static string array formule[8000]
       
       
        static method create takes string formule returns thistype           
            local thistype this = thistype.createTree(formule)
           
            set thistype.x[this.i] = 0
            set this.E.begin = 0
            set this.E.end = 0
            set this.iteration = 1
            set I = I + 1

            return this
        endmethod
       
       
        private static method createTree takes string formule returns thistype
            local thistype this = thistype.allocate()
            local string arg
            local thistype returned

            if formule == "" then
                return this
            endif
           
            set this.i = I
            set thistype.formule[this.i] = formule
            set arg = getFirstArg(this.i)
            set thistype.formule[i] = SubString(thistype.formule[this.i], StringLength(arg) + 1, StringLength(thistype.formule[this.i]))
           
            if arg == "cos" or arg == "sin" or arg == "sqrt" or arg == "tan" or arg == "arccos" or arg == "arcsin" or arg == "arctan" then
                set this.symb = arg
               
                set returned = createTree(thistype.formule[this.i])
                set this.sag = returned
                set formule = SubString(thistype.formule[this.i], StringLength(getFirstArg(this.i)) + 1, StringLength(thistype.formule[this.i]))
               
            elseif arg == "x" then
                set this.symb = arg
               
            elseif S2I(arg) == 0 then
                set this.symb = arg
                set returned = createTree(thistype.formule[this.i])
                set this.sag = returned
                set formule = SubString(thistype.formule[this.i], StringLength(getFirstArg(this.i)) + 1, StringLength(thistype.formule[this.i]))
                set returned = createTree(thistype.formule[this.i])
                set this.sad = returned
           
            else
                set this.value = S2R(arg)
            endif

            return this
        endmethod
       
       
        private static method getFirstArg takes integer i returns string
            local string mot = ""
            local string car
            local integer j = 0
           
            loop
                set car = SubString(thistype.formule[i], j, j+1)
                exitwhen car == " " or j == StringLength(thistype.formule[i])
                set mot = mot + car
                set j = j + 1
            endloop
           
            return mot
        endmethod
       
       
        method setIntervalle takes real a, real b, real iteration returns nothing
            set this.E = intervalle.create(a, b)
            set this.iteration = iteration
        endmethod
       
       
        method setTabReal takes nothing returns nothing
            local integer i = 0
            local integer max = R2I((this.E.end - this.E.begin) / this.iteration)
                       
            if max > 8000 then
                call BJDebugMsg("There is to many value, increase iteration or reduce intervalle")
                return
            endif

            set thistype.x[this.i] = this.E.begin
           
            loop
                exitwhen i > max
               
                call SaveReal(Hash, this, i, this.executeCalcul())
                set i = i + 1
                set thistype.x[this.i] = thistype.x[this.i] + this.iteration
            endloop
        endmethod
       
       
        method getRealValue takes integer i returns real
            return LoadReal(Hash, this, i)
        endmethod
       
       
        method executeCalcul takes nothing returns real
            local thistype sag = this.sag
            local thistype sad = this.sad

            if this.symb == "" then
                return this.value
            endif

            if this.symb == "+" then
                return sag.executeCalcul() + sad.executeCalcul()
           
            elseif this.symb == "-" then
                return sag.executeCalcul() - sad.executeCalcul()
           
            elseif this.symb == "/" then
                return sag.executeCalcul() / sad.executeCalcul()
           
            elseif this.symb == "*" then
                return sag.executeCalcul() * sad.executeCalcul()
           
            elseif this.symb == "pow" then
                return Pow(sag.executeCalcul(), sad.executeCalcul())
           
            elseif this.symb == "sqrt" then
                return SquareRoot(sag.executeCalcul())
           
            elseif this.symb == "cos" then
                return CosBJ(sag.executeCalcul())
           
            elseif this.symb == "tan" then
                return TanBJ(sag.executeCalcul())
           
            elseif this.symb == "arccos" then
                return AcosBJ(sag.executeCalcul())
           
            elseif this.symb == "arcsin" then
                return AsinBJ(sag.executeCalcul())
           
            elseif this.symb == "arctan" then
                return AtanBJ(sag.executeCalcul())
           
            elseif this.symb == "sin" then
                return SinBJ(sag.executeCalcul())
           
            elseif this.symb == "x" then
                return  thistype.x[this.i]
            endif
           
            return 0.
        endmethod
    endstruct
endlibrary

Utilisation : à venir (utilisation pour déplacer une unité selon une fonction mathématique particulière)
Copyright : Libre
Remarques : Il faut entrer les fonctions en convention polonaise, et je ne sais pas si cela changera un jour (je ne sais pas reconnaitre le format usuel)



j'aimerai surtout des remarques sur comment faciliter l'utilisation de la librairie.
souhaitez vous une fonction pour modifier x ?
souhaitez vous une fonction qui récapitule chaque étape pour tout faire d'un coup ?

se sont des feedback comme ça qui m'intéresse. je ferai les mises à jour qu'il faut. ah et si quelqu'un a la gentillesse de traduire mon API ça me permettrait de poster la ressource sur un site anglophone et ainsi récupérer encore d'avantages de feedback ^^ merci Smile
_________________
22:27:43<Seiraw> Bah y a deux genre de personnes
22:27:57<Seiraw> les soumis et les soumises
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé Envoyer l'e-mail
Montrer les messages depuis:   
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Fonction Jass Toutes les heures sont au format GMT + 1 Heure
Page 1 sur 1

 
Sauter vers:  
Vous ne pouvez pas poster de nouveaux sujets dans ce forum
Vous ne pouvez pas répondre aux sujets dans ce forum
Vous ne pouvez pas éditer vos messages dans ce forum
Vous ne pouvez pas supprimer vos messages dans ce forum
Vous ne pouvez pas voter dans les sondages de ce forum


Powered by phpBB © 2001, 2005 phpBB Group
Traduction par : phpBB-fr.com