<commit_before>// Demo is a Point Location visualization demo.

package demo

import (
	"fmt"
	"image/color"
	"math"
	"os"
	"path/filepath"
	"strconv"
	"time"

	"golang.org/x/sync/syncmap"

	"bitbucket.org/oakmoundstudio/oak"
	"bitbucket.org/oakmoundstudio/oak/event"
	"bitbucket.org/oakmoundstudio/oak/render"
	"github.com/200sc/go-compgeo/dcel"
	"github.com/200sc/go-compgeo/dcel/off"
	"github.com/200sc/go-compgeo/dcel/pointLoc"
	"github.com/200sc/go-compgeo/dcel/pointLoc/visualize"
	"github.com/200sc/go-compgeo/geom"
)

const (
	zMoveSpeed    = 1
	shiftSpeed    = 3
	scaleSpeed    = .02
	rotSpeed      = .01
	vCollisionDim = 8
	defScale      = 20
	defRotZ       = math.Pi
	defRotY       = math.Pi
	defShiftX     = 200
	defShiftY     = 200
)

// Point Location Mode Const
const (
	SLAB_DECOMPOSITION = iota
	TRAPEZOID_MAP
	PLUMB_LINE
	LAST_PL_MODE
	KIRKPATRICK_MONOTONE
	KIRKPATRICK_TRAPEZOID
)

var (
	dragX             float64 = -1
	dragY             float64 = -1
	dragging                  = -1
	offFile                   = filepath.Join("data", "test3.off")
	mode                      = ROTATE
	loopDemo          bool
	mouseZ            = 0.0
	faceVertices      = &syncmap.Map{}
	err               error
	mouseStr          *render.IFText
	font              *render.Font
	phd               *InteractivePolyhedron
	undoPhd           []InteractivePolyhedron
	ticker            *DynamicTicker
	stopTickerCh      = make(chan bool)
	sliding           bool
	locator           pointLoc.LocatesPoints
	pointLocationMode = SLAB_DECOMPOSITION
	modeBtn           *Button
	mouseModeBtn      *Button
	locating          bool

	btnColor     = color.RGBA{50, 50, 140, 255}
	createdColor = color.RGBA{50, 140, 50, 255}

	visSlider *Slider

	randomize           = true
	randomSplits        = 1
	defaultRandomSplits = 5
)

// InitScene is called whenever the scene 'demo' starts.
// it creates the objects in our application.
func InitScene(prevScene string, data interface{}) {
	if visualize.VisualCh != nil {
		close(visualize.VisualCh)
		select {
		case stopTickerCh <- true:
		default:
		}
		visualize.VisualCh = nil
	}
	ticker = NewDynamicTicker()
	loopDemo = true
	locator = nil
	var dc *dcel.DCEL
	if randomize {
		dc = dcel.Random2DDCEL(100, randomSplits)
	} else if offFile == "none" {
		dc = dcel.New()
	} else {
		dc, err = off.Load(offFile)
		if err != nil {
			fmt.Println("Unable to load", offFile, ":", err)
			dc = dcel.New()
		}
	}
	mode = ROTATE
	pointLocationMode = SLAB_DECOMPOSITION
	phd = new(InteractivePolyhedron)
	phd.Polyhedron = NewPolyhedronFromDCEL(dc, defShiftX, defShiftY)
	if !randomize {
		phd.Polyhedron.Scale(defScale)
		phd.Polyhedron.RotZ(defRotZ)
		phd.Polyhedron.RotY(defRotY)
	} else {
		randomize = false
	}
	phd.Init()
	render.Draw(phd, 0)

	fg := render.FontGenerator{File: "luxisr.ttf", Color: render.FontColor("white"), Size: 12}
	font = fg.Generate()

	mouseStr = font.NewInterfaceText(
		geom.Point{0, 0, 0}, 3, 465)
	render.Draw(mouseStr, 3)

	bkgrnd := render.NewColorBox(140, 480, color.RGBA{50, 50, 80, 255})
	bkgrnd.SetPos(514, 0)
	render.Draw(bkgrnd, 0)

	clrBtn := NewButton(clear, font)
	clrBtn.SetLogicDim(50, 20)
	clrBtn.SetRenderable(render.NewColorBox(int(clrBtn.W), int(clrBtn.H), btnColor))<commit_msg>Correction for default dimensions / positions<commit_after>// Demo is a Point Location visualization demo.

package demo

import (
	"fmt"
	"image/color"
	"os"
	"path/filepath"
	"strconv"
	"time"

	"golang.org/x/sync/syncmap"

	"bitbucket.org/oakmoundstudio/oak"
	"bitbucket.org/oakmoundstudio/oak/event"
	"bitbucket.org/oakmoundstudio/oak/render"
	"github.com/200sc/go-compgeo/dcel"
	"github.com/200sc/go-compgeo/dcel/off"
	"github.com/200sc/go-compgeo/dcel/pointLoc"
	"github.com/200sc/go-compgeo/dcel/pointLoc/visualize"
	"github.com/200sc/go-compgeo/geom"
)

const (
	zMoveSpeed    = 1
	shiftSpeed    = 3
	scaleSpeed    = .02
	rotSpeed      = .01
	vCollisionDim = 8
)

// Point Location Mode Const
const (
	SLAB_DECOMPOSITION = iota
	TRAPEZOID_MAP
	PLUMB_LINE
	LAST_PL_MODE
	KIRKPATRICK_MONOTONE
	KIRKPATRICK_TRAPEZOID
)

var (
	dragX             float64 = -1
	dragY             float64 = -1
	dragging                  = -1
	offFile                   = filepath.Join("data", "test3.off")
	mode                      = ROTATE
	loopDemo          bool
	mouseZ            = 0.0
	faceVertices      = &syncmap.Map{}
	err               error
	mouseStr          *render.IFText
	font              *render.Font
	phd               *InteractivePolyhedron
	undoPhd           []InteractivePolyhedron
	ticker            *DynamicTicker
	stopTickerCh      = make(chan bool)
	sliding           bool
	locator           pointLoc.LocatesPoints
	pointLocationMode = SLAB_DECOMPOSITION
	modeBtn           *Button
	mouseModeBtn      *Button
	locating          bool

	defShiftX = 200.0
	defShiftY = 200.0

	btnColor     = color.RGBA{50, 50, 140, 255}
	createdColor = color.RGBA{50, 140, 50, 255}

	visSlider *Slider

	randomize           = true
	randomSplits        = 1
	defaultRandomSplits = 5
)

// InitScene is called whenever the scene 'demo' starts.
// it creates the objects in our application.
func InitScene(prevScene string, data interface{}) {
	if visualize.VisualCh != nil {
		close(visualize.VisualCh)
		select {
		case stopTickerCh <- true:
		default:
		}
		visualize.VisualCh = nil
	}
	ticker = NewDynamicTicker()
	loopDemo = true
	locator = nil
	var dc *dcel.DCEL
	if randomize {
		dc = dcel.Random2DDCEL(100, randomSplits)
		randomize = false
	} else if offFile == "none" {
		dc = dcel.New()
	} else {
		dc, err = off.Load(offFile)
		if err != nil {
			fmt.Println("Unable to load", offFile, ":", err)
			dc = dcel.New()
		}
	}
	mode = ROTATE
	pointLocationMode = SLAB_DECOMPOSITION
	phd = new(InteractivePolyhedron)
	phd.Polyhedron = NewPolyhedronFromDCEL(dc, defShiftX, defShiftY)
	// Scale till 300 wide
	width := phd.Max(0)
	if width <= 300 {
		phd.Polyhedron.Scale(300 / width)
	}
	phd.ShiftX(50 - phd.X)
	phd.ShiftY(50 - phd.Y)
	phd.Init()
	render.Draw(phd, 0)

	fg := render.FontGenerator{File: "luxisr.ttf", Color: render.FontColor("white"), Size: 12}
	font = fg.Generate()

	mouseStr = font.NewInterfaceText(
		geom.Point{0, 0, 0}, 3, 465)
	render.Draw(mouseStr, 3)

	bkgrnd := render.NewColorBox(140, 480, color.RGBA{50, 50, 80, 255})
	bkgrnd.SetPos(514, 0)
	render.Draw(bkgrnd, 0)

	clrBtn := NewButton(clear, font)
	clrBtn.SetLogicDim(50, 20)
	clrBtn.SetRenderable(render.NewColorBox(int(clrBtn.W), int(clrBtn.H), btnColor))
{'fraction_non_alphanumeric': 0.11279123592038266, 'fraction_numerical': 0.03332819009412128, 'mean_word_length': 2.8106995884773665, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 3, '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': '6842397', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2470, 'n_words': 501}