<commit_before>--[[
This file is part of semaphore.
Licensed under the MIT License,
               http://www.opensource.org/licenses/mit-license.php
Copyright 2008 <NAME> <<EMAIL>>
]]--

require('compass')
require('tile')
local cairo = require("lcairo")

CairoRender = {}

	function CairoRender:new(o)
		o = o or {}
		setmetatable(o, self)
		self.__index = self
		return o
	end

	function CairoRender:render(ctx)
		local canvas = self.style.canvas
		cairo.set_source_rgb(ctx, canvas.r, canvas.g, canvas.b)
		cairo.paint(ctx)

		local track_back = self.style.track_back
		local track_front = self.style.track_front

		local function draw_tile(x, y, tile)
			local entry = tile.vector[Vector.ENTRY]
			local exit = tile.vector[Vector.EXIT]
			
			cairo.set_line_width(ctx, self.style.track_back_width)
			cairo.set_source_rgb(ctx, track_back.r, track_back.g, track_back.b)
			cairo.move_to(ctx, x + 0.5 + (entry.x * 0.5), y + 0.5 + (entry.y * 0.5))
			cairo.line_to(ctx, x + 0.5 + (exit.x * 0.5), y + 0.5 + (exit.y * 0.5))
			cairo.stroke(ctx)

			cairo.set_line_width(ctx, self.style.track_front_width)
			cairo.set_source_rgb(ctx, track_front.r, track_front.g, track_front.b)
			cairo.move_to(ctx, x + 0.5 + (entry.x * 0.5), y + 0.5 + (entry.y * 0.5))
			cairo.line_to(ctx, x + 0.5 + (exit.x * 0.5), y + 0.5 + (exit.y * 0.5))
			cairo.stroke(ctx)
		end

		for i=1,self.map.w do
			for j=1,self.map.h do
				local tile = self.map[j][i]
				if tile ~= BLANK then
					draw_tile(i-1, j-1, tile)
				end
			end
		end
	end<commit_msg>invert y coordinates, split out helper functions<commit_after>--[[
This file is part of semaphore.
Licensed under the MIT License,
               http://www.opensource.org/licenses/mit-license.php
Copyright 2008 <NAME> <<EMAIL>>
]]--

require('compass')
require('tile')
local cairo = require("lcairo")

CairoRender = {}

	function CairoRender:new(o)
		o = o or {}
		setmetatable(o, self)
		self.__index = self
		return o
	end

	function CairoRender:render(ctx)
		local canvas = self.style.canvas
		cairo.set_source_rgb(ctx, canvas.r, canvas.g, canvas.b)
		cairo.paint(ctx)

		local track_back = self.style.track_back
		local track_front = self.style.track_front

		local function position(x, y, compass)
			return x + 0.5 + (compass.x * 0.5), self.map.h - y - 0.5 - (compass.y * 0.5)
		end

		local function draw_tile(x, y, tile)
			local entry = tile.vector[Vector.ENTRY]
			local exit = tile.vector[Vector.EXIT]
			
			cairo.set_line_width(ctx, self.style.track_back_width)
			cairo.set_source_rgb(ctx, track_back.r, track_back.g, track_back.b)
			cairo.move_to(ctx, position(x, y, entry))
			cairo.line_to(ctx, position(x, y, exit))
			cairo.stroke(ctx)

			cairo.set_line_width(ctx, self.style.track_front_width)
			cairo.set_source_rgb(ctx, track_front.r, track_front.g, track_front.b)
			cairo.move_to(ctx, position(x, y, entry))
			cairo.line_to(ctx, position(x, y, exit))
			cairo.stroke(ctx)
		end

		for i=1,self.map.w do
			for j=1,self.map.h do
				local tile = self.map[j][i]
				if tile ~= BLANK then
					draw_tile(i-1, j-1, tile)
				end
			end
		end
	end
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.01805869074492099, 'mean_word_length': 3.3506311360448806, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4485099', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1218, 'n_words': 267}