Skip to content

Commit

Permalink
[ cleanup ] Redesign FShapeQuad, update QuadTree, remove FShape
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Dec 9, 2017
1 parent 28c7a9a commit 4f751a1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
9 changes: 3 additions & 6 deletions src/org/frice/obj/Objects.kt
Expand Up @@ -30,13 +30,10 @@ interface AbstractObject {
* @author ice1000
* @since v0.4
*/
interface FContainer {
interface FContainer : FShapeQuad {

var x: Double
var y: Double

val width: Double
val height: Double
override var x: Double
override var y: Double

fun containsPoint(px: Int, py: Int) = px >= x && px <= x + width && py >= y && py <= y + height

Expand Down
2 changes: 1 addition & 1 deletion src/org/frice/obj/sub/ImageObject.kt
Expand Up @@ -21,7 +21,7 @@ constructor(
var res: ImageResource,
override var x: Double = 0.0,
override var y: Double = 0.0,
id: Int = -1) : FShapeQuad, FObject(), FObject.ImageOwner {
id: Int = -1) : FObject(), FObject.ImageOwner {
constructor(res: FriceImage, x: Double, y: Double) : this(create(res), x, y, -1)

init {
Expand Down
8 changes: 8 additions & 0 deletions src/org/frice/utils/QuadTree.kt
Expand Up @@ -2,6 +2,7 @@ package org.frice.utils

import org.frice.obj.PhysicalObject
import org.frice.utils.shape.FQuad
import org.frice.utils.shape.FShapeQuad
import java.util.*

/**
Expand All @@ -26,6 +27,13 @@ class QuadTree(private var level: Int, private var bounds: FQuad) {
for (i in nodes.indices) nodes[i] = null
}

private fun isInner(ob: PhysicalObject, quad: FShapeQuad): Boolean {
return ob.x >= quad.x
&& ob.x + ob.width <= quad.x + quad.width
&& ob.y >= quad.y
&& ob.y + ob.height <= quad.y + quad.height
}

private fun split() {
// width & height
val subWidth = bounds.width / 2
Expand Down
2 changes: 1 addition & 1 deletion src/org/frice/utils/media/AudioPlayer.kt
Expand Up @@ -31,7 +31,7 @@ class AudioPlayer internal constructor(file: File) : Thread() {
/**
* @author ice1000
* @since v1.7.6
* @see AudioPlayer
* @see org.frice.utils.media.AudioPlayer
*/
class AudioPlayerRunnable(file: File) : Runnable {
private var audioInputStream: AudioInputStream
Expand Down
3 changes: 3 additions & 0 deletions src/org/frice/utils/shape/Quads.kt
@@ -1,6 +1,9 @@
package org.frice.utils.shape

/**
* It's just an abstract representation of an object
* with x, y, width and height.
*
* @author ice1000
* @since v1.6.7
* @see org.frice.utils.shape.FQuad
Expand Down
13 changes: 3 additions & 10 deletions src/org/frice/utils/shape/Shapes.kt
Expand Up @@ -2,19 +2,12 @@ package org.frice.utils.shape

import java.awt.geom.Rectangle2D

/**
* Created by ice1000 on 2016/8/14.
* @author ice1000
* @since v0.1.1
*/
interface FShape

interface FShapeInt : FShape {
interface FShapeInt {
var width: Int
var height: Int
}

interface FShapeDouble : FShape {
interface FShapeDouble {
var width: Double
var height: Double
}
Expand Down Expand Up @@ -42,7 +35,7 @@ open class FOval(rh: Double, rv: Double) : FShapeInt {
* @author ice1000
* @since v0.3
*/
data class FPoint(var x: Int, var y: Int) : FShape
data class FPoint(var x: Int, var y: Int)

/**
* Created by ice1000 on 2016/8/14.
Expand Down

0 comments on commit 4f751a1

Please sign in to comment.