Хламидомонада / Говнокод #29187 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
;; *-* Mode: Lisp *-*
;; *-* Coding: UTF-8 *-*

;; 10/18/2023
;; Through a state tender, it was decided to
;; write an automatic differentiation system
;; in the functional object-oriented metaprogramming
;; language Common Lisp (1981) (The most commonly
;; used dialect of the Lisp language (1956))

;;; AGPL 3.0
;;; ALL RIGHT ARE RESERVED

;; Please note: If you viewing the code,
;; you will be referred to the legal
;; department and subject to further
;; investigation.

;; ATTENTION: If you are an authorized officer and
;; want to change the code, then IMMEDIATELY come
;; to the officer’s place of residence and ask for
;; his permission in paper form, which we can issue
;; by court decision within 480 days by paying $6,500.
;; Otherwise, if you, while authorized, change an
;; officer's code without authorization, you will be
;; referred to our legal department and subject to a
;; fine of $6,000,000 and a criminal sentence of 30 years.

;; PART I
;; DEFINITION OF :CL-AD PACKAGE

;; Author of code: Mr. Jr. Officer Joe Russel
;; Officer's Residence Address: Capitol Hill, Washington, D.C. 721 10th Street Southeast, Washington, D.C. 20003

(defpackage :cl-ad
  (:use :cl)
  (:export
     #:scalar))

(in-package :cl-ad)

;; PART II
;; DEFINITION OF SCALAR CLASS

;; Author of code: Mr. Sr. Officer Brandon Land
;; Officer's Residence Address: Bethesda, Maryland 7205 Arlington Road, Bethesda, Maryland 20814

(defvar +cl-ad-empty-fn+ #'(lambda ())
  "Empty lambda for backpropagation")

(defvar +cl-ad-empty-data+ nil
  "Contains empty data")

(defvar +cl-ad-empty-ctx+ nil
  "Contains empty ctx")

(defvar +cl-ad-empty-grad+ 0.0
  "Contains empty grad")

(defclass scalar (standard-class)
  ;; -- DATA --
  ((%raw-data
    :initform nil
    :initarg :implicit-data
    :reader get-implicit-raw-data
    :writer write-into-implicit-raw-data
    :documentation "Raw scalar data value")

  ;; -- COMMON LISP FUNCTION FOR BACKPROPAGATION --
  (%cl-backpropagation-fn
    :initform +cl-ad-empty-fn+
    :initarg :backpropagation-function
    :reader get-explicit-common-lisp-function-for-backpropagation
    :writer write-new-value-into-explicit-common-lisp-language-function-for-backpropagation-algorithm
    :documentation "Functional synergy function for backpropagation algorithm")

  ;; -- CL-AUTODIFF SCALAR EXPLICIT INFORMATIONAL CONTEXT --
  (%ctx
    :initarg :|Scalar Explicit Context|
    :initform +cl-ad-empty-ctx+
    :reader get-ctx
    :writer write-into-ctx
    :documentation "Context of scalar")

  ;; -- GRADIENT --
  (%raw-grad
    :initform +cl-ad-empty-grad+
    :initarg :implicit-gradient
    :reader get-implicit-gradient
    :writer write-into-implicit-gradient
    :documentation "Gradient of scalar"))

  ;; -- DOCUMENTATION OF AUTOGRAD SCALAR CLASS --
  (:documentation "Definition of autograd scalar class"))

1 часть

lisp-worst-code lisp-worst-code, (Updated )

Комментарии (0)

Куча говна / Говнокод #29186 Ссылка на оригинал

0

  1. 1
Питушня #42

#12: https://govnokod.ru/27182 https://govnokod.xyz/_27182
#13: https://govnokod.ru/27260 https://govnokod.xyz/_27260
#14: https://govnokod.ru/27343 https://govnokod.xyz/_27343
#15: https://govnokod.ru/27353 https://govnokod.xyz/_27353
#16: https://govnokod.ru/27384 https://govnokod.xyz/_27384
#17: https://govnokod.ru/27482 https://govnokod.xyz/_27482
#18: https://govnokod.ru/27514 https://govnokod.xyz/_27514
#19: https://govnokod.ru/27620 https://govnokod.xyz/_27620
#20: https://govnokod.ru/27816 https://govnokod.xyz/_27816
#21: https://govnokod.ru/27956 https://govnokod.xyz/_27956
#22: https://govnokod.ru/28143 https://govnokod.xyz/_28143
#23: https://govnokod.ru/28315 https://govnokod.xyz/_28315
#24: (vanished) https://govnokod.xyz/_28362
#25: (vanished) https://govnokod.xyz/_28463
#26: https://govnokod.ru/28481 https://govnokod.xyz/_28481
#27: https://govnokod.ru/28537 https://govnokod.xyz/_28537
#28: https://govnokod.ru/28619 https://govnokod.xyz/_28619
#29: (vanished) https://govnokod.xyz/_28663
#30: https://govnokod.ru/28673 https://govnokod.xyz/_28673
#31: https://govnokod.ru/28679 https://govnokod.xyz/_28679
#32: https://govnokod.ru/28687 https://govnokod.xyz/_28687
#33: https://govnokod.ru/28694 https://govnokod.xyz/_28694
#34: https://govnokod.ru/28701 https://govnokod.xyz/_28701
#35: https://govnokod.ru/28707 https://govnokod.xyz/_28707
#36: https://govnokod.ru/28714 https://govnokod.xyz/_28714
#37: https://govnokod.ru/28724 https://govnokod.xyz/_28724
#38: https://govnokod.ru/28732 https://govnokod.xyz/_28732
#39: https://govnokod.ru/28839 https://govnokod.xyz/_28839
#40: https://govnokod.ru/28909 https://govnokod.xyz/_28909
#41: https://govnokod.ru/29003 https://govnokod.xyz/_29003

nepeKamHblu_nemyx nepeKamHblu_nemyx, (Updated )

Комментарии (410, +410)

Куча говна / Говнокод #29185 Ссылка на оригинал

0

  1. 1
IT Оффтоп #221

#191: https://govnokod.ru/28878 https://govnokod.xyz/_28878
#192: https://govnokod.ru/28886 https://govnokod.xyz/_28886
#193: https://govnokod.ru/28911 https://govnokod.xyz/_28911
#194: https://govnokod.ru/28914 https://govnokod.xyz/_28914
#195: https://govnokod.ru/28917 https://govnokod.xyz/_28917
#196: https://govnokod.ru/28925 https://govnokod.xyz/_28925
#197: https://govnokod.ru/28935 https://govnokod.xyz/_28935
#198: https://govnokod.ru/28938 https://govnokod.xyz/_28938
#199: https://govnokod.ru/28942 https://govnokod.xyz/_28942
#200: https://govnokod.ru/28945 https://govnokod.xyz/_28945
#201: https://govnokod.ru/28948 https://govnokod.xyz/_28948
#202: https://govnokod.ru/28951 https://govnokod.xyz/_28951
#203: https://govnokod.ru/28954 https://govnokod.xyz/_28954
#204: https://govnokod.ru/28971 https://govnokod.xyz/_28971
#205: https://govnokod.ru/28986 https://govnokod.xyz/_28986
#206: https://govnokod.ru/28991 https://govnokod.xyz/_28991
#207: https://govnokod.ru/29002 https://govnokod.xyz/_29002
#208: https://govnokod.ru/29060 https://govnokod.xyz/_29060
#209: https://govnokod.ru/29070 https://govnokod.xyz/_29070
#210: https://govnokod.ru/29079 https://govnokod.xyz/_29079
#211: https://govnokod.ru/29092 https://govnokod.xyz/_29092
#212: https://govnokod.ru/29093 https://govnokod.xyz/_29093
#213: https://govnokod.ru/29104 https://govnokod.xyz/_29104
#214: https://govnokod.ru/29114 https://govnokod.xyz/_29114
#215: https://govnokod.ru/29125 https://govnokod.xyz/_29125
#216: https://govnokod.ru/29132 https://govnokod.xyz/_29132
#217: https://govnokod.ru/29147 https://govnokod.xyz/_29147
#218: https://govnokod.ru/29156 https://govnokod.xyz/_29156
#219: https://govnokod.ru/29166 https://govnokod.xyz/_29166
#220: https://govnokod.ru/29181 https://govnokod.xyz/_29181

nepeKamHblu_nemyx nepeKamHblu_nemyx, (Updated )

Комментарии (407, +407)

ЙажаСценарий / Говнокод #29184 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
let fallbackFunc = ()=>console.log("Hello, World!");
let settings = {
    fallbackButtonName: "Hello, World!",
    fallbackWidth: 512,
    fallbackHeight: 512,
    settingsMenuExitButtonHeight: 32,
    settingsMenuExitButtonName: "X",
    settingElementHeight: 32,
    settingsMenuExitButtonAtBeginning: true,
    settingElementTrueName: "ON",
    settingElementFalseName: "OFF",
    settingsMenuBooleanSeperatorName: "- $",
    hideExtraButtonsToolbar: true,
    updateToolbar: updateToolbar,
    updateSettingsMenu: updateSettingsMenu,
    activateFallbackFunc: fallbackFunc
};

let settingsMenu = document.getElementById("settings");
let settingsElement = document.querySelector(".setting-element#hide");

// -------------------------------------------------------------------

function updateSettingsMenu() {
    settingsMenu.innerHTML = "";
    let exitButton = document.createElement("button");
    exitButton.style.height = settings.settingsMenuExitButtonHeight+"px";
    exitButton.innerText = settings.settingsMenuExitButtonName;
    exitButton.onclick = function() {
        settingsMenu.style.display = "none";
    }

    if (settings.settingsMenuExitButtonAtBeginning) settingsMenu.appendChild(exitButton);
    for (let k in settings) {
        let v = settings[k];

        let setting = settingsElement.cloneNode(true);
        setting.id = "";
        console.log(setting)
        setting.style.height = settings.settingElementHeight+"px";
        let [name,value] = setting.children;
        if (typeof v !== "function") {
            name.innerText = k;
            function booleanToString(bool) {
                return (bool?settings.settingsMenuBooleanSeperatorName.replaceAll("$",settings.settingElementTrueName):settings.settingsMenuBooleanSeperatorName.replaceAll("$",settings.settingElementFalseName))
            }
            value.innerText = (typeof v === "boolean")?booleanToString(v):v;
            value.onclick = function() {
                if (typeof v === "boolean") {
                    settings[k] = !settings[k];
                    value.innerText = booleanToString(settings[k]);
                } else {
                    let input = prompt(`New value for ${k}:`);
                    let newValue = isNaN(input)?input:Number(input);
                    value.innerText = newValue;
                    settings[k] = newValue
                }
            }
        } else {
            name.remove()
            value.innerText = k;
            value.onclick = v;
        }

        settingsMenu.appendChild(setting);
    }
    if (!settings.settingsMenuExitButtonAtBeginning) settingsMenu.appendChild(exitButton);
}
function showSettings() {
    settingsMenu.style.display = "flex";
    updateSettingsMenu();
}

Как вам код?

manabanana manabanana, (Updated )

Комментарии (1, +1)

Си диез / Говнокод #29183 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
using Godot;

namespace CW2EB.UI;
public partial class EscQuittingLabel : Label {

	Tween tween, tween2thesequel;
	public override void _Ready(){
		base._Ready();
		tween = GetTree().CreateTween().SetParallel();
		tween2thesequel = GetTree().CreateTween();
		tween.TweenProperty(this, "theme_override_colors/font_color", new Color(1f, 1f, 1f, 1f), 1);
		tween.TweenProperty(this, "theme_override_colors/font_shadow_color", new Color(0f, 0f, 0f, 1f), 1);

		
		tween2thesequel.TweenCallback(Callable.From(TweenStage1)).SetDelay(.25);
		tween2thesequel.TweenCallback(Callable.From(TweenStage2)).SetDelay(.25);
		tween2thesequel.TweenCallback(Callable.From(TweenStage3)).SetDelay(.25);
		tween2thesequel.TweenCallback(Callable.From(TweenStage4)).SetDelay(.5);
	}

	public void TweenStage1()
		=> Text = Tr("Quitting") + ".";

	public void TweenStage2()
		=> Text = Tr("Quitting") + "..";

	public void TweenStage3()
		=> Text = Tr("Quitting") + "...";

	public void TweenStage4()
		=> GetTree().Quit();
}

Как сделать постепенно появляющееся многоточие?

GhostNoise GhostNoise, (Updated )

Комментарии (1, +1)

Куча говна / Говнокод #29182 Ссылка на оригинал

0

  1. 1
Пиздец-оффтоп #117

#87: https://govnokod.ru/28817 https://govnokod.xyz/_28817
#88: https://govnokod.ru/28836 https://govnokod.xyz/_28836
#89: https://govnokod.ru/28843 https://govnokod.xyz/_28843
#90: https://govnokod.ru/28874 https://govnokod.xyz/_28874
#91: https://govnokod.ru/28880 https://govnokod.xyz/_28880
#92: https://govnokod.ru/28884 https://govnokod.xyz/_28884
#93: https://govnokod.ru/28889 https://govnokod.xyz/_28889
#94: https://govnokod.ru/28895 https://govnokod.xyz/_28895
#95: https://govnokod.ru/28904 https://govnokod.xyz/_28904
#96: https://govnokod.ru/28912 https://govnokod.xyz/_28912
#97: https://govnokod.ru/28918 https://govnokod.xyz/_28918
#98: https://govnokod.ru/28932 https://govnokod.xyz/_28932
#99: https://govnokod.ru/28936 https://govnokod.xyz/_28936
#100: https://govnokod.ru/28940 https://govnokod.xyz/_28940
#101: https://govnokod.ru/28949 https://govnokod.xyz/_28949
#102: https://govnokod.ru/28978 https://govnokod.xyz/_28978
#103: https://govnokod.ru/28982 https://govnokod.xyz/_28982
#104: https://govnokod.ru/28989 https://govnokod.xyz/_28989
#105: https://govnokod.ru/29052 https://govnokod.xyz/_29052
#106: https://govnokod.ru/29069 https://govnokod.xyz/_29069
#107: https://govnokod.ru/29086 https://govnokod.xyz/_29086
#108: https://govnokod.ru/29102 https://govnokod.xyz/_29102
#109: https://govnokod.ru/29126 https://govnokod.xyz/_29126
#110: https://govnokod.ru/29136 https://govnokod.xyz/_29136
#111: https://govnokod.ru/29142 https://govnokod.xyz/_29142
#112: https://govnokod.ru/29155 https://govnokod.xyz/_29155
#113: https://govnokod.ru/29160 https://govnokod.xyz/_29160
#114: https://govnokod.ru/29165 https://govnokod.xyz/_29165
#115: https://govnokod.ru/29173 https://govnokod.xyz/_29173
#116: https://govnokod.ru/29174 https://govnokod.xyz/_29174

nepeKamHblu_nemyx nepeKamHblu_nemyx, (Updated )

Комментарии (461, +461)

Куча говна / Говнокод #29181 Ссылка на оригинал

0

  1. 1
IT Оффтоп #220

#190: https://govnokod.ru/28875 https://govnokod.xyz/_28875
#191: https://govnokod.ru/28878 https://govnokod.xyz/_28878
#192: https://govnokod.ru/28886 https://govnokod.xyz/_28886
#193: https://govnokod.ru/28911 https://govnokod.xyz/_28911
#194: https://govnokod.ru/28914 https://govnokod.xyz/_28914
#195: https://govnokod.ru/28917 https://govnokod.xyz/_28917
#196: https://govnokod.ru/28925 https://govnokod.xyz/_28925
#197: https://govnokod.ru/28935 https://govnokod.xyz/_28935
#198: https://govnokod.ru/28938 https://govnokod.xyz/_28938
#199: https://govnokod.ru/28942 https://govnokod.xyz/_28942
#200: https://govnokod.ru/28945 https://govnokod.xyz/_28945
#201: https://govnokod.ru/28948 https://govnokod.xyz/_28948
#202: https://govnokod.ru/28951 https://govnokod.xyz/_28951
#203: https://govnokod.ru/28954 https://govnokod.xyz/_28954
#204: https://govnokod.ru/28971 https://govnokod.xyz/_28971
#205: https://govnokod.ru/28986 https://govnokod.xyz/_28986
#206: https://govnokod.ru/28991 https://govnokod.xyz/_28991
#207: https://govnokod.ru/29002 https://govnokod.xyz/_29002
#208: https://govnokod.ru/29060 https://govnokod.xyz/_29060
#209: https://govnokod.ru/29070 https://govnokod.xyz/_29070
#210: https://govnokod.ru/29079 https://govnokod.xyz/_29079
#211: https://govnokod.ru/29092 https://govnokod.xyz/_29092
#212: https://govnokod.ru/29093 https://govnokod.xyz/_29093
#213: https://govnokod.ru/29104 https://govnokod.xyz/_29104
#214: https://govnokod.ru/29114 https://govnokod.xyz/_29114
#215: https://govnokod.ru/29125 https://govnokod.xyz/_29125
#216: https://govnokod.ru/29132 https://govnokod.xyz/_29132
#217: https://govnokod.ru/29147 https://govnokod.xyz/_29147
#218: https://govnokod.ru/29156 https://govnokod.xyz/_29156
#219: https://govnokod.ru/29166 https://govnokod.xyz/_29166

nepeKamHblu_nemyx nepeKamHblu_nemyx, (Updated )

Комментарии (449, +449)

Сборный / Говнокод #29180 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
TLS_Callback:
0051CAC3: push ebp
0051CAC4: mov ebp,esp
0051CAC6: cmp dword ptr ds:[51C01C],0
0051CACD: je expressor.51CAD6
0051CACF: pop ebp
0051CAD0: jmp dword ptr ds:[51C020]
0051CAD6: mov eax,dword ptr ss:[ebp + 8]
0051CAD9: xor ecx,ecx
0051CADB: inc ecx
0051CADC: test eax,eax
0051CADE: je expressor.51CAF3
0051CAE0: mov edx,dword ptr ds:[eax + 3C]
0051CAE3: mov edx,dword ptr ds:[edx + eax + 28]
0051CAE7: cmp byte ptr ds:[eax + edx],CC
0051CAEB: jne expressor.51CAF3
0051CAED: mov dword ptr ds:[51C038],ecx
0051CAF3: cmp dword ptr ds:[51C038],0
0051CAFA: mov dword ptr ds:[51C028],eax
0051CAFF: mov eax,dword ptr ss:[ebp + C]
0051CB02: mov dword ptr ds:[51C02C],eax
0051CB07: mov eax,dword ptr ss:[ebp + 10]
0051CB0A: mov dword ptr ds:[51C03C],ecx
0051CB10: mov dword ptr ds:[51C030],eax
0051CB15: jne expressor.51CB21
0051CB17: call expressor.51C81B
0051CB1C: mov dword ptr ds:[51C038],eax
0051CB21: pop ebp
0051CB22: ret C

Что получает через mov eax,dword ptr ss:[ebp + C] и mov eax,dword ptr ss:[ebp + 10]?

BelCodeMonkey BelCodeMonkey, (Updated )

Комментарии (36, +36)

Сборный / Говнокод #29179 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
mov r8, qword ptr [rsi]
mov rdx, qword ptr [rdi]
bswap rdx
mov rcx, rdx
ror rcx, 1
movabs rax, 0x808080808080808
and rcx, rax
or r8, rcx
mov rcx, rdx
ror rcx, 3
movabs rax, 0x404040404040404
and rcx, rax
or r8, rcx
mov rcx, rdx
ror rcx, 5
movabs rax, 0x202020202020202
and rcx, rax
or r8, rcx
mov rcx, rdx
ror rcx, 7
movabs rax, 0x101010101010101
and rcx, rax
or r8, rcx
mov rcx, rdx
ror rcx, 0x39
movabs rax, 0x8080808080808080
and rcx, rax
or r8, rcx
mov rcx, rdx
ror rcx, 0x3B
movabs rax, 0x4040404040404040
and rcx, rax
or r8, rcx
mov rcx, rdx
ror rcx, 0x3D
movabs rax, 0x2020202020202020
and rcx, rax
or r8, rcx
mov rcx, rdx
ror rcx, 0x3F
movabs rax, 0x1010101010101010
and rcx, rax
or r8, rcx
mov qword ptr [rsi], r8

Разворот битов в uint64

CHayT CHayT, (Updated )

Комментарии (9, +9)

Куча говна / Говнокод #29178 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
pub trait Normalize<T> {
    type Output;
    fn normalize(&self, baseline_value: &T) -> Self::Output;
    fn denormalize(&self, baseline_value: &T) -> Self::Output;
}

impl<T, U, W> Normalize<T> for U
where
    T: Copy,
    U: Copy + Div<T, Output = W> + Mul<T, Output = W>,
{
    type Output = W;
    fn normalize(&self, baseline_value: &T) -> Self::Output { *self / *baseline_value }
    fn denormalize(&self, baseline_value: &T) -> Self::Output { *self * *baseline_value }
}

impl<T> Normalize<CanvasSize<T>> for Rectangle
where
    T: Copy,
    f32: Normalize<T, Output = f32>
{
    type Output = Rectangle;

    fn normalize(&self, baseline_value: &CanvasSize<T>) -> Self::Output {
        Rectangle {
            x1: self.x1.normalize(&baseline_value.width),
            y1: self.y1.normalize(&baseline_value.height),
            x2: self.x2.normalize(&baseline_value.width),
            y2: self.y2.normalize(&baseline_value.height),
        }
    }
    fn denormalize(&self, baseline_value: &CanvasSize<T>) -> Self::Output {
        Rectangle {
            x1: self.x1.denormalize(&baseline_value.width),
            y1: self.y1.denormalize(&baseline_value.height),
            x2: self.x2.denormalize(&baseline_value.width),
            y2: self.y2.denormalize(&baseline_value.height),
        }
    }
}

ISO ISO, (Updated )

Комментарии (165, +165)