<commit_before>/* This file is part of magic-sdk, an sdk for the open source programming language magic.
 *
 * Copyright (C) 2016 magic-lang
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

use base
use collections
use math
import IntPoint2D
import IntVector2D
import FloatPoint2D
import FloatBox2D

IntBox2D: cover {
	leftTop: IntPoint2D
	size: IntVector2D

	width ::= this size x
	height ::= this size y
	left ::= this leftTop x
	top ::= this leftTop y
	right ::= this leftTop x + this size x
	bottom ::= this leftTop y + this size y
	rightTop ::= IntPoint2D new(this right, this top)
	leftBottom ::= IntPoint2D new(this left, this bottom)
	rightBottom ::= this leftTop + this size
	center ::= this leftTop + (this size / 2)
	leftCenter ::= IntPoint2D new(this left, this center y)
	rightCenter ::= IntPoint2D new(this right, this center y)
	topCenter ::= IntPoint2D new(this center x, this top)
	bottomCenter ::= IntPoint2D new(this center x, this bottom)
	hasZeroArea ::= this size hasZeroArea
	area ::= this size area

	init: func@ (newLeftTop: IntPoint2D, newSize: IntVector2D) {
		if (newSize x < 0)
			newLeftTop x += newSize x
		if (newSize y < 0)
			newLeftTop y += newSize y
		this leftTop = newLeftTop
		this size = newSize absolute
	}
	init: func@ ~fromSizes (newLeftTop, newSize: IntVector2D) { this init(newLeftTop toIntPoint2D(), newSize) }
	init: func@ ~fromSize (newSize: IntVector2D) { this init(IntPoint2D new(), newSize) }
	init: func@ ~fromInts (left, top, width, height: Int) { this init(IntPoint2D new(left, top), IntVector2D new(width, height)) }
	init: func@ ~fromPoints (first, second: IntPoint2D) {
		left := first x minimum(second x)
		top := first y minimum(second y)
		width := (first x - second x) abs()
		height := (first y - second y) abs()
		this init(left, top, width, height)
	}
	init: func@ ~default { this init(IntPoint2D new(), IntVector2D new()) }
	swap: func -> This { This new(this leftTop swap(), this size swap()) }
	pad: func (left, right, top, bottom: Int) -> This {
		This new(IntPoint2D new(this left - left, this top - top), IntVector2D new(this width + left + right, this height + top + bottom))
	}
	pad: func ~fromFloat (pad: Int) -> This { this pad(pad, pad, pad, pad) }
	pad: func ~fromSize (pad: IntVector2D) -> This { this pad(pad x, pad x, pad y, pad y) }
	resizeTo: func (size: IntVector2D) -> This {
		This createAround(this center, size)
	}
	scale: func (value: Float) -> This {
		This createAround(this center, value * this size)
	}
	enlargeTo: func (size: IntVector2D) -> This {
		This createAround(this center, this size maximum(size))
	}
	shrinkTo: func (size: IntVector2D) -> This {
		This createAround(this center, this size minimum(size))
	}
	intersection: func (other: This) -> This {
		left := this left maximum(other left)
		top := this top maximum(other top)
		width := 0 maximum(this right minimum(other right) - left)
		height := 0 maximum(this bottom minimum(other bottom) - top)
		This new(left, top, width, height)
	}
	union: func ~box (other: This) -> This { // Rock bug: Union without suffix cannot be used because the C name conflicts with keyword "union"
		left := this left minimum(other left)
		top := this top minimum(other top)
		width := 0 maximum(this right maximum(other right) - left)
		height := 0 maximum(this bottom maximum(other bottom) - top)
		This new(left, top, width, height)
	}
	union: func ~point (point: IntPoint2D) -> This {
		This new(this leftTop minimum(point), this rightBottom maximum(point))
	}
	contains: func (point: IntPoint2D) -> Bool {<commit_msg>corrected pad function name<commit_after>/* This file is part of magic-sdk, an sdk for the open source programming language magic.
 *
 * Copyright (C) 2016 magic-lang
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

use base
use collections
use math
import IntPoint2D
import IntVector2D
import FloatPoint2D
import FloatBox2D

IntBox2D: cover {
	leftTop: IntPoint2D
	size: IntVector2D

	width ::= this size x
	height ::= this size y
	left ::= this leftTop x
	top ::= this leftTop y
	right ::= this leftTop x + this size x
	bottom ::= this leftTop y + this size y
	rightTop ::= IntPoint2D new(this right, this top)
	leftBottom ::= IntPoint2D new(this left, this bottom)
	rightBottom ::= this leftTop + this size
	center ::= this leftTop + (this size / 2)
	leftCenter ::= IntPoint2D new(this left, this center y)
	rightCenter ::= IntPoint2D new(this right, this center y)
	topCenter ::= IntPoint2D new(this center x, this top)
	bottomCenter ::= IntPoint2D new(this center x, this bottom)
	hasZeroArea ::= this size hasZeroArea
	area ::= this size area

	init: func@ (newLeftTop: IntPoint2D, newSize: IntVector2D) {
		if (newSize x < 0)
			newLeftTop x += newSize x
		if (newSize y < 0)
			newLeftTop y += newSize y
		this leftTop = newLeftTop
		this size = newSize absolute
	}
	init: func@ ~fromSizes (newLeftTop, newSize: IntVector2D) { this init(newLeftTop toIntPoint2D(), newSize) }
	init: func@ ~fromSize (newSize: IntVector2D) { this init(IntPoint2D new(), newSize) }
	init: func@ ~fromInts (left, top, width, height: Int) { this init(IntPoint2D new(left, top), IntVector2D new(width, height)) }
	init: func@ ~fromPoints (first, second: IntPoint2D) {
		left := first x minimum(second x)
		top := first y minimum(second y)
		width := (first x - second x) abs()
		height := (first y - second y) abs()
		this init(left, top, width, height)
	}
	init: func@ ~default { this init(IntPoint2D new(), IntVector2D new()) }
	swap: func -> This { This new(this leftTop swap(), this size swap()) }
	pad: func (left, right, top, bottom: Int) -> This {
		This new(IntPoint2D new(this left - left, this top - top), IntVector2D new(this width + left + right, this height + top + bottom))
	}
	pad: func ~fromInt (pad: Int) -> This { this pad(pad, pad, pad, pad) }
	pad: func ~fromSize (pad: IntVector2D) -> This { this pad(pad x, pad x, pad y, pad y) }
	resizeTo: func (size: IntVector2D) -> This {
		This createAround(this center, size)
	}
	scale: func (value: Float) -> This {
		This createAround(this center, value * this size)
	}
	enlargeTo: func (size: IntVector2D) -> This {
		This createAround(this center, this size maximum(size))
	}
	shrinkTo: func (size: IntVector2D) -> This {
		This createAround(this center, this size minimum(size))
	}
	intersection: func (other: This) -> This {
		left := this left maximum(other left)
		top := this top maximum(other top)
		width := 0 maximum(this right minimum(other right) - left)
		height := 0 maximum(this bottom minimum(other bottom) - top)
		This new(left, top, width, height)
	}
	union: func ~box (other: This) -> This { // Rock bug: Union without suffix cannot be used because the C name conflicts with keyword "union"
		left := this left minimum(other left)
		top := this top minimum(other top)
		width := 0 maximum(this right maximum(other right) - left)
		height := 0 maximum(this bottom maximum(other bottom) - top)
		This new(left, top, width, height)
	}
	union: func ~point (point: IntPoint2D) -> This {
		This new(this leftTop minimum(point), this rightBottom maximum(point))
	}
	contains: func (point: IntPoint2D) -> Bool {
{'fraction_non_alphanumeric': 0.11708253358925144, 'fraction_numerical': 0.011790512750205649, 'mean_word_length': 4.137323943661972, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7561540', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2387, 'n_words': 923}