<commit_before>package pony.heaps;

import pony.events.Signal1;
import pony.events.Signal2;
import pony.magic.HasSignal;
import pony.geom.Point;
import pony.geom.Rect;

@:enum abstract SmallDeviceQuality(Int) to Int {
	var ideal = 1;
	var low = 2;
	var normal = 3;
	var good = 4;
}

@:nullSafety(Off) @:final class SmartCanvas implements HasSignal {

	@:auto public var onStageResize: Signal2<Float, Rect<Float>>;
	@:auto public var onDynStageResize: Signal1<Rect<Float>>;

	public var width(default, null): Int;
	public var height(default, null): Int;
	public var stageWidth(default, null): Int = 0;
	public var stageHeight(default, null): Int = 0;
	public var stageInitSize(default, null): Point<Int>;
	public var scale(default, null): Float;
	public var ratio(default, null): Float;
	public var dynStage(get, never): Rect<Float>;
	public var rect: Rect<Float>;
	public var noScale: Bool = false;
	public var smallDeviceQuality(default, set): SmallDeviceQuality;
	private var smallDeviceQualityOffset: Float;

	public function new(?size: Point<UInt>, smallDeviceQuality: SmallDeviceQuality = SmallDeviceQuality.ideal) {
		stageInitSize = size;
		rect = new Rect<Float>(0, 0, size.x, size.y);
		width = size.x;
		height = size.y;
		eDynStageResize.onTake << takeDynStageHandler;
		eDynStageResize.onLost << lostDynStageHandler;
	}

	private function takeDynStageHandler(): Void onStageResize << dynStageResize;
	private function lostDynStageHandler(): Void onStageResize >> dynStageResize;
	private function dynStageResize(): Void eDynStageResize.dispatch(dynStage);

	public inline function set_smallDeviceQuality(q: SmallDeviceQuality): SmallDeviceQuality {
		if (this.smallDeviceQuality != q) {
			this.smallDeviceQuality = q;
			smallDeviceQualityOffset = 1 - 1 / q;
			setSize(width, height);
		}
		return q;
	}

	@:extern private inline function get_dynStage(): Rect<Float> {
		return new Rect(-rect.x, -rect.y, width / scale, height / scale);
	}

	private function setSize(w: Int, h: Int): Void {
		width = w;
		height = h;
		if (stageInitSize != null) setStageSize(w, h);
	}
<commit_msg>Heaps SmartCanvas stageWidth and stageHeight<commit_after>package pony.heaps;

import pony.events.Signal1;
import pony.events.Signal2;
import pony.magic.HasSignal;
import pony.geom.Point;
import pony.geom.Rect;

@:enum abstract SmallDeviceQuality(Int) to Int {
	var ideal = 1;
	var low = 2;
	var normal = 3;
	var good = 4;
}

@:nullSafety(Off) @:final class SmartCanvas implements HasSignal {

	@:auto public var onStageResize: Signal2<Float, Rect<Float>>;
	@:auto public var onDynStageResize: Signal1<Rect<Float>>;

	public var width(default, null): Int;
	public var height(default, null): Int;
	public var stageWidth(default, null): Int = 0;
	public var stageHeight(default, null): Int = 0;
	public var stageInitSize(default, null): Point<Int>;
	public var scale(default, null): Float;
	public var ratio(default, null): Float;
	public var dynStage(get, never): Rect<Float>;
	public var rect: Rect<Float>;
	public var noScale: Bool = false;
	public var smallDeviceQuality(default, set): SmallDeviceQuality;
	private var smallDeviceQualityOffset: Float;

	public function new(?size: Point<UInt>, smallDeviceQuality: SmallDeviceQuality = SmallDeviceQuality.ideal) {
		stageInitSize = size;
		if (size != null) {
			stageWidth = size.x;
			stageHeight = size.y;
		}
		rect = new Rect<Float>(0, 0, size.x, size.y);
		width = size.x;
		height = size.y;
		eDynStageResize.onTake << takeDynStageHandler;
		eDynStageResize.onLost << lostDynStageHandler;
	}

	private function takeDynStageHandler(): Void onStageResize << dynStageResize;
	private function lostDynStageHandler(): Void onStageResize >> dynStageResize;
	private function dynStageResize(): Void eDynStageResize.dispatch(dynStage);

	public inline function set_smallDeviceQuality(q: SmallDeviceQuality): SmallDeviceQuality {
		if (this.smallDeviceQuality != q) {
			this.smallDeviceQuality = q;
			smallDeviceQualityOffset = 1 - 1 / q;
			setSize(width, height);
		}
		return q;
	}

	@:extern private inline function get_dynStage(): Rect<Float> {
		return new Rect(-rect.x, -rect.y, width / scale, height / scale);
	}

	private function setSize(w: Int, h: Int): Void {
		width = w;
		height = h;
		if (stageInitSize != null) setStageSize(w, h);
	}

{'fraction_non_alphanumeric': 0.1154025127966496, 'fraction_numerical': 0.006514657980456026, 'mean_word_length': 5.1152204836415365, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2463959', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1384, 'n_words': 401}